1 //===-- llvm/iOther.h - "Other" instruction node definitions ----*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
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.
8 //===----------------------------------------------------------------------===//
10 // This file contains the declarations for instructions that fall into the
11 // grandiose 'other' catagory...
13 //===----------------------------------------------------------------------===//
18 #include "llvm/InstrTypes.h"
22 //===----------------------------------------------------------------------===//
24 //===----------------------------------------------------------------------===//
26 /// CastInst - This class represents a cast from Operand[0] to the type of
27 /// the instruction (i->getType()).
29 class CastInst : public Instruction {
30 CastInst(const CastInst &CI) : Instruction(CI.getType(), Cast) {
32 Operands.push_back(Use(CI.Operands[0], this));
36 Operands.push_back(Use(S, this));
39 CastInst(Value *S, const Type *Ty, const std::string &Name = "",
40 Instruction *InsertBefore = 0)
41 : Instruction(Ty, Cast, Name, InsertBefore) {
44 CastInst(Value *S, const Type *Ty, const std::string &Name,
45 BasicBlock *InsertAtEnd)
46 : Instruction(Ty, Cast, Name, InsertAtEnd) {
50 virtual Instruction *clone() const { return new CastInst(*this); }
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;
57 static inline bool classof(const Value *V) {
58 return isa<Instruction>(V) && classof(cast<Instruction>(V));
63 //===----------------------------------------------------------------------===//
65 //===----------------------------------------------------------------------===//
67 /// CallInst - This class represents a function call, abstracting a target
68 /// machine's calling convention.
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);
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);
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);
98 virtual Instruction *clone() const { return new CallInst(*this); }
99 bool mayWriteToMemory() const { return true; }
101 // FIXME: These methods should be inline once we eliminate
102 // ConstantPointerRefs!
103 const Function *getCalledFunction() const;
104 Function *getCalledFunction();
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]; }
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;
115 static inline bool classof(const Value *V) {
116 return isa<Instruction>(V) && classof(cast<Instruction>(V));
121 //===----------------------------------------------------------------------===//
123 //===----------------------------------------------------------------------===//
125 /// ShiftInst - This class represents left and right shift instructions.
127 class ShiftInst : public Instruction {
128 ShiftInst(const ShiftInst &SI) : Instruction(SI.getType(), SI.getOpcode()) {
130 Operands.push_back(Use(SI.Operands[0], this));
131 Operands.push_back(Use(SI.Operands[1], this));
133 void init(OtherOps Opcode, Value *S, Value *SA) {
134 assert((Opcode == Shl || Opcode == Shr) && "ShiftInst Opcode invalid!");
136 Operands.push_back(Use(S, this));
137 Operands.push_back(Use(SA, this));
141 ShiftInst(OtherOps Opcode, Value *S, Value *SA, const std::string &Name = "",
142 Instruction *InsertBefore = 0)
143 : Instruction(S->getType(), Opcode, Name, InsertBefore) {
146 ShiftInst(OtherOps Opcode, Value *S, Value *SA, const std::string &Name,
147 BasicBlock *InsertAtEnd)
148 : Instruction(S->getType(), Opcode, Name, InsertAtEnd) {
152 OtherOps getOpcode() const {
153 return static_cast<OtherOps>(Instruction::getOpcode());
156 virtual Instruction *clone() const { return new ShiftInst(*this); }
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);
164 static inline bool classof(const Value *V) {
165 return isa<Instruction>(V) && classof(cast<Instruction>(V));
169 //===----------------------------------------------------------------------===//
171 //===----------------------------------------------------------------------===//
173 /// SelectInst - This class represents the LLVM 'select' instruction.
175 class SelectInst : public Instruction {
176 SelectInst(const SelectInst &SI) : Instruction(SI.getType(), SI.getOpcode()) {
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));
182 void init(Value *C, Value *S1, Value *S2) {
184 Operands.push_back(Use(C, this));
185 Operands.push_back(Use(S1, this));
186 Operands.push_back(Use(S2, this));
190 SelectInst(Value *C, Value *S1, Value *S2, const std::string &Name = "",
191 Instruction *InsertBefore = 0)
192 : Instruction(S1->getType(), Instruction::Select, Name, InsertBefore) {
195 SelectInst(Value *C, Value *S1, Value *S2, const std::string &Name,
196 BasicBlock *InsertAtEnd)
197 : Instruction(S1->getType(), Instruction::Select, Name, InsertAtEnd) {
201 Value *getCondition() const { return Operands[0]; }
202 Value *getTrueValue() const { return Operands[1]; }
203 Value *getFalseValue() const { return Operands[2]; }
205 OtherOps getOpcode() const {
206 return static_cast<OtherOps>(Instruction::getOpcode());
209 virtual Instruction *clone() const { return new SelectInst(*this); }
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;
216 static inline bool classof(const Value *V) {
217 return isa<Instruction>(V) && classof(cast<Instruction>(V));
222 //===----------------------------------------------------------------------===//
224 //===----------------------------------------------------------------------===//
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.
230 class VANextInst : public Instruction {
232 void init(Value *List) {
234 Operands.push_back(Use(List, this));
236 VANextInst(const VANextInst &VAN)
237 : Instruction(VAN.getType(), VANext), ArgTy(VAN.getArgType()) {
238 init(VAN.Operands[0]);
242 VANextInst(Value *List, const Type *Ty, const std::string &Name = "",
243 Instruction *InsertBefore = 0)
244 : Instruction(List->getType(), VANext, Name, InsertBefore), ArgTy(Ty) {
247 VANextInst(Value *List, const Type *Ty, const std::string &Name,
248 BasicBlock *InsertAtEnd)
249 : Instruction(List->getType(), VANext, Name, InsertAtEnd), ArgTy(Ty) {
253 const Type *getArgType() const { return ArgTy; }
255 virtual Instruction *clone() const { return new VANextInst(*this); }
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;
262 static inline bool classof(const Value *V) {
263 return isa<Instruction>(V) && classof(cast<Instruction>(V));
268 //===----------------------------------------------------------------------===//
270 //===----------------------------------------------------------------------===//
272 /// VAArgInst - This class represents the va_arg llvm instruction, which returns
273 /// an argument of the specified type given a va_list.
275 class VAArgInst : public Instruction {
276 void init(Value* List) {
278 Operands.push_back(Use(List, this));
280 VAArgInst(const VAArgInst &VAA)
281 : Instruction(VAA.getType(), VAArg) {
282 init(VAA.Operands[0]);
285 VAArgInst(Value *List, const Type *Ty, const std::string &Name = "",
286 Instruction *InsertBefore = 0)
287 : Instruction(Ty, VAArg, Name, InsertBefore) {
290 VAArgInst(Value *List, const Type *Ty, const std::string &Name,
291 BasicBlock *InsertAtEnd)
292 : Instruction(Ty, VAArg, Name, InsertAtEnd) {
296 virtual Instruction *clone() const { return new VAArgInst(*this); }
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;
303 static inline bool classof(const Value *V) {
304 return isa<Instruction>(V) && classof(cast<Instruction>(V));
308 } // End llvm namespace