fefc1a4ff1b8894981a2b55f1f2d9c53bd31f48e
[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 <vector>
12 #include "llvm/User.h"
13
14 class Type;
15 class BasicBlock;
16 class Method;
17 class MachineInstr;             // do not include header file MachineInstr.h
18 class MachineCodeForVMInstr;
19
20 class Instruction : public User {
21   BasicBlock *Parent;
22   unsigned iType;      // InstructionType
23
24   MachineCodeForVMInstr* machineInstrVec;
25   friend class ValueHolder<Instruction,BasicBlock,Method>;
26   inline void setParent(BasicBlock *P) { Parent = P; }
27
28 public:
29   Instruction(const Type *Ty, unsigned iType, const string &Name = "");
30   virtual ~Instruction();  // Virtual dtor == good.
31
32   // Specialize setName to handle symbol table majik...
33   virtual void setName(const string &name);
34   
35   // clone() - Create a copy of 'this' instruction that is identical in all ways
36   // except the following:
37   //   * The instruction has no parent
38   //   * The instruction has no name
39   //
40   virtual Instruction *clone() const = 0;
41   
42   // Add a machine instruction used to implement this instruction
43   //
44   void addMachineInstruction(MachineInstr* minstr);
45   
46   // Accessor methods...
47   //
48   inline const BasicBlock *getParent() const { return Parent; }
49   inline       BasicBlock *getParent()       { return Parent; }
50   virtual bool hasSideEffects() const { return false; }  // Memory & Call insts
51   inline       MachineCodeForVMInstr&
52                 getMachineInstrVec()         { return *machineInstrVec; }
53   const vector<Value*>&
54                 getTempValuesForMachineCode() const;
55   
56   // ---------------------------------------------------------------------------
57   // Subclass classification... getInstType() returns a member of 
58   // one of the enums that is coming soon (down below)...
59   //
60   virtual const char *getOpcodeName() const = 0;
61   unsigned getOpcode() const { return iType; }
62
63   // getInstType is deprecated, use getOpcode() instead.
64   unsigned getInstType() const { return iType; }
65
66   inline bool isTerminator() const {   // Instance of TerminatorInst?
67     return iType >= FirstTermOp && iType < NumTermOps; 
68   }
69   inline bool isDefinition() const { return !isTerminator(); }
70   inline bool isUnaryOp() const {
71     return iType >= FirstUnaryOp && iType < NumUnaryOps;
72   }
73   inline bool isBinaryOp() const {
74     return iType >= FirstBinaryOp && iType < NumBinaryOps;
75   }
76
77   // isPHINode() - This is used frequently enough to allow it to exist
78   inline bool isPHINode() const { return iType == PHINode; }
79
80   // dropAllReferences() - This function is in charge of "letting go" of all
81   // objects that this Instruction refers to.  This first lets go of all
82   // references to hidden values generated code for this instruction,
83   // and then drops all references to its operands.
84   // 
85   void dropAllReferences();
86   
87   //----------------------------------------------------------------------
88   // Exported enumerations...
89   //
90   enum TermOps {       // These terminate basic blocks
91     FirstTermOp = 1,
92     Ret = 1, Br, Switch, 
93     NumTermOps         // Must remain at end of enum
94   };
95
96   enum UnaryOps {
97     FirstUnaryOp = NumTermOps,
98     Not          = NumTermOps,      // Binary inverse
99
100     NumUnaryOps        // Must remain at end of enum
101   };
102
103   enum BinaryOps {
104     // Standard binary operators...
105     FirstBinaryOp = NumUnaryOps,
106     Add = NumUnaryOps, Sub, Mul, Div, Rem,
107
108     // Logical operators...
109     And, Or, Xor,
110
111     // Binary comparison operators...
112     SetEQ, SetNE, SetLE, SetGE, SetLT, SetGT,
113
114     NumBinaryOps
115   };
116
117   enum MemoryOps {
118     FirstMemoryOp = NumBinaryOps,
119     Malloc = NumBinaryOps, Free,     // Heap management instructions
120     Alloca,                          // Stack management instruction
121
122     Load, Store,                     // Memory manipulation instructions.
123     GetElementPtr,                   // Get addr of Structure or Array element
124
125     NumMemoryOps
126   };
127
128   enum OtherOps {
129     FirstOtherOp = NumMemoryOps,
130     PHINode      = NumMemoryOps,     // PHI node instruction
131     Cast,                            // Type cast...
132     Call,                            // Call a function
133
134     Shl, Shr,                        // Shift operations...
135
136     NumOps,                          // Must be the last 'op' defined.
137     UserOp1, UserOp2                 // May be used internally to a pass...
138   };
139 };
140
141 #endif