Changes to build successfully with GCC 3.02
[oota-llvm.git] / include / llvm / InstrTypes.h
1 //===-- llvm/InstrTypes.h - Important Instruction subclasses -----*- C++ -*--=//
2 //
3 // This file defines various meta classes of instructions that exist in the VM
4 // representation.  Specific concrete subclasses of these may be found in the 
5 // i*.h files...
6 //
7 //===----------------------------------------------------------------------===//
8
9 #ifndef LLVM_INSTRUCTION_TYPES_H
10 #define LLVM_INSTRUCTION_TYPES_H
11
12 #include "llvm/Instruction.h"
13
14 class Method;
15 class SymTabValue;
16
17 //===----------------------------------------------------------------------===//
18 //                            TerminatorInst Class
19 //===----------------------------------------------------------------------===//
20
21 // TerminatorInst - Subclasses of this class are all able to terminate a basic 
22 // block.  Thus, these are all the flow control type of operations.
23 //
24 class TerminatorInst : public Instruction {
25 public:
26   TerminatorInst(Instruction::TermOps iType);
27   TerminatorInst(const Type *Ty, Instruction::TermOps iType,
28                  const std::string &Name = "");
29   inline ~TerminatorInst() {}
30
31   // Terminators must implement the methods required by Instruction...
32   virtual Instruction *clone() const = 0;
33   virtual const char *getOpcodeName() const = 0;
34
35   // Additionally, they must provide a method to get at the successors of this
36   // terminator instruction.  If 'idx' is out of range, a null pointer shall be
37   // returned.
38   //
39   virtual const BasicBlock *getSuccessor(unsigned idx) const = 0;
40   virtual unsigned getNumSuccessors() const = 0;
41
42   inline BasicBlock *getSuccessor(unsigned idx) {
43     return (BasicBlock*)((const TerminatorInst *)this)->getSuccessor(idx);
44   }
45
46   // Methods for support type inquiry through isa, cast, and dyn_cast:
47   static inline bool classof(const TerminatorInst *) { return true; }
48   static inline bool classof(const Instruction *I) {
49     return I->getOpcode() >= FirstTermOp && I->getOpcode() < NumTermOps; 
50   }
51   static inline bool classof(const Value *V) {
52     return isa<Instruction>(V) && classof(cast<Instruction>(V));
53   }
54 };
55
56
57 //===----------------------------------------------------------------------===//
58 //                            UnaryOperator Class
59 //===----------------------------------------------------------------------===//
60
61 class UnaryOperator : public Instruction {
62 public:
63
64   // create() - Construct a unary instruction, given the opcode
65   // and its operand.
66   //
67   static UnaryOperator *create(UnaryOps Op, Value *Source);
68
69   UnaryOperator(Value *S, UnaryOps iType, const std::string &Name = "")
70       : Instruction(S->getType(), iType, Name) {
71     Operands.reserve(1);
72     Operands.push_back(Use(S, this));
73   }
74
75   inline UnaryOps getOpcode() const { 
76     return (UnaryOps)Instruction::getOpcode();
77   }
78
79   virtual Instruction *clone() const { 
80     return create(getOpcode(), Operands[0]);
81   }
82
83   virtual const char *getOpcodeName() const = 0;
84
85   // Methods for support type inquiry through isa, cast, and dyn_cast:
86   static inline bool classof(const UnaryOperator *) { return true; }
87   static inline bool classof(const Instruction *I) {
88     return I->getOpcode() >= FirstUnaryOp && I->getOpcode() < NumUnaryOps; 
89   }
90   static inline bool classof(const Value *V) {
91     return isa<Instruction>(V) && classof(cast<Instruction>(V));
92   }
93 };
94
95
96
97 //===----------------------------------------------------------------------===//
98 //                           BinaryOperator Class
99 //===----------------------------------------------------------------------===//
100
101 class BinaryOperator : public Instruction {
102 public:
103
104   // create() - Construct a binary instruction, given the opcode
105   // and the two operands.
106   //
107   static BinaryOperator *create(BinaryOps Op, Value *S1, Value *S2,
108                                 const std::string &Name = "");
109
110   BinaryOperator(BinaryOps iType, Value *S1, Value *S2, 
111                  const std::string &Name = "") 
112     : Instruction(S1->getType(), iType, Name) {
113     Operands.reserve(2);
114     Operands.push_back(Use(S1, this));
115     Operands.push_back(Use(S2, this));
116     assert(Operands[0] && Operands[1] && 
117            Operands[0]->getType() == Operands[1]->getType());
118   }
119
120   inline BinaryOps getOpcode() const { 
121     return (BinaryOps)Instruction::getOpcode();
122   }
123
124   virtual Instruction *clone() const {
125     return create(getOpcode(), Operands[0], Operands[1]);
126   }
127
128   virtual const char *getOpcodeName() const = 0;
129
130   // swapOperands - Exchange the two operands to this instruction.
131   // This instruction is safe to use on any binary instruction and
132   // does not modify the semantics of the instruction.  If the
133   // instruction is order dependant (SetLT f.e.) the opcode is
134   // changed.  If the instruction cannot be reversed (ie, it's a Div),
135   // then return true.
136   //
137   bool swapOperands();
138
139   // Methods for support type inquiry through isa, cast, and dyn_cast:
140   static inline bool classof(const BinaryOperator *) { return true; }
141   static inline bool classof(const Instruction *I) {
142     return I->getOpcode() >= FirstBinaryOp && I->getOpcode() < NumBinaryOps; 
143   }
144   static inline bool classof(const Value *V) {
145     return isa<Instruction>(V) && classof(cast<Instruction>(V));
146   }
147 };
148
149 #endif