1 //===-- llvm/iOther.h - "Other" instruction node definitions ----*- C++ -*-===//
3 // This file contains the declarations for instructions that fall into the
4 // grandiose 'other' catagory...
6 //===----------------------------------------------------------------------===//
11 #include "llvm/InstrTypes.h"
13 //===----------------------------------------------------------------------===//
15 //===----------------------------------------------------------------------===//
17 /// CastInst - This class represents a cast from Operand[0] to the type of
18 /// the instruction (i->getType()).
20 class CastInst : public Instruction {
21 CastInst(const CastInst &CI) : Instruction(CI.getType(), Cast) {
23 Operands.push_back(Use(CI.Operands[0], this));
26 CastInst(Value *S, const Type *Ty, const std::string &Name = "",
27 Instruction *InsertBefore = 0)
28 : Instruction(Ty, Cast, Name, InsertBefore) {
30 Operands.push_back(Use(S, this));
33 virtual Instruction *clone() const { return new CastInst(*this); }
35 // Methods for support type inquiry through isa, cast, and dyn_cast:
36 static inline bool classof(const CastInst *) { return true; }
37 static inline bool classof(const Instruction *I) {
38 return I->getOpcode() == Cast;
40 static inline bool classof(const Value *V) {
41 return isa<Instruction>(V) && classof(cast<Instruction>(V));
46 //===----------------------------------------------------------------------===//
48 //===----------------------------------------------------------------------===//
50 class CallInst : public Instruction {
51 CallInst(const CallInst &CI);
53 CallInst(Value *F, const std::vector<Value*> &Par,
54 const std::string &Name = "", Instruction *InsertBefore = 0);
56 // Alternate CallInst ctors w/ no actuals & one actual, respectively.
57 CallInst(Value *F, const std::string &Name = "",
58 Instruction *InsertBefore = 0);
59 CallInst(Value *F, Value *Actual, const std::string& Name = "",
60 Instruction* InsertBefore = 0);
62 virtual Instruction *clone() const { return new CallInst(*this); }
63 bool mayWriteToMemory() const { return true; }
65 const Function *getCalledFunction() const {
66 return dyn_cast<Function>(Operands[0].get());
68 Function *getCalledFunction() {
69 return dyn_cast<Function>(Operands[0].get());
72 // getCalledValue - Get a pointer to a method that is invoked by this inst.
73 inline const Value *getCalledValue() const { return Operands[0]; }
74 inline Value *getCalledValue() { return Operands[0]; }
76 // Methods for support type inquiry through isa, cast, and dyn_cast:
77 static inline bool classof(const CallInst *) { return true; }
78 static inline bool classof(const Instruction *I) {
79 return I->getOpcode() == Instruction::Call;
81 static inline bool classof(const Value *V) {
82 return isa<Instruction>(V) && classof(cast<Instruction>(V));
87 //===----------------------------------------------------------------------===//
89 //===----------------------------------------------------------------------===//
91 // ShiftInst - This class represents left and right shift instructions.
93 class ShiftInst : public Instruction {
94 ShiftInst(const ShiftInst &SI) : Instruction(SI.getType(), SI.getOpcode()) {
96 Operands.push_back(Use(SI.Operands[0], this));
97 Operands.push_back(Use(SI.Operands[1], this));
100 ShiftInst(OtherOps Opcode, Value *S, Value *SA, const std::string &Name = "",
101 Instruction *InsertBefore = 0)
102 : Instruction(S->getType(), Opcode, Name, InsertBefore) {
103 assert((Opcode == Shl || Opcode == Shr) && "ShiftInst Opcode invalid!");
105 Operands.push_back(Use(S, this));
106 Operands.push_back(Use(SA, this));
109 OtherOps getOpcode() const { return (OtherOps)Instruction::getOpcode(); }
111 virtual Instruction *clone() const { return new ShiftInst(*this); }
113 // Methods for support type inquiry through isa, cast, and dyn_cast:
114 static inline bool classof(const ShiftInst *) { return true; }
115 static inline bool classof(const Instruction *I) {
116 return (I->getOpcode() == Instruction::Shr) |
117 (I->getOpcode() == Instruction::Shl);
119 static inline bool classof(const Value *V) {
120 return isa<Instruction>(V) && classof(cast<Instruction>(V));
125 //===----------------------------------------------------------------------===//
127 //===----------------------------------------------------------------------===//
129 /// VANextInst - This class represents the va_next llvm instruction, which
130 /// advances a vararg list passed an argument of the specified type, returning
131 /// the resultant list.
133 class VANextInst : public Instruction {
135 VANextInst(const VANextInst &VAN)
136 : Instruction(VAN.getType(), VANext), ArgTy(VAN.getArgType()) {
138 Operands.push_back(Use(VAN.Operands[0], this));
141 VANextInst(Value *List, const Type *Ty, const std::string &Name = "",
142 Instruction *InsertBefore = 0)
143 : Instruction(List->getType(), VANext, Name, InsertBefore), ArgTy(Ty) {
145 Operands.push_back(Use(List, this));
148 const Type *getArgType() const { return ArgTy; }
150 virtual Instruction *clone() const { return new VANextInst(*this); }
152 // Methods for support type inquiry through isa, cast, and dyn_cast:
153 static inline bool classof(const VANextInst *) { return true; }
154 static inline bool classof(const Instruction *I) {
155 return I->getOpcode() == VANext;
157 static inline bool classof(const Value *V) {
158 return isa<Instruction>(V) && classof(cast<Instruction>(V));
162 /// VAArgInst - This class represents the va_arg llvm instruction, which returns
163 /// an argument of the specified type given a va_list.
165 class VAArgInst : public Instruction {
166 VAArgInst(const VAArgInst &VAA)
167 : Instruction(VAA.getType(), VAArg) {
169 Operands.push_back(Use(VAA.Operands[0], this));
172 VAArgInst(Value *List, const Type *Ty, const std::string &Name = "",
173 Instruction *InsertBefore = 0)
174 : Instruction(Ty, VAArg, Name, InsertBefore) {
176 Operands.push_back(Use(List, this));
179 virtual Instruction *clone() const { return new VAArgInst(*this); }
181 bool mayWriteToMemory() const { return true; }
183 // Methods for support type inquiry through isa, cast, and dyn_cast:
184 static inline bool classof(const VAArgInst *) { return true; }
185 static inline bool classof(const Instruction *I) {
186 return I->getOpcode() == VAArg;
188 static inline bool classof(const Value *V) {
189 return isa<Instruction>(V) && classof(cast<Instruction>(V));