Add new opcode for Invoke instruction
[oota-llvm.git] / include / llvm / Instruction.h
1 //===-- llvm/Instruction.h - Instruction class definition --------*- C++ -*--=//
2 //
3 // This file contains the declaration of the Instruction class, which is the
4 // base class for all of the VM instructions.
5 //
6 //===----------------------------------------------------------------------===//
7
8 #ifndef LLVM_INSTRUCTION_H
9 #define LLVM_INSTRUCTION_H
10
11 #include "llvm/User.h"
12
13 class Type;
14 class BasicBlock;
15 class Method;
16 class MachineInstr;
17 class MachineCodeForVMInstr;
18
19 class Instruction : public User {
20   BasicBlock *Parent;
21   unsigned iType;      // InstructionType
22
23   MachineCodeForVMInstr* machineInstrVec;
24   friend class ValueHolder<Instruction,BasicBlock,Method>;
25   inline void setParent(BasicBlock *P) { Parent = P; }
26
27 public:
28   Instruction(const Type *Ty, unsigned iType, const string &Name = "");
29   virtual ~Instruction();  // Virtual dtor == good.
30
31   // Specialize setName to handle symbol table majik...
32   virtual void setName(const string &name, SymbolTable *ST = 0);
33   
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
38   //
39   virtual Instruction *clone() const = 0;
40   
41   // Accessor methods...
42   //
43   inline const BasicBlock *getParent() const { return Parent; }
44   inline       BasicBlock *getParent()       { return Parent; }
45   virtual bool hasSideEffects() const { return false; }  // Memory & Call insts
46
47   // ---------------------------------------------------------------------------
48   // Machine code accessors...
49   //
50   inline MachineCodeForVMInstr &getMachineInstrVec() const {
51     return *machineInstrVec; 
52   }
53   
54   // Add a machine instruction used to implement this instruction
55   //
56   void addMachineInstruction(MachineInstr* minstr);
57   
58   // ---------------------------------------------------------------------------
59   // Subclass classification... getInstType() returns a member of 
60   // one of the enums that is coming soon (down below)...
61   //
62   virtual const char *getOpcodeName() const = 0;
63   unsigned getOpcode() const { return iType; }
64
65   // getInstType is deprecated, use getOpcode() instead.
66   unsigned getInstType() const { return iType; }
67
68   inline bool isTerminator() const {   // Instance of TerminatorInst?
69     return iType >= FirstTermOp && iType < NumTermOps;
70   }
71   inline bool isDefinition() const { return !isTerminator(); }
72   inline bool isUnaryOp() const {
73     return iType >= FirstUnaryOp && iType < NumUnaryOps;
74   }
75   inline bool isBinaryOp() const {
76     return iType >= FirstBinaryOp && iType < NumBinaryOps;
77   }
78
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.
83   // 
84   void dropAllReferences();
85
86
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;
91   }
92   
93   //----------------------------------------------------------------------
94   // Exported enumerations...
95   //
96   enum TermOps {       // These terminate basic blocks
97     FirstTermOp = 1,
98     Ret = 1, Br, Switch, Invoke,
99     NumTermOps         // Must remain at end of enum
100   };
101
102   enum UnaryOps {
103     FirstUnaryOp = NumTermOps,
104     Not          = NumTermOps,      // Binary inverse
105
106     NumUnaryOps        // Must remain at end of enum
107   };
108
109   enum BinaryOps {
110     // Standard binary operators...
111     FirstBinaryOp = NumUnaryOps,
112     Add = NumUnaryOps, Sub, Mul, Div, Rem,
113
114     // Logical operators...
115     And, Or, Xor,
116
117     // Binary comparison operators...
118     SetEQ, SetNE, SetLE, SetGE, SetLT, SetGT,
119
120     NumBinaryOps
121   };
122
123   enum MemoryOps {
124     FirstMemoryOp = NumBinaryOps,
125     Malloc = NumBinaryOps, Free,     // Heap management instructions
126     Alloca,                          // Stack management instruction
127
128     Load, Store,                     // Memory manipulation instructions.
129     GetElementPtr,                   // Get addr of Structure or Array element
130
131     NumMemoryOps
132   };
133
134   enum OtherOps {
135     FirstOtherOp = NumMemoryOps,
136     PHINode      = NumMemoryOps,     // PHI node instruction
137     Cast,                            // Type cast...
138     Call,                            // Call a function
139
140     Shl, Shr,                        // Shift operations...
141
142     NumOps,                          // Must be the last 'op' defined.
143     UserOp1, UserOp2                 // May be used internally to a pass...
144   };
145 };
146
147 #endif