Add dummy entries to document what members can be added
[oota-llvm.git] / include / llvm / iTerminators.h
1 //===-- llvm/iTerminators.h - Termintator instruction nodes -----*- C++ -*-===//
2 //
3 // This file contains the declarations for all the subclasses of the Instruction
4 // class which represent "terminator" instructions.  Terminator instructions are
5 // the only instructions allowed and required to terminate a BasicBlock.
6 //
7 //===----------------------------------------------------------------------===//
8
9 #ifndef LLVM_ITERMINATORS_H
10 #define LLVM_ITERMINATORS_H
11
12 #include "llvm/InstrTypes.h"
13
14 //===---------------------------------------------------------------------------
15 // ReturnInst - Return a value (possibly void), from a method.  Execution does
16 //              not continue in this method any longer.
17 //
18 class ReturnInst : public TerminatorInst {
19   ReturnInst(const ReturnInst &RI) : TerminatorInst(Instruction::Ret) {
20     if (RI.Operands.size()) {
21       assert(RI.Operands.size() == 1 && "Return insn can only have 1 operand!");
22       Operands.reserve(1);
23       Operands.push_back(Use(RI.Operands[0], this));
24     }
25   }
26 public:
27   ReturnInst(Value *RetVal = 0, Instruction *InsertBefore = 0)
28     : TerminatorInst(Instruction::Ret, InsertBefore) {
29     if (RetVal) {
30       Operands.reserve(1);
31       Operands.push_back(Use(RetVal, this));
32     }
33   }
34
35   virtual Instruction *clone() const { return new ReturnInst(*this); }
36
37   inline const Value *getReturnValue() const {
38     return Operands.size() ? Operands[0].get() : 0; 
39   }
40   inline       Value *getReturnValue()       {
41     return Operands.size() ? Operands[0].get() : 0;
42   }
43
44   virtual const BasicBlock *getSuccessor(unsigned idx) const {
45     assert(0 && "ReturnInst has no successors!");
46     abort();
47     return 0;
48   }
49   virtual void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
50     assert(0 && "ReturnInst has no successors!");
51   }
52   virtual unsigned getNumSuccessors() const { return 0; }
53
54   // Methods for support type inquiry through isa, cast, and dyn_cast:
55   static inline bool classof(const ReturnInst *) { return true; }
56   static inline bool classof(const Instruction *I) {
57     return (I->getOpcode() == Instruction::Ret);
58   }
59   static inline bool classof(const Value *V) {
60     return isa<Instruction>(V) && classof(cast<Instruction>(V));
61   }
62 };
63
64
65 //===---------------------------------------------------------------------------
66 // BranchInst - Conditional or Unconditional Branch instruction.
67 //
68 class BranchInst : public TerminatorInst {
69   BranchInst(const BranchInst &BI);
70 public:
71   // If cond = null, then is an unconditional br...
72   BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *cond = 0,
73              Instruction *InsertBefore = 0);
74   BranchInst(BasicBlock *IfTrue, Instruction *InsertBefore = 0);
75
76   virtual Instruction *clone() const { return new BranchInst(*this); }
77
78   inline bool isUnconditional() const { return Operands.size() == 1; }
79   inline bool isConditional()   const { return Operands.size() == 3; }
80
81   inline const Value *getCondition() const {
82     return isUnconditional() ? 0 : Operands[2].get();
83   }
84   Value *getCondition() {
85     return isUnconditional() ? 0 : Operands[2].get();
86   }
87
88   // setUnconditionalDest - Change the current branch to an unconditional branch
89   // targeting the specified block.
90   //
91   void setUnconditionalDest(BasicBlock *Dest) {
92     if (isConditional()) Operands.erase(Operands.begin()+1, Operands.end());
93     Operands[0] = (Value*)Dest;
94   }
95
96   virtual const BasicBlock *getSuccessor(unsigned i) const {
97     assert(i < getNumSuccessors() && "Successor # out of range for Branch!");
98     return (i == 0) ? cast<BasicBlock>(Operands[0].get()) : 
99                       cast<BasicBlock>(Operands[1].get());
100   }
101   inline BasicBlock *getSuccessor(unsigned idx) {
102     return (BasicBlock*)((const BranchInst *)this)->getSuccessor(idx);
103   }
104
105   virtual void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
106     assert(idx < getNumSuccessors() && "Successor # out of range for Branch!");
107     Operands[idx] = (Value*)NewSucc;
108   }
109
110   virtual unsigned getNumSuccessors() const { return 1+isConditional(); }
111
112   // Methods for support type inquiry through isa, cast, and dyn_cast:
113   static inline bool classof(const BranchInst *) { return true; }
114   static inline bool classof(const Instruction *I) {
115     return (I->getOpcode() == Instruction::Br);
116   }
117   static inline bool classof(const Value *V) {
118     return isa<Instruction>(V) && classof(cast<Instruction>(V));
119   }
120 };
121
122
123 //===---------------------------------------------------------------------------
124 // SwitchInst - Multiway switch
125 //
126 class SwitchInst : public TerminatorInst {
127   // Operand[0]    = Value to switch on
128   // Operand[1]    = Default basic block destination
129   // Operand[2n  ] = Value to match
130   // Operand[2n+1] = BasicBlock to go to on match
131   SwitchInst(const SwitchInst &RI);
132 public:
133   SwitchInst(Value *Value, BasicBlock *Default, Instruction *InsertBefore = 0);
134
135   virtual Instruction *clone() const { return new SwitchInst(*this); }
136
137   // Accessor Methods for Switch stmt
138   //
139   inline const Value *getCondition() const { return Operands[0]; }
140   inline       Value *getCondition()       { return Operands[0]; }
141   inline const BasicBlock *getDefaultDest() const {
142     return cast<BasicBlock>(Operands[1].get());
143   }
144   inline       BasicBlock *getDefaultDest()       {
145     return cast<BasicBlock>(Operands[1].get());
146   }
147
148   void dest_push_back(Constant *OnVal, BasicBlock *Dest);
149
150   virtual const BasicBlock *getSuccessor(unsigned idx) const {
151     assert(idx < getNumSuccessors() &&"Successor idx out of range for switch!");
152     return cast<BasicBlock>(Operands[idx*2+1].get());
153   }
154   inline BasicBlock *getSuccessor(unsigned idx) {
155     assert(idx < getNumSuccessors() &&"Successor idx out of range for switch!");
156     return cast<BasicBlock>(Operands[idx*2+1].get());
157   }
158
159   virtual void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
160     assert(idx < getNumSuccessors() && "Successor # out of range for switch!");
161     Operands[idx*2+1] = (Value*)NewSucc;
162   }
163
164   // getSuccessorValue - Return the value associated with the specified
165   // successor.
166   inline const Constant *getSuccessorValue(unsigned idx) const {
167     assert(idx < getNumSuccessors() && "Successor # out of range!");
168     return cast<Constant>(Operands[idx*2].get());
169   }
170   inline Constant *getSuccessorValue(unsigned idx) {
171     assert(idx < getNumSuccessors() && "Successor # out of range!");
172     return cast<Constant>(Operands[idx*2].get());
173   }
174   virtual unsigned getNumSuccessors() const { return Operands.size()/2; }
175
176   // Methods for support type inquiry through isa, cast, and dyn_cast:
177   static inline bool classof(const SwitchInst *) { return true; }
178   static inline bool classof(const Instruction *I) {
179     return (I->getOpcode() == Instruction::Switch);
180   }
181   static inline bool classof(const Value *V) {
182     return isa<Instruction>(V) && classof(cast<Instruction>(V));
183   }
184 };
185
186
187 //===---------------------------------------------------------------------------
188 // InvokeInst - Invoke instruction
189 //
190 class InvokeInst : public TerminatorInst {
191   InvokeInst(const InvokeInst &BI);
192 public:
193   InvokeInst(Value *Meth, BasicBlock *IfNormal, BasicBlock *IfException,
194              const std::vector<Value*> &Params, const std::string &Name = "",
195              Instruction *InsertBefore = 0);
196
197   virtual Instruction *clone() const { return new InvokeInst(*this); }
198
199   bool hasSideEffects() const { return true; }
200
201   // getCalledFunction - Return the function called, or null if this is an
202   // indirect function invocation...
203   //
204   inline const Function *getCalledFunction() const {
205     return dyn_cast<Function>(Operands[0].get());
206   }
207   inline Function *getCalledFunction() {
208     return dyn_cast<Function>(Operands[0].get());
209   }
210
211   // getCalledValue - Get a pointer to a method that is invoked by this inst.
212   inline const Value *getCalledValue() const { return Operands[0]; }
213   inline       Value *getCalledValue()       { return Operands[0]; }
214
215   // get*Dest - Return the destination basic blocks...
216   inline const BasicBlock *getNormalDest() const {
217     return cast<BasicBlock>(Operands[1].get());
218   }
219   inline       BasicBlock *getNormalDest() {
220     return cast<BasicBlock>(Operands[1].get());
221   }
222   inline const BasicBlock *getExceptionalDest() const {
223     return cast<BasicBlock>(Operands[2].get());
224   }
225   inline       BasicBlock *getExceptionalDest() {
226     return cast<BasicBlock>(Operands[2].get());
227   }
228
229   inline void setNormalDest(BasicBlock *B){
230     Operands[1] = (Value*)B;
231   }
232
233   inline void setExceptionalDest(BasicBlock *B){
234     Operands[2] = (Value*)B;
235   }
236
237   virtual const BasicBlock *getSuccessor(unsigned i) const {
238     assert(i < 2 && "Successor # out of range for invoke!");
239     return i == 0 ? getNormalDest() : getExceptionalDest();
240   }
241   inline BasicBlock *getSuccessor(unsigned i) {
242     assert(i < 2 && "Successor # out of range for invoke!");
243     return i == 0 ? getNormalDest() : getExceptionalDest();
244   }
245
246   virtual void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
247     assert(idx < 2 && "Successor # out of range for invoke!");
248     Operands[idx+1] = (Value*)NewSucc;
249   }
250
251   virtual unsigned getNumSuccessors() const { return 2; }
252
253   // Methods for support type inquiry through isa, cast, and dyn_cast:
254   static inline bool classof(const InvokeInst *) { return true; }
255   static inline bool classof(const Instruction *I) {
256     return (I->getOpcode() == Instruction::Invoke);
257   }
258   static inline bool classof(const Value *V) {
259     return isa<Instruction>(V) && classof(cast<Instruction>(V));
260   }
261 };
262
263 #endif