Fix comment
[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 //===----------------------------------------------------------------------===//
15 //                            TerminatorInst Class
16 //===----------------------------------------------------------------------===//
17
18 // TerminatorInst - Subclasses of this class are all able to terminate a basic 
19 // block.  Thus, these are all the flow control type of operations.
20 //
21 class TerminatorInst : public Instruction {
22 protected:
23   TerminatorInst(Instruction::TermOps iType);
24   TerminatorInst(const Type *Ty, Instruction::TermOps iType,
25                  const std::string &Name = "");
26 public:
27
28   // Terminators must implement the methods required by Instruction...
29   virtual Instruction *clone() const = 0;
30   virtual const char *getOpcodeName() const = 0;
31
32   // Additionally, they must provide a method to get at the successors of this
33   // terminator instruction.  'idx' may not be >= the number of successors
34   // returned by getNumSuccessors()!
35   //
36   virtual const BasicBlock *getSuccessor(unsigned idx) const = 0;
37   virtual unsigned getNumSuccessors() const = 0;
38   
39   // Set a successor at a given index
40   virtual void setSuccessor(unsigned idx, BasicBlock *B) = 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 protected:
63   UnaryOperator(Value *S, UnaryOps iType, const std::string &Name = "")
64       : Instruction(S->getType(), iType, Name) {
65     Operands.reserve(1);
66     Operands.push_back(Use(S, this));
67   }
68 public:
69
70   // create() - Construct a unary instruction, given the opcode
71   // and its operand.
72   //
73   static UnaryOperator *create(UnaryOps Op, Value *Source);
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 protected:
103   BinaryOperator(BinaryOps iType, Value *S1, Value *S2, 
104                  const std::string &Name = "") 
105     : Instruction(S1->getType(), iType, Name) {
106     Operands.reserve(2);
107     Operands.push_back(Use(S1, this));
108     Operands.push_back(Use(S2, this));
109     assert(Operands[0] && Operands[1] && 
110            Operands[0]->getType() == Operands[1]->getType());
111   }
112
113 public:
114
115   // create() - Construct a binary instruction, given the opcode
116   // and the two operands.
117   //
118   static BinaryOperator *create(BinaryOps Op, Value *S1, Value *S2,
119                                 const std::string &Name = "");
120
121   inline BinaryOps getOpcode() const { 
122     return (BinaryOps)Instruction::getOpcode();
123   }
124
125   virtual Instruction *clone() const {
126     return create(getOpcode(), Operands[0], Operands[1]);
127   }
128
129   virtual const char *getOpcodeName() const = 0;
130
131   // swapOperands - Exchange the two operands to this instruction.
132   // This instruction is safe to use on any binary instruction and
133   // does not modify the semantics of the instruction.  If the
134   // instruction is order dependant (SetLT f.e.) the opcode is
135   // changed.  If the instruction cannot be reversed (ie, it's a Div),
136   // then return true.
137   //
138   bool swapOperands();
139
140   // Methods for support type inquiry through isa, cast, and dyn_cast:
141   static inline bool classof(const BinaryOperator *) { return true; }
142   static inline bool classof(const Instruction *I) {
143     return I->getOpcode() >= FirstBinaryOp && I->getOpcode() < NumBinaryOps; 
144   }
145   static inline bool classof(const Value *V) {
146     return isa<Instruction>(V) && classof(cast<Instruction>(V));
147   }
148 };
149
150 #endif