*** empty log message ***
[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 template<typename SC> struct ilist_traits;
13 template<typename ValueSubClass, typename ItemParentClass, typename SymTabClass,
14          typename SubClass> class SymbolTableListTraits;
15
16 class Instruction : public User {
17   BasicBlock *Parent;
18   Instruction *Prev, *Next; // Next and Prev links for our intrusive linked list
19
20   void setNext(Instruction *N) { Next = N; }
21   void setPrev(Instruction *N) { Prev = N; }
22
23   friend class SymbolTableListTraits<Instruction, BasicBlock, Function,
24                                      ilist_traits<Instruction> >;
25   inline void setParent(BasicBlock *P) { Parent = P; }
26 protected:
27   unsigned iType;      // InstructionType
28 public:
29   Instruction(const Type *Ty, unsigned iType, const std::string &Name = "");
30   virtual ~Instruction() {
31     assert(Parent == 0 && "Instruction still embedded in basic block!");
32   }
33
34   // Specialize setName to handle symbol table majik...
35   virtual void setName(const std::string &name, SymbolTable *ST = 0);
36   
37   // clone() - Create a copy of 'this' instruction that is identical in all ways
38   // except the following:
39   //   * The instruction has no parent
40   //   * The instruction has no name
41   //
42   virtual Instruction *clone() const = 0;
43   
44   // Accessor methods...
45   //
46   inline const BasicBlock *getParent() const { return Parent; }
47   inline       BasicBlock *getParent()       { return Parent; }
48
49   // getNext/Prev - Return the next or previous instruction in the list.  The
50   // last node in the list is a terminator instruction.
51         Instruction *getNext()       { return Next; }
52   const Instruction *getNext() const { return Next; }
53         Instruction *getPrev()       { return Prev; }
54   const Instruction *getPrev() const { return Prev; }
55
56   virtual bool hasSideEffects() const { return false; }  // Memory & Call insts
57
58   // ---------------------------------------------------------------------------
59   // Subclass classification... getOpcode() 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   inline bool isTerminator() const {   // Instance of TerminatorInst?
66     return iType >= FirstTermOp && iType < NumTermOps;
67   }
68   inline bool isDefinition() const { return !isTerminator(); }
69   inline bool isUnaryOp() const {
70     return iType >= FirstUnaryOp && iType < NumUnaryOps;
71   }
72   inline bool isBinaryOp() const {
73     return iType >= FirstBinaryOp && iType < NumBinaryOps;
74   }
75
76   virtual void print(std::ostream &OS) const;
77
78   // Methods for support type inquiry through isa, cast, and dyn_cast:
79   static inline bool classof(const Instruction *I) { return true; }
80   static inline bool classof(const Value *V) {
81     return V->getValueType() == Value::InstructionVal;
82   }
83   
84   //----------------------------------------------------------------------
85   // Exported enumerations...
86   //
87   enum TermOps {       // These terminate basic blocks
88 #define  FIRST_TERM_INST(N)             FirstTermOp = N,
89 #define HANDLE_TERM_INST(N, OPC, CLASS) OPC = N,
90 #define   LAST_TERM_INST(N)             NumTermOps = N+1,
91 #include "llvm/Instruction.def"
92   };
93
94   enum UnaryOps {
95 #define  FIRST_UNARY_INST(N)             FirstUnaryOp = N,
96 #define HANDLE_UNARY_INST(N, OPC, CLASS) OPC = N,
97 #define   LAST_UNARY_INST(N)             NumUnaryOps = N+1,
98 #include "llvm/Instruction.def"
99   };
100
101   enum BinaryOps {
102 #define  FIRST_BINARY_INST(N)             FirstBinaryOp = N,
103 #define HANDLE_BINARY_INST(N, OPC, CLASS) OPC = N,
104 #define   LAST_BINARY_INST(N)             NumBinaryOps = N+1,
105 #include "llvm/Instruction.def"
106   };
107
108   enum MemoryOps {
109 #define  FIRST_MEMORY_INST(N)             FirstMemoryOp = N,
110 #define HANDLE_MEMORY_INST(N, OPC, CLASS) OPC = N,
111 #define   LAST_MEMORY_INST(N)             NumMemoryOps = N+1,
112 #include "llvm/Instruction.def"
113   };
114
115   enum OtherOps {
116 #define  FIRST_OTHER_INST(N)             FirstOtherOp = N,
117 #define HANDLE_OTHER_INST(N, OPC, CLASS) OPC = N,
118 #define   LAST_OTHER_INST(N)             NumOtherOps = N+1,
119 #include "llvm/Instruction.def"
120   };
121 };
122
123 #endif