Remove unneeded #include
[oota-llvm.git] / include / llvm / Instruction.h
1 //===-- llvm/Instruction.h - Instruction class definition -------*- C++ -*-===//
2 // 
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
7 // 
8 //===----------------------------------------------------------------------===//
9 //
10 // This file contains the declaration of the Instruction class, which is the
11 // base class for all of the LLVM instructions.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #ifndef LLVM_INSTRUCTION_H
16 #define LLVM_INSTRUCTION_H
17
18 #include "llvm/User.h"
19
20 namespace llvm {
21
22 class AssemblyAnnotationWriter;
23
24 template<typename SC> struct ilist_traits;
25 template<typename ValueSubClass, typename ItemParentClass, typename SymTabClass,
26          typename SubClass> class SymbolTableListTraits;
27
28 class Instruction : public User {
29   BasicBlock *Parent;
30   Instruction *Prev, *Next; // Next and Prev links for our intrusive linked list
31
32   void setNext(Instruction *N) { Next = N; }
33   void setPrev(Instruction *N) { Prev = N; }
34
35   friend class SymbolTableListTraits<Instruction, BasicBlock, Function,
36                                      ilist_traits<Instruction> >;
37   void setParent(BasicBlock *P);
38 protected:
39   unsigned iType;      // InstructionType: The opcode of the instruction
40
41   Instruction(const Type *Ty, unsigned iType, const std::string &Name = "",
42               Instruction *InsertBefore = 0);
43 public:
44
45   // Specialize setName to handle symbol table majik...
46   virtual void setName(const std::string &name, SymbolTable *ST = 0);
47   
48   /// clone() - Create a copy of 'this' instruction that is identical in all
49   /// ways except the following:
50   ///   * The instruction has no parent
51   ///   * The instruction has no name
52   ///
53   virtual Instruction *clone() const = 0;
54   
55   // Accessor methods...
56   //
57   inline const BasicBlock *getParent() const { return Parent; }
58   inline       BasicBlock *getParent()       { return Parent; }
59
60   // getNext/Prev - Return the next or previous instruction in the list.  The
61   // last node in the list is a terminator instruction.
62         Instruction *getNext()       { return Next; }
63   const Instruction *getNext() const { return Next; }
64         Instruction *getPrev()       { return Prev; }
65   const Instruction *getPrev() const { return Prev; }
66
67   /// mayWriteToMemory - Return true if this instruction may modify memory.
68   ///
69   virtual bool mayWriteToMemory() const { return false; }
70
71   // ---------------------------------------------------------------------------
72   /// Subclass classification... getOpcode() returns a member of 
73   /// one of the enums that is coming soon (down below)...
74   ///
75   unsigned getOpcode() const { return iType; }
76   virtual const char *getOpcodeName() const {
77     return getOpcodeName(getOpcode());
78   }
79   static const char* getOpcodeName(unsigned OpCode);
80
81   inline bool isTerminator() const {   // Instance of TerminatorInst?
82     return iType >= TermOpsBegin && iType < TermOpsEnd;
83   }
84   inline bool isBinaryOp() const {
85     return iType >= BinaryOpsBegin && iType < BinaryOpsEnd;
86   }
87
88   /// isAssociative - Return true if the instruction is associative:
89   ///
90   ///   Associative operators satisfy:  x op (y op z) === (x op y) op z
91   ///
92   /// In LLVM, the Add, Mul, And, Or, and Xor operators are associative, when
93   /// not applied to floating point types.
94   ///
95   bool isAssociative() const { return isAssociative(getOpcode(), getType()); }
96   static bool isAssociative(unsigned op, const Type *Ty);
97
98   /// isCommutative - Return true if the instruction is commutative:
99   ///
100   ///   Commutative operators satisfy: (x op y) === (y op x)
101   ///
102   /// In LLVM, these are the associative operators, plus SetEQ and SetNE, when
103   /// applied to any type.
104   ///
105   bool isCommutative() const { return isCommutative(getOpcode()); }
106   static bool isCommutative(unsigned op);
107
108   /// isRelational - Return true if the instruction is a Set* instruction:
109   ///
110   bool isRelational() const { return isRelational(getOpcode()); }
111   static bool isRelational(unsigned op);
112
113
114   /// isTrappingInstruction - Return true if the instruction may trap.
115   ///
116   bool isTrapping() const {
117     return isTrapping(getOpcode()); 
118   }
119   static bool isTrapping(unsigned op);
120   
121   virtual void print(std::ostream &OS) const { print(OS, 0); }
122   void print(std::ostream &OS, AssemblyAnnotationWriter *AAW) const;
123
124   /// Methods for support type inquiry through isa, cast, and dyn_cast:
125   static inline bool classof(const Instruction *I) { return true; }
126   static inline bool classof(const Value *V) {
127     return V->getValueType() == Value::InstructionVal;
128   }
129   
130   //----------------------------------------------------------------------
131   // Exported enumerations...
132   //
133   enum TermOps {       // These terminate basic blocks
134 #define  FIRST_TERM_INST(N)             TermOpsBegin = N,
135 #define HANDLE_TERM_INST(N, OPC, CLASS) OPC = N,
136 #define   LAST_TERM_INST(N)             TermOpsEnd = N+1,
137 #include "llvm/Instruction.def"
138   };
139
140   enum BinaryOps {
141 #define  FIRST_BINARY_INST(N)             BinaryOpsBegin = N,
142 #define HANDLE_BINARY_INST(N, OPC, CLASS) OPC = N,
143 #define   LAST_BINARY_INST(N)             BinaryOpsEnd = N+1,
144 #include "llvm/Instruction.def"
145   };
146
147   enum MemoryOps {
148 #define  FIRST_MEMORY_INST(N)             MemoryOpsBegin = N,
149 #define HANDLE_MEMORY_INST(N, OPC, CLASS) OPC = N,
150 #define   LAST_MEMORY_INST(N)             MemoryOpsEnd = N+1,
151 #include "llvm/Instruction.def"
152   };
153
154   enum OtherOps {
155 #define  FIRST_OTHER_INST(N)             OtherOpsBegin = N,
156 #define HANDLE_OTHER_INST(N, OPC, CLASS) OPC = N,
157 #define   LAST_OTHER_INST(N)             OtherOpsEnd = N+1,
158 #include "llvm/Instruction.def"
159   };
160 };
161
162 } // End llvm namespace
163
164 #endif