Changed the fundemental architecture of Operands for Instructions. Now
[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
17 class Instruction : public User {
18   BasicBlock *Parent;
19   unsigned iType;      // InstructionType
20
21   friend class ValueHolder<Instruction,BasicBlock>;
22   inline void setParent(BasicBlock *P) { Parent = P; }
23
24 public:
25   Instruction(const Type *Ty, unsigned iType, const string &Name = "");
26   virtual ~Instruction();  // Virtual dtor == good.
27
28   // Specialize setName to handle symbol table majik...
29   virtual void setName(const string &name);
30
31   // clone() - Create a copy of 'this' instruction that is identical in all ways
32   // except the following:
33   //   * The instruction has no parent
34   //   * The instruction has no name
35   //
36   virtual Instruction *clone() const = 0;
37
38   // Accessor methods...
39   //
40   inline const BasicBlock *getParent() const { return Parent; }
41   inline       BasicBlock *getParent()       { return Parent; }
42   bool hasSideEffects() const { return false; }  // Memory & Call insts = true
43
44   // ---------------------------------------------------------------------------
45   // Subclass classification... getInstType() returns a member of 
46   // one of the enums that is coming soon (down below)...
47   //
48   virtual string getOpcode() const = 0;
49
50   unsigned getInstType() const { return iType; }
51   inline bool isTerminator() const {   // Instance of TerminatorInst?
52     return iType >= FirstTermOp && iType < NumTermOps; 
53   }
54   inline bool isDefinition() const { return !isTerminator(); }
55   inline bool isUnaryOp() const {
56     return iType >= FirstUnaryOp && iType < NumUnaryOps;
57   }
58   inline bool isBinaryOp() const {
59     return iType >= FirstBinaryOp && iType < NumBinaryOps;
60   }
61
62   // isPHINode() - This is used frequently enough to allow it to exist
63   inline bool isPHINode() const { return iType == PHINode; }
64
65
66   //----------------------------------------------------------------------
67   // Exported enumerations...
68   //
69   enum TermOps {       // These terminate basic blocks
70     FirstTermOp = 1,
71     Ret = 1, Br, Switch, 
72     NumTermOps         // Must remain at end of enum
73   };
74
75   enum UnaryOps {
76     FirstUnaryOp = NumTermOps,
77     Neg          = NumTermOps, Not, 
78     
79     // Type conversions...
80     ToBoolTy  , 
81     ToUByteTy , ToSByteTy,  ToUShortTy, ToShortTy,
82     ToUInt    , ToInt,      ToULongTy , ToLongTy,
83
84     ToFloatTy , ToDoubleTy, ToArrayTy , ToPointerTy,
85
86     NumUnaryOps        // Must remain at end of enum
87   };
88
89   enum BinaryOps {
90     // Standard binary operators...
91     FirstBinaryOp = NumUnaryOps,
92     Add = NumUnaryOps, Sub, Mul, Div, Rem,
93
94     // Logical operators...
95     And, Or, Xor,
96
97     // Binary comparison operators...
98     SetEQ, SetNE, SetLE, SetGE, SetLT, SetGT,
99
100     NumBinaryOps
101   };
102
103   enum MemoryOps {
104     FirstMemoryOp = NumBinaryOps,
105     Malloc = NumBinaryOps, Free,     // Heap management instructions
106     Alloca,                          // Stack management instruction
107
108     Load, Store,                     // Memory manipulation instructions.
109
110     GetField, PutField,              // Structure manipulation instructions
111
112     NumMemoryOps
113   };
114
115   enum OtherOps {
116     FirstOtherOp = NumMemoryOps,
117     PHINode      = NumMemoryOps,     // PHI node instruction
118     Call,                            // Call a function
119
120     Shl, Shr,                        // Shift operations...
121
122     NumOps,                          // Must be the last 'op' defined.
123     UserOp1, UserOp2                 // May be used internally to a pass...
124   };
125 };
126
127 #endif