1 //===-- llvm/Instruction.h - Instruction class definition --------*- C++ -*--=//
3 // This file contains the declaration of the Instruction class, which is the
4 // base class for all of the VM instructions.
6 //===----------------------------------------------------------------------===//
8 #ifndef LLVM_INSTRUCTION_H
9 #define LLVM_INSTRUCTION_H
11 #include "llvm/User.h"
17 class MachineCodeForVMInstr;
19 class Instruction : public User {
21 unsigned iType; // InstructionType
23 MachineCodeForVMInstr* machineInstrVec;
24 friend class ValueHolder<Instruction,BasicBlock,Method>;
25 inline void setParent(BasicBlock *P) { Parent = P; }
28 Instruction(const Type *Ty, unsigned iType, const string &Name = "");
29 virtual ~Instruction(); // Virtual dtor == good.
31 // Specialize setName to handle symbol table majik...
32 virtual void setName(const string &name, SymbolTable *ST = 0);
34 // clone() - Create a copy of 'this' instruction that is identical in all ways
35 // except the following:
36 // * The instruction has no parent
37 // * The instruction has no name
39 virtual Instruction *clone() const = 0;
41 // Accessor methods...
43 inline const BasicBlock *getParent() const { return Parent; }
44 inline BasicBlock *getParent() { return Parent; }
45 virtual bool hasSideEffects() const { return false; } // Memory & Call insts
47 // ---------------------------------------------------------------------------
48 // Machine code accessors...
50 inline MachineCodeForVMInstr &getMachineInstrVec() const {
51 return *machineInstrVec;
54 // Add a machine instruction used to implement this instruction
56 void addMachineInstruction(MachineInstr* minstr);
58 // ---------------------------------------------------------------------------
59 // Subclass classification... getInstType() returns a member of
60 // one of the enums that is coming soon (down below)...
62 virtual const char *getOpcodeName() const = 0;
63 unsigned getOpcode() const { return iType; }
65 // getInstType is deprecated, use getOpcode() instead.
66 unsigned getInstType() const { return iType; }
68 inline bool isTerminator() const { // Instance of TerminatorInst?
69 return iType >= FirstTermOp && iType < NumTermOps;
71 inline bool isDefinition() const { return !isTerminator(); }
72 inline bool isUnaryOp() const {
73 return iType >= FirstUnaryOp && iType < NumUnaryOps;
75 inline bool isBinaryOp() const {
76 return iType >= FirstBinaryOp && iType < NumBinaryOps;
79 // dropAllReferences() - This function is in charge of "letting go" of all
80 // objects that this Instruction refers to. This first lets go of all
81 // references to hidden values generated code for this instruction,
82 // and then drops all references to its operands.
84 void dropAllReferences();
87 // Methods for support type inquiry through isa, cast, and dyn_cast:
88 static inline bool classof(const Instruction *I) { return true; }
89 static inline bool classof(const Value *V) {
90 return V->getValueType() == Value::InstructionVal;
93 //----------------------------------------------------------------------
94 // Exported enumerations...
96 enum TermOps { // These terminate basic blocks
97 #define FIRST_TERM_INST(N) FirstTermOp = N,
98 #define HANDLE_TERM_INST(N, OPC, CLASS) OPC = N,
99 #define LAST_TERM_INST(N) NumTermOps = N+1,
100 #include "llvm/Instruction.def"
104 #define FIRST_UNARY_INST(N) FirstUnaryOp = N,
105 #define HANDLE_UNARY_INST(N, OPC, CLASS) OPC = N,
106 #define LAST_UNARY_INST(N) NumUnaryOps = N+1,
107 #include "llvm/Instruction.def"
111 #define FIRST_BINARY_INST(N) FirstBinaryOp = N,
112 #define HANDLE_BINARY_INST(N, OPC, CLASS) OPC = N,
113 #define LAST_BINARY_INST(N) NumBinaryOps = N+1,
114 #include "llvm/Instruction.def"
118 #define FIRST_MEMORY_INST(N) FirstMemoryOp = N,
119 #define HANDLE_MEMORY_INST(N, OPC, CLASS) OPC = N,
120 #define LAST_MEMORY_INST(N) NumMemoryOps = N+1,
121 #include "llvm/Instruction.def"
125 #define FIRST_OTHER_INST(N) FirstOtherOp = N,
126 #define HANDLE_OTHER_INST(N, OPC, CLASS) OPC = N,
127 #define LAST_OTHER_INST(N) NumOtherOps = N+1,
128 #include "llvm/Instruction.def"