Add convinience constructor for function calls with two args.
[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 *Actual1, Value *Actual2);
74   void init(Value *Func, Value *Actual);
75   void init(Value *Func);
76
77 public:
78   CallInst(Value *F, const std::vector<Value*> &Par,
79            const std::string &Name = "", Instruction *InsertBefore = 0);
80   CallInst(Value *F, const std::vector<Value*> &Par,
81            const std::string &Name, BasicBlock *InsertAtEnd);
82
83   // Alternate CallInst ctors w/ two actuals, w/ one actual and no
84   // actuals, respectively.
85   CallInst(Value *F, Value *Actual1, Value *Actual2,
86            const std::string& Name = "", Instruction *InsertBefore = 0);
87   CallInst(Value *F, Value *Actual1, Value *Actual2,
88            const std::string& Name, BasicBlock *InsertAtEnd);
89   CallInst(Value *F, Value *Actual, const std::string& Name = "",
90            Instruction *InsertBefore = 0);
91   CallInst(Value *F, Value *Actual, const std::string& Name,
92            BasicBlock *InsertAtEnd);
93   explicit CallInst(Value *F, const std::string &Name = "", 
94                     Instruction *InsertBefore = 0);
95   explicit CallInst(Value *F, const std::string &Name, 
96                     BasicBlock *InsertAtEnd);
97
98   virtual Instruction *clone() const { return new CallInst(*this); }
99   bool mayWriteToMemory() const { return true; }
100
101   // FIXME: These methods should be inline once we eliminate
102   // ConstantPointerRefs!
103   const Function *getCalledFunction() const;
104   Function *getCalledFunction();
105
106   // getCalledValue - Get a pointer to a method that is invoked by this inst.
107   inline const Value *getCalledValue() const { return Operands[0]; }
108   inline       Value *getCalledValue()       { return Operands[0]; }
109
110   // Methods for support type inquiry through isa, cast, and dyn_cast:
111   static inline bool classof(const CallInst *) { return true; }
112   static inline bool classof(const Instruction *I) {
113     return I->getOpcode() == Instruction::Call; 
114   }
115   static inline bool classof(const Value *V) {
116     return isa<Instruction>(V) && classof(cast<Instruction>(V));
117   }
118 };
119
120
121 //===----------------------------------------------------------------------===//
122 //                                 ShiftInst Class
123 //===----------------------------------------------------------------------===//
124
125 /// ShiftInst - This class represents left and right shift instructions.
126 ///
127 class ShiftInst : public Instruction {
128   ShiftInst(const ShiftInst &SI) : Instruction(SI.getType(), SI.getOpcode()) {
129     Operands.reserve(2);
130     Operands.push_back(Use(SI.Operands[0], this));
131     Operands.push_back(Use(SI.Operands[1], this));
132   }
133   void init(OtherOps Opcode, Value *S, Value *SA) {
134     assert((Opcode == Shl || Opcode == Shr) && "ShiftInst Opcode invalid!");
135     Operands.reserve(2);
136     Operands.push_back(Use(S, this));
137     Operands.push_back(Use(SA, this));
138   }
139
140 public:
141   ShiftInst(OtherOps Opcode, Value *S, Value *SA, const std::string &Name = "",
142             Instruction *InsertBefore = 0)
143     : Instruction(S->getType(), Opcode, Name, InsertBefore) {
144     init(Opcode, S, SA);
145   }
146   ShiftInst(OtherOps Opcode, Value *S, Value *SA, const std::string &Name,
147             BasicBlock *InsertAtEnd)
148     : Instruction(S->getType(), Opcode, Name, InsertAtEnd) {
149     init(Opcode, S, SA);
150   }
151
152   OtherOps getOpcode() const {
153     return static_cast<OtherOps>(Instruction::getOpcode());
154   }
155
156   virtual Instruction *clone() const { return new ShiftInst(*this); }
157
158   // Methods for support type inquiry through isa, cast, and dyn_cast:
159   static inline bool classof(const ShiftInst *) { return true; }
160   static inline bool classof(const Instruction *I) {
161     return (I->getOpcode() == Instruction::Shr) | 
162            (I->getOpcode() == Instruction::Shl);
163   }
164   static inline bool classof(const Value *V) {
165     return isa<Instruction>(V) && classof(cast<Instruction>(V));
166   }
167 };
168
169 //===----------------------------------------------------------------------===//
170 //                               SelectInst Class
171 //===----------------------------------------------------------------------===//
172
173 /// SelectInst - This class represents the LLVM 'select' instruction.
174 ///
175 class SelectInst : public Instruction {
176   SelectInst(const SelectInst &SI) : Instruction(SI.getType(), SI.getOpcode()) {
177     Operands.reserve(3);
178     Operands.push_back(Use(SI.Operands[0], this));
179     Operands.push_back(Use(SI.Operands[1], this));
180     Operands.push_back(Use(SI.Operands[2], this));
181   }
182   void init(Value *C, Value *S1, Value *S2) {
183     Operands.reserve(3);
184     Operands.push_back(Use(C, this));
185     Operands.push_back(Use(S1, this));
186     Operands.push_back(Use(S2, this));
187   }
188
189 public:
190   SelectInst(Value *C, Value *S1, Value *S2, const std::string &Name = "",
191              Instruction *InsertBefore = 0)
192     : Instruction(S1->getType(), Instruction::Select, Name, InsertBefore) {
193     init(C, S1, S2);
194   }
195   SelectInst(Value *C, Value *S1, Value *S2, const std::string &Name,
196              BasicBlock *InsertAtEnd)
197     : Instruction(S1->getType(), Instruction::Select, Name, InsertAtEnd) {
198     init(C, S1, S2);
199   }
200
201   Value *getCondition() const { return Operands[0]; }
202   Value *getTrueValue() const { return Operands[1]; }
203   Value *getFalseValue() const { return Operands[2]; }
204
205   OtherOps getOpcode() const {
206     return static_cast<OtherOps>(Instruction::getOpcode());
207   }
208
209   virtual Instruction *clone() const { return new SelectInst(*this); }
210
211   // Methods for support type inquiry through isa, cast, and dyn_cast:
212   static inline bool classof(const SelectInst *) { return true; }
213   static inline bool classof(const Instruction *I) {
214     return I->getOpcode() == Instruction::Select;
215   }
216   static inline bool classof(const Value *V) {
217     return isa<Instruction>(V) && classof(cast<Instruction>(V));
218   }
219 };
220
221
222 //===----------------------------------------------------------------------===//
223 //                                VANextInst Class
224 //===----------------------------------------------------------------------===//
225
226 /// VANextInst - This class represents the va_next llvm instruction, which
227 /// advances a vararg list passed an argument of the specified type, returning
228 /// the resultant list.
229 ///
230 class VANextInst : public Instruction {
231   PATypeHolder ArgTy;
232   void init(Value *List) {
233     Operands.reserve(1);
234     Operands.push_back(Use(List, this));
235   }
236   VANextInst(const VANextInst &VAN)
237     : Instruction(VAN.getType(), VANext), ArgTy(VAN.getArgType()) {
238     init(VAN.Operands[0]);
239   }
240
241 public:
242   VANextInst(Value *List, const Type *Ty, const std::string &Name = "",
243              Instruction *InsertBefore = 0)
244     : Instruction(List->getType(), VANext, Name, InsertBefore), ArgTy(Ty) {
245     init(List);
246   }
247   VANextInst(Value *List, const Type *Ty, const std::string &Name,
248              BasicBlock *InsertAtEnd)
249     : Instruction(List->getType(), VANext, Name, InsertAtEnd), ArgTy(Ty) {
250     init(List);
251   }
252
253   const Type *getArgType() const { return ArgTy; }
254
255   virtual Instruction *clone() const { return new VANextInst(*this); }
256
257   // Methods for support type inquiry through isa, cast, and dyn_cast:
258   static inline bool classof(const VANextInst *) { return true; }
259   static inline bool classof(const Instruction *I) {
260     return I->getOpcode() == VANext;
261   }
262   static inline bool classof(const Value *V) {
263     return isa<Instruction>(V) && classof(cast<Instruction>(V));
264   }
265 };
266
267
268 //===----------------------------------------------------------------------===//
269 //                                VAArgInst Class
270 //===----------------------------------------------------------------------===//
271
272 /// VAArgInst - This class represents the va_arg llvm instruction, which returns
273 /// an argument of the specified type given a va_list.
274 ///
275 class VAArgInst : public Instruction {
276   void init(Value* List) {
277     Operands.reserve(1);
278     Operands.push_back(Use(List, this));
279   }
280   VAArgInst(const VAArgInst &VAA)
281     : Instruction(VAA.getType(), VAArg) {
282     init(VAA.Operands[0]);
283   }
284 public:
285   VAArgInst(Value *List, const Type *Ty, const std::string &Name = "",
286              Instruction *InsertBefore = 0)
287     : Instruction(Ty, VAArg, Name, InsertBefore) {
288     init(List);
289   }
290   VAArgInst(Value *List, const Type *Ty, const std::string &Name,
291             BasicBlock *InsertAtEnd)
292     : Instruction(Ty, VAArg, Name, InsertAtEnd) {
293     init(List);
294   }
295
296   virtual Instruction *clone() const { return new VAArgInst(*this); }
297
298   // Methods for support type inquiry through isa, cast, and dyn_cast:
299   static inline bool classof(const VAArgInst *) { return true; }
300   static inline bool classof(const Instruction *I) {
301     return I->getOpcode() == VAArg;
302   }
303   static inline bool classof(const Value *V) {
304     return isa<Instruction>(V) && classof(cast<Instruction>(V));
305   }
306 };
307
308 } // End llvm namespace
309
310 #endif