IntervalPartition & IntervalIterator classes have been split out into
[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
4 // Instruction class, which is itself defined in the Instruction.h file.  In 
5 // between these definitions and the Instruction class are classes that expose
6 // the SSA properties of each instruction, and that form the SSA graph.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #ifndef LLVM_ITERMINATORS_H
11 #define LLVM_ITERMINATORS_H
12
13 #include "llvm/InstrTypes.h"
14 #include "llvm/BasicBlock.h"
15 #include "llvm/ConstPoolVals.h"
16
17 //===----------------------------------------------------------------------===//
18 //         Classes to represent Basic Block "Terminator" instructions
19 //===----------------------------------------------------------------------===//
20
21
22 //===---------------------------------------------------------------------------
23 // ReturnInst - Return a value (possibly void), from a method.  Execution does
24 //              not continue in this method any longer.
25 //
26 class ReturnInst : public TerminatorInst {
27   Use Val;   // Will be null if returning void...
28   ReturnInst(const ReturnInst &RI);
29 public:
30   ReturnInst(Value *value = 0);
31   inline ~ReturnInst() { dropAllReferences(); }
32
33   virtual Instruction *clone() const { return new ReturnInst(*this); }
34
35   virtual string getOpcode() const { return "ret"; }
36
37   inline const Value *getReturnValue() const { return Val; }
38   inline       Value *getReturnValue()       { return Val; }
39
40   virtual void dropAllReferences();
41   virtual const Value *getOperand(unsigned i) const {
42     return (i == 0) ? Val : 0;
43   }
44   inline Value *getOperand(unsigned i) { return (i == 0) ? Val : 0;  }
45   virtual bool setOperand(unsigned i, Value *Val);
46   virtual unsigned getNumOperands() const { return Val != 0; }
47
48   // Additionally, they must provide a method to get at the successors of this
49   // terminator instruction.  If 'idx' is out of range, a null pointer shall be
50   // returned.
51   //
52   virtual const BasicBlock *getSuccessor(unsigned idx) const { return 0; }
53   virtual unsigned getNumSuccessors() const { return 0; }
54 };
55
56
57 //===---------------------------------------------------------------------------
58 // BranchInst - Conditional or Unconditional Branch instruction.
59 //
60 class BranchInst : public TerminatorInst {
61   BasicBlockUse TrueDest, FalseDest;
62   Use Condition;
63
64   BranchInst(const BranchInst &BI);
65 public:
66   // If cond = null, then is an unconditional br...
67   BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse = 0, Value *cond = 0);
68   inline ~BranchInst() { dropAllReferences(); }
69
70   virtual Instruction *clone() const { return new BranchInst(*this); }
71
72   virtual void dropAllReferences();
73   
74   inline bool isUnconditional() const {
75     return Condition == 0 || !FalseDest;
76   }
77
78   virtual string getOpcode() const { return "br"; }
79
80   inline Value *getOperand(unsigned i) {
81     return (Value*)((const BranchInst *)this)->getOperand(i);
82   }
83   virtual const Value *getOperand(unsigned i) const;
84   virtual bool setOperand(unsigned i, Value *Val);
85   virtual unsigned getNumOperands() const { return isUnconditional() ? 1 : 3; }
86
87   // Additionally, they must provide a method to get at the successors of this
88   // terminator instruction.  If 'idx' is out of range, a null pointer shall be
89   // returned.
90   //
91   virtual const BasicBlock *getSuccessor(unsigned idx) const;
92   virtual unsigned getNumSuccessors() const { return 1+!isUnconditional(); }
93 };
94
95
96 //===---------------------------------------------------------------------------
97 // SwitchInst - Multiway switch
98 //
99 class SwitchInst : public TerminatorInst {
100 public:
101   typedef pair<ConstPoolUse, BasicBlockUse> dest_value;
102 private:
103   BasicBlockUse DefaultDest;
104   Use Val;
105   vector<dest_value> Destinations;
106
107   SwitchInst(const SwitchInst &RI);
108 public:
109   typedef vector<dest_value>::iterator       dest_iterator;
110   typedef vector<dest_value>::const_iterator dest_const_iterator;
111
112   SwitchInst(Value *Value, BasicBlock *Default);
113   inline ~SwitchInst() { dropAllReferences(); }
114
115   virtual Instruction *clone() const { return new SwitchInst(*this); }
116
117   void dest_push_back(ConstPoolVal *OnVal, BasicBlock *Dest);
118
119   virtual string getOpcode() const { return "switch"; }
120   inline Value *getOperand(unsigned i) {
121     return (Value*)((const SwitchInst*)this)->getOperand(i);
122   }
123   virtual const Value *getOperand(unsigned i) const;
124   virtual bool setOperand(unsigned i, Value *Val);
125   virtual unsigned getNumOperands() const;
126   virtual void dropAllReferences();  
127
128   // Additionally, they must provide a method to get at the successors of this
129   // terminator instruction.  If 'idx' is out of range, a null pointer shall be
130   // returned.
131   //
132   virtual const BasicBlock *getSuccessor(unsigned idx) const;
133   virtual unsigned getNumSuccessors() const { return 1+Destinations.size(); }
134 };
135
136 #endif