* Clean up some comments
[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 LLVM 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   void setParent(BasicBlock *P);
26 protected:
27   unsigned iType;      // InstructionType: The opcode of the instruction
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
38   /// ways 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 isBinaryOp() const {
72     return iType >= FirstBinaryOp && iType < NumBinaryOps;
73   }
74
75   virtual void print(std::ostream &OS) const;
76
77   /// Methods for support type inquiry through isa, cast, and dyn_cast:
78   static inline bool classof(const Instruction *I) { return true; }
79   static inline bool classof(const Value *V) {
80     return V->getValueType() == Value::InstructionVal;
81   }
82   
83   //----------------------------------------------------------------------
84   // Exported enumerations...
85   //
86   enum TermOps {       // These terminate basic blocks
87 #define  FIRST_TERM_INST(N)             FirstTermOp = N,
88 #define HANDLE_TERM_INST(N, OPC, CLASS) OPC = N,
89 #define   LAST_TERM_INST(N)             NumTermOps = N+1,
90 #include "llvm/Instruction.def"
91   };
92
93   enum BinaryOps {
94 #define  FIRST_BINARY_INST(N)             FirstBinaryOp = N,
95 #define HANDLE_BINARY_INST(N, OPC, CLASS) OPC = N,
96 #define   LAST_BINARY_INST(N)             NumBinaryOps = N+1,
97 #include "llvm/Instruction.def"
98   };
99
100   enum MemoryOps {
101 #define  FIRST_MEMORY_INST(N)             FirstMemoryOp = N,
102 #define HANDLE_MEMORY_INST(N, OPC, CLASS) OPC = N,
103 #define   LAST_MEMORY_INST(N)             NumMemoryOps = N+1,
104 #include "llvm/Instruction.def"
105   };
106
107   enum OtherOps {
108 #define  FIRST_OTHER_INST(N)             FirstOtherOp = N,
109 #define HANDLE_OTHER_INST(N, OPC, CLASS) OPC = N,
110 #define   LAST_OTHER_INST(N)             NumOtherOps = N+1,
111 #include "llvm/Instruction.def"
112   };
113 };
114
115 #endif