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));
35 CastInst(Value *S, const Type *Ty, const std::string &Name = "",
36 Instruction *InsertBefore = 0)
37 : Instruction(Ty, Cast, Name, InsertBefore) {
39 Operands.push_back(Use(S, this));
42 virtual Instruction *clone() const { return new CastInst(*this); }
44 // Methods for support type inquiry through isa, cast, and dyn_cast:
45 static inline bool classof(const CastInst *) { return true; }
46 static inline bool classof(const Instruction *I) {
47 return I->getOpcode() == Cast;
49 static inline bool classof(const Value *V) {
50 return isa<Instruction>(V) && classof(cast<Instruction>(V));
55 //===----------------------------------------------------------------------===//
57 //===----------------------------------------------------------------------===//
59 /// CallInst - This class represents a function call, abstracting a target
60 /// machine's calling convention.
62 class CallInst : public Instruction {
63 CallInst(const CallInst &CI);
65 CallInst(Value *F, const std::vector<Value*> &Par,
66 const std::string &Name = "", Instruction *InsertBefore = 0);
68 // Alternate CallInst ctors w/ no actuals & one actual, respectively.
69 CallInst(Value *F, const std::string &Name = "",
70 Instruction *InsertBefore = 0);
71 CallInst(Value *F, Value *Actual, const std::string& Name = "",
72 Instruction *InsertBefore = 0);
74 virtual Instruction *clone() const { return new CallInst(*this); }
75 bool mayWriteToMemory() const { return true; }
77 // FIXME: These methods should be inline once we eliminate
78 // ConstantPointerRefs!
79 const Function *getCalledFunction() const;
80 Function *getCalledFunction();
82 // getCalledValue - Get a pointer to a method that is invoked by this inst.
83 inline const Value *getCalledValue() const { return Operands[0]; }
84 inline Value *getCalledValue() { return Operands[0]; }
86 // Methods for support type inquiry through isa, cast, and dyn_cast:
87 static inline bool classof(const CallInst *) { return true; }
88 static inline bool classof(const Instruction *I) {
89 return I->getOpcode() == Instruction::Call;
91 static inline bool classof(const Value *V) {
92 return isa<Instruction>(V) && classof(cast<Instruction>(V));
97 //===----------------------------------------------------------------------===//
99 //===----------------------------------------------------------------------===//
101 /// ShiftInst - This class represents left and right shift instructions.
103 class ShiftInst : public Instruction {
104 ShiftInst(const ShiftInst &SI) : Instruction(SI.getType(), SI.getOpcode()) {
106 Operands.push_back(Use(SI.Operands[0], this));
107 Operands.push_back(Use(SI.Operands[1], this));
110 ShiftInst(OtherOps Opcode, Value *S, Value *SA, const std::string &Name = "",
111 Instruction *InsertBefore = 0)
112 : Instruction(S->getType(), Opcode, Name, InsertBefore) {
113 assert((Opcode == Shl || Opcode == Shr) && "ShiftInst Opcode invalid!");
115 Operands.push_back(Use(S, this));
116 Operands.push_back(Use(SA, this));
119 OtherOps getOpcode() const {
120 return static_cast<OtherOps>(Instruction::getOpcode());
123 virtual Instruction *clone() const { return new ShiftInst(*this); }
125 // Methods for support type inquiry through isa, cast, and dyn_cast:
126 static inline bool classof(const ShiftInst *) { return true; }
127 static inline bool classof(const Instruction *I) {
128 return (I->getOpcode() == Instruction::Shr) |
129 (I->getOpcode() == Instruction::Shl);
131 static inline bool classof(const Value *V) {
132 return isa<Instruction>(V) && classof(cast<Instruction>(V));
136 //===----------------------------------------------------------------------===//
138 //===----------------------------------------------------------------------===//
140 /// SelectInst - This class represents the LLVM 'select' instruction.
142 class SelectInst : public Instruction {
143 SelectInst(const SelectInst &SI) : Instruction(SI.getType(), SI.getOpcode()) {
145 Operands.push_back(Use(SI.Operands[0], this));
146 Operands.push_back(Use(SI.Operands[1], this));
147 Operands.push_back(Use(SI.Operands[2], this));
150 SelectInst(Value *C, Value *S1, Value *S2, const std::string &Name = "",
151 Instruction *InsertBefore = 0)
152 : Instruction(S1->getType(), Instruction::Select, Name, InsertBefore) {
154 Operands.push_back(Use(C, this));
155 Operands.push_back(Use(S1, this));
156 Operands.push_back(Use(S2, this));
159 Value *getCondition() const { return Operands[0]; }
160 Value *getTrueValue() const { return Operands[1]; }
161 Value *getFalseValue() const { return Operands[2]; }
163 OtherOps getOpcode() const {
164 return static_cast<OtherOps>(Instruction::getOpcode());
167 virtual Instruction *clone() const { return new SelectInst(*this); }
169 // Methods for support type inquiry through isa, cast, and dyn_cast:
170 static inline bool classof(const SelectInst *) { return true; }
171 static inline bool classof(const Instruction *I) {
172 return I->getOpcode() == Instruction::Select;
174 static inline bool classof(const Value *V) {
175 return isa<Instruction>(V) && classof(cast<Instruction>(V));
180 //===----------------------------------------------------------------------===//
182 //===----------------------------------------------------------------------===//
184 /// VANextInst - This class represents the va_next llvm instruction, which
185 /// advances a vararg list passed an argument of the specified type, returning
186 /// the resultant list.
188 class VANextInst : public Instruction {
190 VANextInst(const VANextInst &VAN)
191 : Instruction(VAN.getType(), VANext), ArgTy(VAN.getArgType()) {
193 Operands.push_back(Use(VAN.Operands[0], this));
196 VANextInst(Value *List, const Type *Ty, const std::string &Name = "",
197 Instruction *InsertBefore = 0)
198 : Instruction(List->getType(), VANext, Name, InsertBefore), ArgTy(Ty) {
200 Operands.push_back(Use(List, this));
203 const Type *getArgType() const { return ArgTy; }
205 virtual Instruction *clone() const { return new VANextInst(*this); }
207 // Methods for support type inquiry through isa, cast, and dyn_cast:
208 static inline bool classof(const VANextInst *) { return true; }
209 static inline bool classof(const Instruction *I) {
210 return I->getOpcode() == VANext;
212 static inline bool classof(const Value *V) {
213 return isa<Instruction>(V) && classof(cast<Instruction>(V));
218 //===----------------------------------------------------------------------===//
220 //===----------------------------------------------------------------------===//
222 /// VAArgInst - This class represents the va_arg llvm instruction, which returns
223 /// an argument of the specified type given a va_list.
225 class VAArgInst : public Instruction {
226 VAArgInst(const VAArgInst &VAA)
227 : Instruction(VAA.getType(), VAArg) {
229 Operands.push_back(Use(VAA.Operands[0], this));
232 VAArgInst(Value *List, const Type *Ty, const std::string &Name = "",
233 Instruction *InsertBefore = 0)
234 : Instruction(Ty, VAArg, Name, InsertBefore) {
236 Operands.push_back(Use(List, this));
239 virtual Instruction *clone() const { return new VAArgInst(*this); }
241 // Methods for support type inquiry through isa, cast, and dyn_cast:
242 static inline bool classof(const VAArgInst *) { return true; }
243 static inline bool classof(const Instruction *I) {
244 return I->getOpcode() == VAArg;
246 static inline bool classof(const Value *V) {
247 return isa<Instruction>(V) && classof(cast<Instruction>(V));
251 } // End llvm namespace