Definition of the Bytecode Handler interface. Subclasses can override just
[oota-llvm.git] / include / llvm / iOther.h
1 //===-- llvm/iOther.h - "Other" instruction node definitions ----*- C++ -*-===//
2 // 
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
7 // 
8 //===----------------------------------------------------------------------===//
9 //
10 // This file contains the declarations for instructions that fall into the 
11 // grandiose 'other' catagory...
12 //
13 //===----------------------------------------------------------------------===//
14
15 #ifndef LLVM_IOTHER_H
16 #define LLVM_IOTHER_H
17
18 #include "llvm/InstrTypes.h"
19
20 namespace llvm {
21
22 //===----------------------------------------------------------------------===//
23 //                                 CastInst Class
24 //===----------------------------------------------------------------------===//
25
26 /// CastInst - This class represents a cast from Operand[0] to the type of
27 /// the instruction (i->getType()).
28 ///
29 class CastInst : public Instruction {
30   CastInst(const CastInst &CI) : Instruction(CI.getType(), Cast) {
31     Operands.reserve(1);
32     Operands.push_back(Use(CI.Operands[0], this));
33   }
34   void init(Value *S) {
35     Operands.reserve(1);
36     Operands.push_back(Use(S, this));
37   }
38 public:
39   CastInst(Value *S, const Type *Ty, const std::string &Name = "",
40            Instruction *InsertBefore = 0)
41     : Instruction(Ty, Cast, Name, InsertBefore) {
42     init(S);
43   }
44   CastInst(Value *S, const Type *Ty, const std::string &Name,
45            BasicBlock *InsertAtEnd)
46     : Instruction(Ty, Cast, Name, InsertAtEnd) {
47     init(S);
48   }
49
50   virtual Instruction *clone() const { return new CastInst(*this); }
51
52   // Methods for support type inquiry through isa, cast, and dyn_cast:
53   static inline bool classof(const CastInst *) { return true; }
54   static inline bool classof(const Instruction *I) {
55     return I->getOpcode() == Cast;
56   }
57   static inline bool classof(const Value *V) {
58     return isa<Instruction>(V) && classof(cast<Instruction>(V));
59   }
60 };
61
62
63 //===----------------------------------------------------------------------===//
64 //                                 CallInst Class
65 //===----------------------------------------------------------------------===//
66
67 /// CallInst - This class represents a function call, abstracting a target
68 /// machine's calling convention.
69 ///
70 class CallInst : public Instruction {
71   CallInst(const CallInst &CI);
72   void init(Value *Func, const std::vector<Value*> &Params);
73   void init(Value *Func, Value *Actual);
74   void init(Value *Func);
75
76 public:
77   CallInst(Value *F, const std::vector<Value*> &Par,
78            const std::string &Name = "", Instruction *InsertBefore = 0);
79   CallInst(Value *F, const std::vector<Value*> &Par,
80            const std::string &Name, BasicBlock *InsertAtEnd);
81
82   // Alternate CallInst ctors w/ one actual & no actuals, respectively.
83   CallInst(Value *F, Value *Actual, const std::string& Name = "",
84            Instruction *InsertBefore = 0);
85   CallInst(Value *F, Value *Actual, const std::string& Name,
86            BasicBlock *InsertAtEnd);
87   explicit CallInst(Value *F, const std::string &Name = "", 
88                     Instruction *InsertBefore = 0);
89   explicit CallInst(Value *F, const std::string &Name, 
90                     BasicBlock *InsertAtEnd);
91
92   virtual Instruction *clone() const { return new CallInst(*this); }
93   bool mayWriteToMemory() const { return true; }
94
95   // FIXME: These methods should be inline once we eliminate
96   // ConstantPointerRefs!
97   const Function *getCalledFunction() const;
98   Function *getCalledFunction();
99
100   // getCalledValue - Get a pointer to a method that is invoked by this inst.
101   inline const Value *getCalledValue() const { return Operands[0]; }
102   inline       Value *getCalledValue()       { return Operands[0]; }
103
104   // Methods for support type inquiry through isa, cast, and dyn_cast:
105   static inline bool classof(const CallInst *) { return true; }
106   static inline bool classof(const Instruction *I) {
107     return I->getOpcode() == Instruction::Call; 
108   }
109   static inline bool classof(const Value *V) {
110     return isa<Instruction>(V) && classof(cast<Instruction>(V));
111   }
112 };
113
114
115 //===----------------------------------------------------------------------===//
116 //                                 ShiftInst Class
117 //===----------------------------------------------------------------------===//
118
119 /// ShiftInst - This class represents left and right shift instructions.
120 ///
121 class ShiftInst : public Instruction {
122   ShiftInst(const ShiftInst &SI) : Instruction(SI.getType(), SI.getOpcode()) {
123     Operands.reserve(2);
124     Operands.push_back(Use(SI.Operands[0], this));
125     Operands.push_back(Use(SI.Operands[1], this));
126   }
127   void init(OtherOps Opcode, Value *S, Value *SA) {
128     assert((Opcode == Shl || Opcode == Shr) && "ShiftInst Opcode invalid!");
129     Operands.reserve(2);
130     Operands.push_back(Use(S, this));
131     Operands.push_back(Use(SA, this));
132   }
133
134 public:
135   ShiftInst(OtherOps Opcode, Value *S, Value *SA, const std::string &Name = "",
136             Instruction *InsertBefore = 0)
137     : Instruction(S->getType(), Opcode, Name, InsertBefore) {
138     init(Opcode, S, SA);
139   }
140   ShiftInst(OtherOps Opcode, Value *S, Value *SA, const std::string &Name,
141             BasicBlock *InsertAtEnd)
142     : Instruction(S->getType(), Opcode, Name, InsertAtEnd) {
143     init(Opcode, S, SA);
144   }
145
146   OtherOps getOpcode() const {
147     return static_cast<OtherOps>(Instruction::getOpcode());
148   }
149
150   virtual Instruction *clone() const { return new ShiftInst(*this); }
151
152   // Methods for support type inquiry through isa, cast, and dyn_cast:
153   static inline bool classof(const ShiftInst *) { return true; }
154   static inline bool classof(const Instruction *I) {
155     return (I->getOpcode() == Instruction::Shr) | 
156            (I->getOpcode() == Instruction::Shl);
157   }
158   static inline bool classof(const Value *V) {
159     return isa<Instruction>(V) && classof(cast<Instruction>(V));
160   }
161 };
162
163 //===----------------------------------------------------------------------===//
164 //                               SelectInst Class
165 //===----------------------------------------------------------------------===//
166
167 /// SelectInst - This class represents the LLVM 'select' instruction.
168 ///
169 class SelectInst : public Instruction {
170   SelectInst(const SelectInst &SI) : Instruction(SI.getType(), SI.getOpcode()) {
171     Operands.reserve(3);
172     Operands.push_back(Use(SI.Operands[0], this));
173     Operands.push_back(Use(SI.Operands[1], this));
174     Operands.push_back(Use(SI.Operands[2], this));
175   }
176   void init(Value *C, Value *S1, Value *S2) {
177     Operands.reserve(3);
178     Operands.push_back(Use(C, this));
179     Operands.push_back(Use(S1, this));
180     Operands.push_back(Use(S2, this));
181   }
182
183 public:
184   SelectInst(Value *C, Value *S1, Value *S2, const std::string &Name = "",
185              Instruction *InsertBefore = 0)
186     : Instruction(S1->getType(), Instruction::Select, Name, InsertBefore) {
187     init(C, S1, S2);
188   }
189   SelectInst(Value *C, Value *S1, Value *S2, const std::string &Name,
190              BasicBlock *InsertAtEnd)
191     : Instruction(S1->getType(), Instruction::Select, Name, InsertAtEnd) {
192     init(C, S1, S2);
193   }
194
195   Value *getCondition() const { return Operands[0]; }
196   Value *getTrueValue() const { return Operands[1]; }
197   Value *getFalseValue() const { return Operands[2]; }
198
199   OtherOps getOpcode() const {
200     return static_cast<OtherOps>(Instruction::getOpcode());
201   }
202
203   virtual Instruction *clone() const { return new SelectInst(*this); }
204
205   // Methods for support type inquiry through isa, cast, and dyn_cast:
206   static inline bool classof(const SelectInst *) { return true; }
207   static inline bool classof(const Instruction *I) {
208     return I->getOpcode() == Instruction::Select;
209   }
210   static inline bool classof(const Value *V) {
211     return isa<Instruction>(V) && classof(cast<Instruction>(V));
212   }
213 };
214
215
216 //===----------------------------------------------------------------------===//
217 //                                VANextInst Class
218 //===----------------------------------------------------------------------===//
219
220 /// VANextInst - This class represents the va_next llvm instruction, which
221 /// advances a vararg list passed an argument of the specified type, returning
222 /// the resultant list.
223 ///
224 class VANextInst : public Instruction {
225   PATypeHolder ArgTy;
226   void init(Value *List) {
227     Operands.reserve(1);
228     Operands.push_back(Use(List, this));
229   }
230   VANextInst(const VANextInst &VAN)
231     : Instruction(VAN.getType(), VANext), ArgTy(VAN.getArgType()) {
232     init(VAN.Operands[0]);
233   }
234
235 public:
236   VANextInst(Value *List, const Type *Ty, const std::string &Name = "",
237              Instruction *InsertBefore = 0)
238     : Instruction(List->getType(), VANext, Name, InsertBefore), ArgTy(Ty) {
239     init(List);
240   }
241   VANextInst(Value *List, const Type *Ty, const std::string &Name,
242              BasicBlock *InsertAtEnd)
243     : Instruction(List->getType(), VANext, Name, InsertAtEnd), ArgTy(Ty) {
244     init(List);
245   }
246
247   const Type *getArgType() const { return ArgTy; }
248
249   virtual Instruction *clone() const { return new VANextInst(*this); }
250
251   // Methods for support type inquiry through isa, cast, and dyn_cast:
252   static inline bool classof(const VANextInst *) { return true; }
253   static inline bool classof(const Instruction *I) {
254     return I->getOpcode() == VANext;
255   }
256   static inline bool classof(const Value *V) {
257     return isa<Instruction>(V) && classof(cast<Instruction>(V));
258   }
259 };
260
261
262 //===----------------------------------------------------------------------===//
263 //                                VAArgInst Class
264 //===----------------------------------------------------------------------===//
265
266 /// VAArgInst - This class represents the va_arg llvm instruction, which returns
267 /// an argument of the specified type given a va_list.
268 ///
269 class VAArgInst : public Instruction {
270   void init(Value* List) {
271     Operands.reserve(1);
272     Operands.push_back(Use(List, this));
273   }
274   VAArgInst(const VAArgInst &VAA)
275     : Instruction(VAA.getType(), VAArg) {
276     init(VAA.Operands[0]);
277   }
278 public:
279   VAArgInst(Value *List, const Type *Ty, const std::string &Name = "",
280              Instruction *InsertBefore = 0)
281     : Instruction(Ty, VAArg, Name, InsertBefore) {
282     init(List);
283   }
284   VAArgInst(Value *List, const Type *Ty, const std::string &Name,
285             BasicBlock *InsertAtEnd)
286     : Instruction(Ty, VAArg, Name, InsertAtEnd) {
287     init(List);
288   }
289
290   virtual Instruction *clone() const { return new VAArgInst(*this); }
291
292   // Methods for support type inquiry through isa, cast, and dyn_cast:
293   static inline bool classof(const VAArgInst *) { return true; }
294   static inline bool classof(const Instruction *I) {
295     return I->getOpcode() == VAArg;
296   }
297   static inline bool classof(const Value *V) {
298     return isa<Instruction>(V) && classof(cast<Instruction>(V));
299   }
300 };
301
302 } // End llvm namespace
303
304 #endif