Neg instruction removed. Cast instruction implemented.
[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 const char *getOpcodeName() const = 0;
49   unsigned getOpcode() const { return iType; }
50
51   // getInstType is deprecated, use getOpcode() instead.
52   unsigned getInstType() const { return iType; }
53
54   inline bool isTerminator() const {   // Instance of TerminatorInst?
55     return iType >= FirstTermOp && iType < NumTermOps; 
56   }
57   inline bool isDefinition() const { return !isTerminator(); }
58   inline bool isUnaryOp() const {
59     return iType >= FirstUnaryOp && iType < NumUnaryOps;
60   }
61   inline bool isBinaryOp() const {
62     return iType >= FirstBinaryOp && iType < NumBinaryOps;
63   }
64
65   // isPHINode() - This is used frequently enough to allow it to exist
66   inline bool isPHINode() const { return iType == PHINode; }
67
68
69   //----------------------------------------------------------------------
70   // Exported enumerations...
71   //
72   enum TermOps {       // These terminate basic blocks
73     FirstTermOp = 1,
74     Ret = 1, Br, Switch, 
75     NumTermOps         // Must remain at end of enum
76   };
77
78   enum UnaryOps {
79     FirstUnaryOp = NumTermOps,
80     Not          = NumTermOps,      // Binary inverse
81     Cast,                           // Type cast...
82
83     NumUnaryOps        // Must remain at end of enum
84   };
85
86   enum BinaryOps {
87     // Standard binary operators...
88     FirstBinaryOp = NumUnaryOps,
89     Add = NumUnaryOps, Sub, Mul, Div, Rem,
90
91     // Logical operators...
92     And, Or, Xor,
93
94     // Binary comparison operators...
95     SetEQ, SetNE, SetLE, SetGE, SetLT, SetGT,
96
97     NumBinaryOps
98   };
99
100   enum MemoryOps {
101     FirstMemoryOp = NumBinaryOps,
102     Malloc = NumBinaryOps, Free,     // Heap management instructions
103     Alloca,                          // Stack management instruction
104
105     Load, Store,                     // Memory manipulation instructions.
106
107     GetField, PutField,              // Structure manipulation instructions
108
109     NumMemoryOps
110   };
111
112   enum OtherOps {
113     FirstOtherOp = NumMemoryOps,
114     PHINode      = NumMemoryOps,     // PHI node instruction
115     Call,                            // Call a function
116
117     Shl, Shr,                        // Shift operations...
118
119     NumOps,                          // Must be the last 'op' defined.
120     UserOp1, UserOp2                 // May be used internally to a pass...
121   };
122 };
123
124 #endif