2003-09-30 18:37:50 +00:00
|
|
|
//===-- llvm/CodeGen/MachineInstr.h - MachineInstr class --------*- C++ -*-===//
|
2005-04-21 20:39:54 +00:00
|
|
|
//
|
2003-10-20 20:19:47 +00:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 19:59:42 +00:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-04-21 20:39:54 +00:00
|
|
|
//
|
2003-10-20 20:19:47 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2002-02-03 07:11:59 +00:00
|
|
|
//
|
|
|
|
// This file contains the declaration of the MachineInstr class, which is the
|
2003-08-21 22:14:26 +00:00
|
|
|
// basic representation for all target dependent machine instructions used by
|
2002-02-03 07:11:59 +00:00
|
|
|
// the back end.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2001-07-21 12:39:03 +00:00
|
|
|
|
|
|
|
#ifndef LLVM_CODEGEN_MACHINEINSTR_H
|
|
|
|
#define LLVM_CODEGEN_MACHINEINSTR_H
|
|
|
|
|
2007-12-30 04:40:25 +00:00
|
|
|
#include "llvm/CodeGen/MachineOperand.h"
|
2003-06-11 14:01:36 +00:00
|
|
|
|
2003-11-11 22:41:34 +00:00
|
|
|
namespace llvm {
|
|
|
|
|
2006-11-13 23:34:06 +00:00
|
|
|
class TargetInstrDescriptor;
|
2002-10-30 00:46:48 +00:00
|
|
|
class TargetMachine;
|
2002-10-28 02:29:46 +00:00
|
|
|
|
2004-10-27 16:14:51 +00:00
|
|
|
template <typename T> struct ilist_traits;
|
|
|
|
template <typename T> struct ilist;
|
2004-02-12 02:27:10 +00:00
|
|
|
|
2003-06-03 15:42:53 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2006-05-04 18:16:01 +00:00
|
|
|
/// MachineInstr - Representation of each machine instruction.
|
|
|
|
///
|
2003-06-02 22:07:37 +00:00
|
|
|
class MachineInstr {
|
2006-11-30 07:08:44 +00:00
|
|
|
const TargetInstrDescriptor *TID; // Instruction descriptor.
|
2006-11-27 23:37:22 +00:00
|
|
|
unsigned short NumImplicitOps; // Number of implicit operands (which
|
2006-11-15 20:48:17 +00:00
|
|
|
// are determined at construction time).
|
|
|
|
|
2006-05-04 19:14:44 +00:00
|
|
|
std::vector<MachineOperand> Operands; // the operands
|
2004-02-12 02:27:10 +00:00
|
|
|
MachineInstr* prev, *next; // links for our intrusive list
|
2004-02-12 18:49:07 +00:00
|
|
|
MachineBasicBlock* parent; // pointer to the owning basic block
|
2004-03-03 19:07:27 +00:00
|
|
|
|
2002-10-28 20:48:39 +00:00
|
|
|
// OperandComplete - Return true if it's illegal to add a new operand
|
|
|
|
bool OperandsComplete() const;
|
2002-10-29 19:41:18 +00:00
|
|
|
|
2004-05-23 19:35:12 +00:00
|
|
|
MachineInstr(const MachineInstr&);
|
2003-06-02 22:07:37 +00:00
|
|
|
void operator=(const MachineInstr&); // DO NOT IMPLEMENT
|
2004-02-12 02:27:10 +00:00
|
|
|
|
|
|
|
// Intrusive list support
|
2004-10-27 16:14:51 +00:00
|
|
|
friend struct ilist_traits<MachineInstr>;
|
2004-02-12 02:27:10 +00:00
|
|
|
|
2001-07-21 12:39:03 +00:00
|
|
|
public:
|
2006-11-27 23:37:22 +00:00
|
|
|
/// MachineInstr ctor - This constructor creates a dummy MachineInstr with
|
2006-11-30 07:08:44 +00:00
|
|
|
/// TID NULL and no operands.
|
2006-11-27 23:37:22 +00:00
|
|
|
MachineInstr();
|
2002-09-20 00:47:49 +00:00
|
|
|
|
2006-11-13 23:34:06 +00:00
|
|
|
/// MachineInstr ctor - This constructor create a MachineInstr and add the
|
2007-12-30 00:12:25 +00:00
|
|
|
/// implicit operands. It reserves space for number of operands specified by
|
2006-11-27 23:37:22 +00:00
|
|
|
/// TargetInstrDescriptor.
|
2007-10-13 02:23:01 +00:00
|
|
|
explicit MachineInstr(const TargetInstrDescriptor &TID, bool NoImp = false);
|
2006-11-13 23:34:06 +00:00
|
|
|
|
2002-10-29 23:18:23 +00:00
|
|
|
/// MachineInstr ctor - Work exactly the same as the ctor above, except that
|
|
|
|
/// the MachineInstr is created and added to the end of the specified basic
|
|
|
|
/// block.
|
|
|
|
///
|
2006-11-27 23:37:22 +00:00
|
|
|
MachineInstr(MachineBasicBlock *MBB, const TargetInstrDescriptor &TID);
|
2005-04-21 20:39:54 +00:00
|
|
|
|
2004-02-16 07:17:43 +00:00
|
|
|
~MachineInstr();
|
|
|
|
|
2004-02-12 18:49:07 +00:00
|
|
|
const MachineBasicBlock* getParent() const { return parent; }
|
|
|
|
MachineBasicBlock* getParent() { return parent; }
|
2006-11-30 07:08:44 +00:00
|
|
|
|
|
|
|
/// getInstrDescriptor - Returns the target instruction descriptor of this
|
|
|
|
/// MachineInstr.
|
|
|
|
const TargetInstrDescriptor *getInstrDescriptor() const { return TID; }
|
2004-02-12 18:49:07 +00:00
|
|
|
|
2004-03-03 19:07:27 +00:00
|
|
|
/// getOpcode - Returns the opcode of this MachineInstr.
|
2004-02-12 01:34:03 +00:00
|
|
|
///
|
2007-09-14 20:08:19 +00:00
|
|
|
int getOpcode() const;
|
2003-05-31 07:43:01 +00:00
|
|
|
|
2004-02-12 01:34:03 +00:00
|
|
|
/// Access to explicit operands of the instruction.
|
|
|
|
///
|
2006-05-04 19:14:44 +00:00
|
|
|
unsigned getNumOperands() const { return Operands.size(); }
|
2005-04-21 20:39:54 +00:00
|
|
|
|
2002-10-28 04:24:49 +00:00
|
|
|
const MachineOperand& getOperand(unsigned i) const {
|
2002-10-29 19:41:18 +00:00
|
|
|
assert(i < getNumOperands() && "getOperand() out of range!");
|
2006-05-04 19:14:44 +00:00
|
|
|
return Operands[i];
|
2002-10-28 04:24:49 +00:00
|
|
|
}
|
|
|
|
MachineOperand& getOperand(unsigned i) {
|
2002-10-29 19:41:18 +00:00
|
|
|
assert(i < getNumOperands() && "getOperand() out of range!");
|
2006-05-04 19:14:44 +00:00
|
|
|
return Operands[i];
|
2002-10-28 04:24:49 +00:00
|
|
|
}
|
2002-10-28 04:30:20 +00:00
|
|
|
|
2007-05-15 01:26:09 +00:00
|
|
|
/// getNumExplicitOperands - Returns the number of non-implicit operands.
|
|
|
|
///
|
|
|
|
unsigned getNumExplicitOperands() const;
|
2006-10-20 22:39:36 +00:00
|
|
|
|
|
|
|
/// isIdenticalTo - Return true if this instruction is identical to (same
|
|
|
|
/// opcode and same operands as) the specified instruction.
|
|
|
|
bool isIdenticalTo(const MachineInstr *Other) const {
|
|
|
|
if (Other->getOpcode() != getOpcode() ||
|
2006-10-20 22:44:45 +00:00
|
|
|
Other->getNumOperands() != getNumOperands())
|
2006-10-20 22:39:36 +00:00
|
|
|
return false;
|
|
|
|
for (unsigned i = 0, e = getNumOperands(); i != e; ++i)
|
|
|
|
if (!getOperand(i).isIdenticalTo(Other->getOperand(i)))
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
2002-10-29 19:41:18 +00:00
|
|
|
|
2004-05-23 20:58:02 +00:00
|
|
|
/// clone - Create a copy of 'this' instruction that is identical in
|
|
|
|
/// all ways except the the instruction has no parent, prev, or next.
|
2006-05-04 19:14:44 +00:00
|
|
|
MachineInstr* clone() const { return new MachineInstr(*this); }
|
2006-04-17 21:35:08 +00:00
|
|
|
|
|
|
|
/// removeFromParent - This method unlinks 'this' from the containing basic
|
|
|
|
/// block, and returns it, but does not delete it.
|
|
|
|
MachineInstr *removeFromParent();
|
|
|
|
|
|
|
|
/// eraseFromParent - This method unlinks 'this' from the containing basic
|
|
|
|
/// block and deletes it.
|
|
|
|
void eraseFromParent() {
|
|
|
|
delete removeFromParent();
|
|
|
|
}
|
2004-05-23 19:35:12 +00:00
|
|
|
|
2007-04-26 19:00:32 +00:00
|
|
|
/// findRegisterUseOperandIdx() - Returns the operand index that is a use of
|
2007-03-26 22:37:45 +00:00
|
|
|
/// the specific register or -1 if it is not found. It further tightening
|
2007-02-23 01:04:26 +00:00
|
|
|
/// the search criteria to a use that kills the register if isKill is true.
|
2007-05-29 18:35:22 +00:00
|
|
|
int findRegisterUseOperandIdx(unsigned Reg, bool isKill = false) const;
|
2006-12-06 08:27:42 +00:00
|
|
|
|
2007-02-19 21:49:54 +00:00
|
|
|
/// findRegisterDefOperand() - Returns the MachineOperand that is a def of
|
|
|
|
/// the specific register or NULL if it is not found.
|
|
|
|
MachineOperand *findRegisterDefOperand(unsigned Reg);
|
2007-05-15 01:26:09 +00:00
|
|
|
|
2007-05-29 18:35:22 +00:00
|
|
|
/// findFirstPredOperandIdx() - Find the index of the first operand in the
|
|
|
|
/// operand list that is used to represent the predicate. It returns -1 if
|
|
|
|
/// none is found.
|
|
|
|
int findFirstPredOperandIdx() const;
|
2007-02-19 21:49:54 +00:00
|
|
|
|
2007-10-12 08:50:34 +00:00
|
|
|
/// isRegReDefinedByTwoAddr - Returns true if the Reg re-definition is due
|
|
|
|
/// to two addr elimination.
|
|
|
|
bool isRegReDefinedByTwoAddr(unsigned Reg) const;
|
|
|
|
|
2006-11-15 20:48:17 +00:00
|
|
|
/// copyKillDeadInfo - Copies kill / dead operand properties from MI.
|
|
|
|
///
|
2006-12-06 08:27:42 +00:00
|
|
|
void copyKillDeadInfo(const MachineInstr *MI);
|
2006-11-15 20:48:17 +00:00
|
|
|
|
2007-05-15 01:26:09 +00:00
|
|
|
/// copyPredicates - Copies predicate operand(s) from MI.
|
|
|
|
void copyPredicates(const MachineInstr *MI);
|
|
|
|
|
2001-10-11 04:23:19 +00:00
|
|
|
//
|
|
|
|
// Debugging support
|
2002-10-30 00:46:48 +00:00
|
|
|
//
|
2006-12-17 05:15:13 +00:00
|
|
|
void print(std::ostream *OS, const TargetMachine *TM) const {
|
|
|
|
if (OS) print(*OS, TM);
|
2006-11-28 22:21:29 +00:00
|
|
|
}
|
2004-06-25 00:13:11 +00:00
|
|
|
void print(std::ostream &OS, const TargetMachine *TM) const;
|
2006-12-16 02:15:42 +00:00
|
|
|
void print(std::ostream &OS) const;
|
2006-12-17 05:15:13 +00:00
|
|
|
void print(std::ostream *OS) const { if (OS) print(*OS); }
|
2002-10-28 04:24:49 +00:00
|
|
|
void dump() const;
|
2006-12-16 02:15:42 +00:00
|
|
|
friend std::ostream& operator<<(std::ostream& os, const MachineInstr& minstr){
|
|
|
|
minstr.print(os);
|
|
|
|
return os;
|
|
|
|
}
|
2002-02-05 06:02:59 +00:00
|
|
|
|
2002-10-28 20:48:39 +00:00
|
|
|
//===--------------------------------------------------------------------===//
|
2006-05-04 19:14:44 +00:00
|
|
|
// Accessors to add operands when building up machine instructions.
|
2002-10-28 20:48:39 +00:00
|
|
|
//
|
2007-12-30 00:29:19 +00:00
|
|
|
void addOperand(const MachineOperand &Op) {
|
|
|
|
bool isImpReg = Op.isRegister() && Op.isImplicit();
|
|
|
|
assert((isImpReg || !OperandsComplete()) &&
|
|
|
|
"Trying to add an operand to a machine instr that is already done!");
|
|
|
|
if (isImpReg || NumImplicitOps == 0) // This is true most of the time.
|
|
|
|
Operands.push_back(Op);
|
|
|
|
else
|
|
|
|
// Insert a real operand before any implicit ones.
|
|
|
|
Operands.insert(Operands.begin()+Operands.size()-NumImplicitOps, Op);
|
|
|
|
}
|
2007-12-30 00:45:46 +00:00
|
|
|
|
2002-12-28 20:05:44 +00:00
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
// Accessors used to modify instructions in place.
|
|
|
|
//
|
|
|
|
|
2006-11-30 07:08:44 +00:00
|
|
|
/// setInstrDescriptor - Replace the instruction descriptor (thus opcode) of
|
|
|
|
/// the current instruction with a new one.
|
2003-01-13 00:18:17 +00:00
|
|
|
///
|
2006-11-30 07:08:44 +00:00
|
|
|
void setInstrDescriptor(const TargetInstrDescriptor &tid) { TID = &tid; }
|
2003-01-13 00:18:17 +00:00
|
|
|
|
|
|
|
/// RemoveOperand - Erase an operand from an instruction, leaving it with one
|
|
|
|
/// fewer operand than it started with.
|
|
|
|
///
|
|
|
|
void RemoveOperand(unsigned i) {
|
2006-05-04 19:14:44 +00:00
|
|
|
Operands.erase(Operands.begin()+i);
|
|
|
|
}
|
|
|
|
private:
|
2006-11-13 23:34:06 +00:00
|
|
|
|
|
|
|
/// addImplicitDefUseOperands - Add all implicit def and use operands to
|
|
|
|
/// this instruction.
|
2006-11-30 07:08:44 +00:00
|
|
|
void addImplicitDefUseOperands();
|
2001-10-11 04:23:19 +00:00
|
|
|
};
|
2001-07-21 12:39:03 +00:00
|
|
|
|
2003-06-03 15:42:53 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2001-10-10 20:50:20 +00:00
|
|
|
// Debugging Support
|
|
|
|
|
2003-06-03 15:42:53 +00:00
|
|
|
std::ostream& operator<<(std::ostream &OS, const MachineInstr &MI);
|
2001-08-28 23:11:46 +00:00
|
|
|
|
2003-11-11 22:41:34 +00:00
|
|
|
} // End llvm namespace
|
|
|
|
|
2001-07-21 12:39:03 +00:00
|
|
|
#endif
|