Create a static version of Instruction::getOpcodeName(opCode) that
[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   unsigned getOpcode() const { return iType; }
63   virtual const char *getOpcodeName() const {
64     return getOpcodeName(getOpcode());
65   }
66   static const char* getOpcodeName(unsigned OpCode);
67
68   inline bool isTerminator() const {   // Instance of TerminatorInst?
69     return iType >= FirstTermOp && iType < NumTermOps;
70   }
71   inline bool isDefinition() const { return !isTerminator(); }
72   inline bool isUnaryOp() const {
73     return iType >= FirstUnaryOp && iType < NumUnaryOps;
74   }
75   inline bool isBinaryOp() const {
76     return iType >= FirstBinaryOp && iType < NumBinaryOps;
77   }
78
79   virtual void print(std::ostream &OS) const;
80
81   // Methods for support type inquiry through isa, cast, and dyn_cast:
82   static inline bool classof(const Instruction *I) { return true; }
83   static inline bool classof(const Value *V) {
84     return V->getValueType() == Value::InstructionVal;
85   }
86   
87   //----------------------------------------------------------------------
88   // Exported enumerations...
89   //
90   enum TermOps {       // These terminate basic blocks
91 #define  FIRST_TERM_INST(N)             FirstTermOp = N,
92 #define HANDLE_TERM_INST(N, OPC, CLASS) OPC = N,
93 #define   LAST_TERM_INST(N)             NumTermOps = N+1,
94 #include "llvm/Instruction.def"
95   };
96
97   enum UnaryOps {
98 #define  FIRST_UNARY_INST(N)             FirstUnaryOp = N,
99 #define HANDLE_UNARY_INST(N, OPC, CLASS) OPC = N,
100 #define   LAST_UNARY_INST(N)             NumUnaryOps = N+1,
101 #include "llvm/Instruction.def"
102   };
103
104   enum BinaryOps {
105 #define  FIRST_BINARY_INST(N)             FirstBinaryOp = N,
106 #define HANDLE_BINARY_INST(N, OPC, CLASS) OPC = N,
107 #define   LAST_BINARY_INST(N)             NumBinaryOps = N+1,
108 #include "llvm/Instruction.def"
109   };
110
111   enum MemoryOps {
112 #define  FIRST_MEMORY_INST(N)             FirstMemoryOp = N,
113 #define HANDLE_MEMORY_INST(N, OPC, CLASS) OPC = N,
114 #define   LAST_MEMORY_INST(N)             NumMemoryOps = N+1,
115 #include "llvm/Instruction.def"
116   };
117
118   enum OtherOps {
119 #define  FIRST_OTHER_INST(N)             FirstOtherOp = N,
120 #define HANDLE_OTHER_INST(N, OPC, CLASS) OPC = N,
121 #define   LAST_OTHER_INST(N)             NumOtherOps = N+1,
122 #include "llvm/Instruction.def"
123   };
124 };
125
126 #endif