Remove unneeded dtors
[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
13 template<typename SC> struct ilist_traits;
14 template<typename ValueSubClass, typename ItemParentClass, typename SymTabClass,
15          typename SubClass> class SymbolTableListTraits;
16
17 class Instruction : public User {
18   BasicBlock *Parent;
19   Instruction *Prev, *Next; // Next and Prev links for our intrusive linked list
20
21   void setNext(Instruction *N) { Next = N; }
22   void setPrev(Instruction *N) { Prev = N; }
23
24   friend class SymbolTableListTraits<Instruction, BasicBlock, Function,
25                                      ilist_traits<Instruction> >;
26   void setParent(BasicBlock *P);
27 protected:
28   unsigned iType;      // InstructionType: The opcode of the instruction
29
30   Instruction(const Type *Ty, unsigned iType, const std::string &Name = "",
31               Instruction *InsertBefore = 0);
32 public:
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   /// mayWriteToMemory - Return true if this instruction may modify memory.
57   ///
58   virtual bool mayWriteToMemory() const { return false; }
59
60   // ---------------------------------------------------------------------------
61   /// Subclass classification... getOpcode() returns a member of 
62   /// one of the enums that is coming soon (down below)...
63   ///
64   unsigned getOpcode() const { return iType; }
65   virtual const char *getOpcodeName() const {
66     return getOpcodeName(getOpcode());
67   }
68   static const char* getOpcodeName(unsigned OpCode);
69
70   inline bool isTerminator() const {   // Instance of TerminatorInst?
71     return iType >= TermOpsBegin && iType < TermOpsEnd;
72   }
73   inline bool isBinaryOp() const {
74     return iType >= BinaryOpsBegin && iType < BinaryOpsEnd;
75   }
76
77   /// isAssociative - Return true if the instruction is associative:
78   ///
79   ///   Associative operators satisfy:  x op (y op z) === (x op y) op z
80   ///
81   /// In LLVM, the Add, Mul, And, Or, and Xor operators are associative, when
82   /// not applied to floating point types.
83   ///
84   bool isAssociative() const { return isAssociative(getOpcode(), getType()); }
85   static bool isAssociative(unsigned op, const Type *Ty);
86
87   /// isCommutative - Return true if the instruction is commutative:
88   ///
89   ///   Commutative operators satisfy: (x op y) === (y op x)
90   ///
91   /// In LLVM, these are the associative operators, plus SetEQ and SetNE, when
92   /// applied to any type.
93   ///
94   bool isCommutative() const { return isCommutative(getOpcode()); }
95   static bool isCommutative(unsigned op);
96
97   /// isTrappingInstruction - Return true if the instruction may trap.
98   ///
99   bool isTrapping() const {
100     return isTrapping(getOpcode()); 
101   }
102   static bool isTrapping(unsigned op);
103   
104   virtual void print(std::ostream &OS) const;
105
106   /// Methods for support type inquiry through isa, cast, and dyn_cast:
107   static inline bool classof(const Instruction *I) { return true; }
108   static inline bool classof(const Value *V) {
109     return V->getValueType() == Value::InstructionVal;
110   }
111   
112   //----------------------------------------------------------------------
113   // Exported enumerations...
114   //
115   enum TermOps {       // These terminate basic blocks
116 #define  FIRST_TERM_INST(N)             TermOpsBegin = N,
117 #define HANDLE_TERM_INST(N, OPC, CLASS) OPC = N,
118 #define   LAST_TERM_INST(N)             TermOpsEnd = N+1,
119 #include "llvm/Instruction.def"
120   };
121
122   enum BinaryOps {
123 #define  FIRST_BINARY_INST(N)             BinaryOpsBegin = N,
124 #define HANDLE_BINARY_INST(N, OPC, CLASS) OPC = N,
125 #define   LAST_BINARY_INST(N)             BinaryOpsEnd = N+1,
126 #include "llvm/Instruction.def"
127   };
128
129   enum MemoryOps {
130 #define  FIRST_MEMORY_INST(N)             MemoryOpsBegin = N,
131 #define HANDLE_MEMORY_INST(N, OPC, CLASS) OPC = N,
132 #define   LAST_MEMORY_INST(N)             MemoryOpsEnd = N+1,
133 #include "llvm/Instruction.def"
134   };
135
136   enum OtherOps {
137 #define  FIRST_OTHER_INST(N)             OtherOpsBegin = N,
138 #define HANDLE_OTHER_INST(N, OPC, CLASS) OPC = N,
139 #define   LAST_OTHER_INST(N)             OtherOpsEnd = N+1,
140 #include "llvm/Instruction.def"
141   };
142 };
143
144 #endif