Commit more code over to new cast style
[oota-llvm.git] / include / llvm / iOther.h
1 //===-- llvm/iOther.h - "Other" instruction node definitions -----*- C++ -*--=//
2 //
3 // This file contains the declarations for instructions that fall into the 
4 // grandios 'other' catagory...
5 //
6 //===----------------------------------------------------------------------===//
7
8 #ifndef LLVM_IOTHER_H
9 #define LLVM_IOTHER_H
10
11 #include "llvm/InstrTypes.h"
12 #include "llvm/Method.h"
13
14 //===----------------------------------------------------------------------===//
15 //                               PHINode Class
16 //===----------------------------------------------------------------------===//
17
18 // PHINode - The PHINode class is used to represent the magical mystical PHI
19 // node, that can not exist in nature, but can be synthesized in a computer
20 // scientist's overactive imagination.
21 //
22 class PHINode : public Instruction {
23   PHINode(const PHINode &PN);
24 public:
25   PHINode(const Type *Ty, const string &Name = "");
26
27   virtual Instruction *clone() const { return new PHINode(*this); }
28   virtual const char *getOpcodeName() const { return "phi"; }
29
30   // getNumIncomingValues - Return the number of incoming edges the PHI node has
31   inline unsigned getNumIncomingValues() const { return Operands.size()/2; }
32
33   // getIncomingValue - Return incoming value #x
34   inline const Value *getIncomingValue(unsigned i) const {
35     return Operands[i*2];
36   }
37   inline Value *getIncomingValue(unsigned i) {
38     return Operands[i*2];
39   }
40   inline void setIncomingValue(unsigned i, Value *V) {
41     Operands[i*2] = V;
42   }
43
44   // getIncomingBlock - Return incoming basic block #x
45   inline const BasicBlock *getIncomingBlock(unsigned i) const { 
46     return cast<const BasicBlock>(Operands[i*2+1]);
47   }
48   inline BasicBlock *getIncomingBlock(unsigned i) { 
49     return cast<BasicBlock>(Operands[i*2+1]);
50   }
51
52   // addIncoming - Add an incoming value to the end of the PHI list
53   void addIncoming(Value *D, BasicBlock *BB);
54
55   // removeIncomingValue - Remove an incoming value.  This is useful if a
56   // predecessor basic block is deleted.  The value removed is returned.
57   Value *removeIncomingValue(const BasicBlock *BB);
58
59
60   // Methods for support type inquiry through isa, cast, and dyn_cast:
61   static inline bool classof(const PHINode *) { return true; }
62   static inline bool classof(const Instruction *I) {
63     return I->getOpcode() == Instruction::PHINode; 
64   }
65   static inline bool classof(const Value *V) {
66     return isa<Instruction>(V) && classof(cast<Instruction>(V));
67   }
68 };
69
70
71 //===----------------------------------------------------------------------===//
72 //                                 CastInst Class
73 //===----------------------------------------------------------------------===//
74
75 // CastInst - This class represents a cast from Operand[0] to the type of
76 // the instruction (i->getType()).
77 //
78 class CastInst : public Instruction {
79   CastInst(const CastInst &CI) : Instruction(CI.getType(), Cast) {
80     Operands.reserve(1);
81     Operands.push_back(Use(CI.Operands[0], this));
82   }
83 public:
84   CastInst(Value *S, const Type *Ty, const string &Name = "")
85     : Instruction(Ty, Cast, Name) {
86     Operands.reserve(1);
87     Operands.push_back(Use(S, this));
88   }
89
90   virtual Instruction *clone() const { return new CastInst(*this); }
91   virtual const char *getOpcodeName() const { return "cast"; }
92
93   // Methods for support type inquiry through isa, cast, and dyn_cast:
94   static inline bool classof(const CastInst *) { return true; }
95   static inline bool classof(const Instruction *I) {
96     return I->getOpcode() == Cast;
97   }
98   static inline bool classof(const Value *V) {
99     return isa<Instruction>(V) && classof(cast<Instruction>(V));
100   }
101 };
102
103
104 //===----------------------------------------------------------------------===//
105 //                           MethodArgument Class
106 //===----------------------------------------------------------------------===//
107
108 class MethodArgument : public Value {  // Defined in the InstrType.cpp file
109   Method *Parent;
110
111   friend class ValueHolder<MethodArgument,Method,Method>;
112   inline void setParent(Method *parent) { Parent = parent; }
113
114 public:
115   MethodArgument(const Type *Ty, const string &Name = "") 
116     : Value(Ty, Value::MethodArgumentVal, Name) {
117     Parent = 0;
118   }
119
120   // Specialize setName to handle symbol table majik...
121   virtual void setName(const string &name, SymbolTable *ST = 0);
122
123   inline const Method *getParent() const { return Parent; }
124   inline       Method *getParent()       { return Parent; }
125
126   // Methods for support type inquiry through isa, cast, and dyn_cast:
127   static inline bool classof(const MethodArgument *) { return true; }
128   static inline bool classof(const Value *V) {
129     return V->getValueType() == MethodArgumentVal;
130   }
131 };
132
133
134 //===----------------------------------------------------------------------===//
135 //             Classes to function calls and method invocations
136 //===----------------------------------------------------------------------===//
137
138 class CallInst : public Instruction {
139   CallInst(const CallInst &CI);
140 public:
141   CallInst(Method *M, const vector<Value*> &params, const string &Name = "");
142
143   virtual const char *getOpcodeName() const { return "call"; }
144
145   virtual Instruction *clone() const { return new CallInst(*this); }
146   bool hasSideEffects() const { return true; }
147
148
149   const Method *getCalledMethod() const {
150     return cast<Method>(Operands[0]);
151   }
152   Method *getCalledMethod() {
153     return  cast<Method>(Operands[0]); 
154   }
155
156   // Methods for support type inquiry through isa, cast, and dyn_cast:
157   static inline bool classof(const CallInst *) { return true; }
158   static inline bool classof(const Instruction *I) {
159     return I->getOpcode() == Instruction::Call; 
160   }
161   static inline bool classof(const Value *V) {
162     return isa<Instruction>(V) && classof(cast<Instruction>(V));
163   }
164 };
165
166
167 //===----------------------------------------------------------------------===//
168 //                                 ShiftInst Class
169 //===----------------------------------------------------------------------===//
170
171 // ShiftInst - This class represents left and right shift instructions.
172 //
173 class ShiftInst : public Instruction {
174   ShiftInst(const ShiftInst &SI) : Instruction(SI.getType(), SI.getOpcode()) {
175     Operands.reserve(2);
176     Operands.push_back(Use(SI.Operands[0], this));
177     Operands.push_back(Use(SI.Operands[1], this));
178   }
179 public:
180   ShiftInst(OtherOps Opcode, Value *S, Value *SA, const string &Name = "")
181     : Instruction(S->getType(), Opcode, Name) {
182     assert((Opcode == Shl || Opcode == Shr) && "ShiftInst Opcode invalid!");
183     Operands.reserve(2);
184     Operands.push_back(Use(S, this));
185     Operands.push_back(Use(SA, this));
186   }
187
188   virtual Instruction *clone() const { return new ShiftInst(*this); }
189   virtual const char *getOpcodeName() const {
190     return getOpcode() == Shl ? "shl" : "shr"; 
191   }
192
193   // Methods for support type inquiry through isa, cast, and dyn_cast:
194   static inline bool classof(const ShiftInst *) { return true; }
195   static inline bool classof(const Instruction *I) {
196     return (I->getOpcode() == Instruction::Shr) | 
197            (I->getOpcode() == Instruction::Shl);
198   }
199   static inline bool classof(const Value *V) {
200     return isa<Instruction>(V) && classof(cast<Instruction>(V));
201   }
202 };
203
204 #endif