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"
20 //===----------------------------------------------------------------------===//
22 //===----------------------------------------------------------------------===//
24 /// CastInst - This class represents a cast from Operand[0] to the type of
25 /// the instruction (i->getType()).
27 class CastInst : public Instruction {
28 CastInst(const CastInst &CI) : Instruction(CI.getType(), Cast) {
30 Operands.push_back(Use(CI.Operands[0], this));
33 CastInst(Value *S, const Type *Ty, const std::string &Name = "",
34 Instruction *InsertBefore = 0)
35 : Instruction(Ty, Cast, Name, InsertBefore) {
37 Operands.push_back(Use(S, this));
40 virtual Instruction *clone() const { return new CastInst(*this); }
42 // Methods for support type inquiry through isa, cast, and dyn_cast:
43 static inline bool classof(const CastInst *) { return true; }
44 static inline bool classof(const Instruction *I) {
45 return I->getOpcode() == Cast;
47 static inline bool classof(const Value *V) {
48 return isa<Instruction>(V) && classof(cast<Instruction>(V));
53 //===----------------------------------------------------------------------===//
55 //===----------------------------------------------------------------------===//
57 class CallInst : public Instruction {
58 CallInst(const CallInst &CI);
60 CallInst(Value *F, const std::vector<Value*> &Par,
61 const std::string &Name = "", Instruction *InsertBefore = 0);
63 // Alternate CallInst ctors w/ no actuals & one actual, respectively.
64 CallInst(Value *F, const std::string &Name = "",
65 Instruction *InsertBefore = 0);
66 CallInst(Value *F, Value *Actual, const std::string& Name = "",
67 Instruction* InsertBefore = 0);
69 virtual Instruction *clone() const { return new CallInst(*this); }
70 bool mayWriteToMemory() const { return true; }
72 const Function *getCalledFunction() const {
73 return dyn_cast<Function>(Operands[0].get());
75 Function *getCalledFunction() {
76 return dyn_cast<Function>(Operands[0].get());
79 // getCalledValue - Get a pointer to a method that is invoked by this inst.
80 inline const Value *getCalledValue() const { return Operands[0]; }
81 inline Value *getCalledValue() { return Operands[0]; }
83 // Methods for support type inquiry through isa, cast, and dyn_cast:
84 static inline bool classof(const CallInst *) { return true; }
85 static inline bool classof(const Instruction *I) {
86 return I->getOpcode() == Instruction::Call;
88 static inline bool classof(const Value *V) {
89 return isa<Instruction>(V) && classof(cast<Instruction>(V));
94 //===----------------------------------------------------------------------===//
96 //===----------------------------------------------------------------------===//
98 // ShiftInst - This class represents left and right shift instructions.
100 class ShiftInst : public Instruction {
101 ShiftInst(const ShiftInst &SI) : Instruction(SI.getType(), SI.getOpcode()) {
103 Operands.push_back(Use(SI.Operands[0], this));
104 Operands.push_back(Use(SI.Operands[1], this));
107 ShiftInst(OtherOps Opcode, Value *S, Value *SA, const std::string &Name = "",
108 Instruction *InsertBefore = 0)
109 : Instruction(S->getType(), Opcode, Name, InsertBefore) {
110 assert((Opcode == Shl || Opcode == Shr) && "ShiftInst Opcode invalid!");
112 Operands.push_back(Use(S, this));
113 Operands.push_back(Use(SA, this));
116 OtherOps getOpcode() const { return (OtherOps)Instruction::getOpcode(); }
118 virtual Instruction *clone() const { return new ShiftInst(*this); }
120 // Methods for support type inquiry through isa, cast, and dyn_cast:
121 static inline bool classof(const ShiftInst *) { return true; }
122 static inline bool classof(const Instruction *I) {
123 return (I->getOpcode() == Instruction::Shr) |
124 (I->getOpcode() == Instruction::Shl);
126 static inline bool classof(const Value *V) {
127 return isa<Instruction>(V) && classof(cast<Instruction>(V));
132 //===----------------------------------------------------------------------===//
134 //===----------------------------------------------------------------------===//
136 /// VANextInst - This class represents the va_next llvm instruction, which
137 /// advances a vararg list passed an argument of the specified type, returning
138 /// the resultant list.
140 class VANextInst : public Instruction {
142 VANextInst(const VANextInst &VAN)
143 : Instruction(VAN.getType(), VANext), ArgTy(VAN.getArgType()) {
145 Operands.push_back(Use(VAN.Operands[0], this));
148 VANextInst(Value *List, const Type *Ty, const std::string &Name = "",
149 Instruction *InsertBefore = 0)
150 : Instruction(List->getType(), VANext, Name, InsertBefore), ArgTy(Ty) {
152 Operands.push_back(Use(List, this));
155 const Type *getArgType() const { return ArgTy; }
157 virtual Instruction *clone() const { return new VANextInst(*this); }
159 // Methods for support type inquiry through isa, cast, and dyn_cast:
160 static inline bool classof(const VANextInst *) { return true; }
161 static inline bool classof(const Instruction *I) {
162 return I->getOpcode() == VANext;
164 static inline bool classof(const Value *V) {
165 return isa<Instruction>(V) && classof(cast<Instruction>(V));
169 /// VAArgInst - This class represents the va_arg llvm instruction, which returns
170 /// an argument of the specified type given a va_list.
172 class VAArgInst : public Instruction {
173 VAArgInst(const VAArgInst &VAA)
174 : Instruction(VAA.getType(), VAArg) {
176 Operands.push_back(Use(VAA.Operands[0], this));
179 VAArgInst(Value *List, const Type *Ty, const std::string &Name = "",
180 Instruction *InsertBefore = 0)
181 : Instruction(Ty, VAArg, Name, InsertBefore) {
183 Operands.push_back(Use(List, this));
186 virtual Instruction *clone() const { return new VAArgInst(*this); }
188 bool mayWriteToMemory() const { return true; }
190 // Methods for support type inquiry through isa, cast, and dyn_cast:
191 static inline bool classof(const VAArgInst *) { return true; }
192 static inline bool classof(const Instruction *I) {
193 return I->getOpcode() == VAArg;
195 static inline bool classof(const Value *V) {
196 return isa<Instruction>(V) && classof(cast<Instruction>(V));