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 *Actual);
74 void init(Value *Func);
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);
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);
92 virtual Instruction *clone() const { return new CallInst(*this); }
93 bool mayWriteToMemory() const { return true; }
95 // FIXME: These methods should be inline once we eliminate
96 // ConstantPointerRefs!
97 const Function *getCalledFunction() const;
98 Function *getCalledFunction();
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]; }
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;
109 static inline bool classof(const Value *V) {
110 return isa<Instruction>(V) && classof(cast<Instruction>(V));
115 //===----------------------------------------------------------------------===//
117 //===----------------------------------------------------------------------===//
119 /// ShiftInst - This class represents left and right shift instructions.
121 class ShiftInst : public Instruction {
122 ShiftInst(const ShiftInst &SI) : Instruction(SI.getType(), SI.getOpcode()) {
124 Operands.push_back(Use(SI.Operands[0], this));
125 Operands.push_back(Use(SI.Operands[1], this));
127 void init(OtherOps Opcode, Value *S, Value *SA) {
128 assert((Opcode == Shl || Opcode == Shr) && "ShiftInst Opcode invalid!");
130 Operands.push_back(Use(S, this));
131 Operands.push_back(Use(SA, this));
135 ShiftInst(OtherOps Opcode, Value *S, Value *SA, const std::string &Name = "",
136 Instruction *InsertBefore = 0)
137 : Instruction(S->getType(), Opcode, Name, InsertBefore) {
140 ShiftInst(OtherOps Opcode, Value *S, Value *SA, const std::string &Name,
141 BasicBlock *InsertAtEnd)
142 : Instruction(S->getType(), Opcode, Name, InsertAtEnd) {
146 OtherOps getOpcode() const {
147 return static_cast<OtherOps>(Instruction::getOpcode());
150 virtual Instruction *clone() const { return new ShiftInst(*this); }
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);
158 static inline bool classof(const Value *V) {
159 return isa<Instruction>(V) && classof(cast<Instruction>(V));
163 //===----------------------------------------------------------------------===//
165 //===----------------------------------------------------------------------===//
167 /// SelectInst - This class represents the LLVM 'select' instruction.
169 class SelectInst : public Instruction {
170 SelectInst(const SelectInst &SI) : Instruction(SI.getType(), SI.getOpcode()) {
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));
176 void init(Value *C, Value *S1, Value *S2) {
178 Operands.push_back(Use(C, this));
179 Operands.push_back(Use(S1, this));
180 Operands.push_back(Use(S2, this));
184 SelectInst(Value *C, Value *S1, Value *S2, const std::string &Name = "",
185 Instruction *InsertBefore = 0)
186 : Instruction(S1->getType(), Instruction::Select, Name, InsertBefore) {
189 SelectInst(Value *C, Value *S1, Value *S2, const std::string &Name,
190 BasicBlock *InsertAtEnd)
191 : Instruction(S1->getType(), Instruction::Select, Name, InsertAtEnd) {
195 Value *getCondition() const { return Operands[0]; }
196 Value *getTrueValue() const { return Operands[1]; }
197 Value *getFalseValue() const { return Operands[2]; }
199 OtherOps getOpcode() const {
200 return static_cast<OtherOps>(Instruction::getOpcode());
203 virtual Instruction *clone() const { return new SelectInst(*this); }
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;
210 static inline bool classof(const Value *V) {
211 return isa<Instruction>(V) && classof(cast<Instruction>(V));
216 //===----------------------------------------------------------------------===//
218 //===----------------------------------------------------------------------===//
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.
224 class VANextInst : public Instruction {
226 void init(Value *List) {
228 Operands.push_back(Use(List, this));
230 VANextInst(const VANextInst &VAN)
231 : Instruction(VAN.getType(), VANext), ArgTy(VAN.getArgType()) {
232 init(VAN.Operands[0]);
236 VANextInst(Value *List, const Type *Ty, const std::string &Name = "",
237 Instruction *InsertBefore = 0)
238 : Instruction(List->getType(), VANext, Name, InsertBefore), ArgTy(Ty) {
241 VANextInst(Value *List, const Type *Ty, const std::string &Name,
242 BasicBlock *InsertAtEnd)
243 : Instruction(List->getType(), VANext, Name, InsertAtEnd), ArgTy(Ty) {
247 const Type *getArgType() const { return ArgTy; }
249 virtual Instruction *clone() const { return new VANextInst(*this); }
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;
256 static inline bool classof(const Value *V) {
257 return isa<Instruction>(V) && classof(cast<Instruction>(V));
262 //===----------------------------------------------------------------------===//
264 //===----------------------------------------------------------------------===//
266 /// VAArgInst - This class represents the va_arg llvm instruction, which returns
267 /// an argument of the specified type given a va_list.
269 class VAArgInst : public Instruction {
270 void init(Value* List) {
272 Operands.push_back(Use(List, this));
274 VAArgInst(const VAArgInst &VAA)
275 : Instruction(VAA.getType(), VAArg) {
276 init(VAA.Operands[0]);
279 VAArgInst(Value *List, const Type *Ty, const std::string &Name = "",
280 Instruction *InsertBefore = 0)
281 : Instruction(Ty, VAArg, Name, InsertBefore) {
284 VAArgInst(Value *List, const Type *Ty, const std::string &Name,
285 BasicBlock *InsertAtEnd)
286 : Instruction(Ty, VAArg, Name, InsertAtEnd) {
290 virtual Instruction *clone() const { return new VAArgInst(*this); }
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;
297 static inline bool classof(const Value *V) {
298 return isa<Instruction>(V) && classof(cast<Instruction>(V));
302 } // End llvm namespace