* Inline destructor
[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 BasicBlock;
14 class Method;
15
16 class Instruction : public User {
17   BasicBlock *Parent;
18
19   friend class ValueHolder<Instruction,BasicBlock,Method>;
20   inline void setParent(BasicBlock *P) { Parent = P; }
21 protected:
22   unsigned iType;      // InstructionType
23 public:
24   Instruction(const Type *Ty, unsigned iType, const std::string &Name = "");
25   virtual ~Instruction() {
26     assert(Parent == 0 && "Instruction still embedded in basic block!");
27   }
28
29   // Specialize setName to handle symbol table majik...
30   virtual void setName(const std::string &name, SymbolTable *ST = 0);
31   
32   // clone() - Create a copy of 'this' instruction that is identical in all ways
33   // except the following:
34   //   * The instruction has no parent
35   //   * The instruction has no name
36   //
37   virtual Instruction *clone() const = 0;
38   
39   // Accessor methods...
40   //
41   inline const BasicBlock *getParent() const { return Parent; }
42   inline       BasicBlock *getParent()       { return Parent; }
43   virtual bool hasSideEffects() const { return false; }  // Memory & Call insts
44
45   // ---------------------------------------------------------------------------
46   // Subclass classification... getInstType() returns a member of 
47   // one of the enums that is coming soon (down below)...
48   //
49   virtual const char *getOpcodeName() const = 0;
50   unsigned getOpcode() const { return iType; }
51
52   // getInstType is deprecated, use getOpcode() instead.
53   unsigned getInstType() const { return iType; }
54
55   inline bool isTerminator() const {   // Instance of TerminatorInst?
56     return iType >= FirstTermOp && iType < NumTermOps;
57   }
58   inline bool isDefinition() const { return !isTerminator(); }
59   inline bool isUnaryOp() const {
60     return iType >= FirstUnaryOp && iType < NumUnaryOps;
61   }
62   inline bool isBinaryOp() const {
63     return iType >= FirstBinaryOp && iType < NumBinaryOps;
64   }
65
66   // Methods for support type inquiry through isa, cast, and dyn_cast:
67   static inline bool classof(const Instruction *I) { return true; }
68   static inline bool classof(const Value *V) {
69     return V->getValueType() == Value::InstructionVal;
70   }
71   
72   //----------------------------------------------------------------------
73   // Exported enumerations...
74   //
75   enum TermOps {       // These terminate basic blocks
76 #define  FIRST_TERM_INST(N)             FirstTermOp = N,
77 #define HANDLE_TERM_INST(N, OPC, CLASS) OPC = N,
78 #define   LAST_TERM_INST(N)             NumTermOps = N+1,
79 #include "llvm/Instruction.def"
80   };
81
82   enum UnaryOps {
83 #define  FIRST_UNARY_INST(N)             FirstUnaryOp = N,
84 #define HANDLE_UNARY_INST(N, OPC, CLASS) OPC = N,
85 #define   LAST_UNARY_INST(N)             NumUnaryOps = N+1,
86 #include "llvm/Instruction.def"
87   };
88
89   enum BinaryOps {
90 #define  FIRST_BINARY_INST(N)             FirstBinaryOp = N,
91 #define HANDLE_BINARY_INST(N, OPC, CLASS) OPC = N,
92 #define   LAST_BINARY_INST(N)             NumBinaryOps = N+1,
93 #include "llvm/Instruction.def"
94   };
95
96   enum MemoryOps {
97 #define  FIRST_MEMORY_INST(N)             FirstMemoryOp = N,
98 #define HANDLE_MEMORY_INST(N, OPC, CLASS) OPC = N,
99 #define   LAST_MEMORY_INST(N)             NumMemoryOps = N+1,
100 #include "llvm/Instruction.def"
101   };
102
103   enum OtherOps {
104 #define  FIRST_OTHER_INST(N)             FirstOtherOp = N,
105 #define HANDLE_OTHER_INST(N, OPC, CLASS) OPC = N,
106 #define   LAST_OTHER_INST(N)             NumOtherOps = N+1,
107 #include "llvm/Instruction.def"
108   };
109 };
110
111 #endif