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 // FIXME: These methods should be inline once we eliminate
73 // ConstantPointerRefs!
74 const Function *getCalledFunction() const;
75 Function *getCalledFunction();
77 // getCalledValue - Get a pointer to a method that is invoked by this inst.
78 inline const Value *getCalledValue() const { return Operands[0]; }
79 inline Value *getCalledValue() { return Operands[0]; }
81 // Methods for support type inquiry through isa, cast, and dyn_cast:
82 static inline bool classof(const CallInst *) { return true; }
83 static inline bool classof(const Instruction *I) {
84 return I->getOpcode() == Instruction::Call;
86 static inline bool classof(const Value *V) {
87 return isa<Instruction>(V) && classof(cast<Instruction>(V));
92 //===----------------------------------------------------------------------===//
94 //===----------------------------------------------------------------------===//
96 // ShiftInst - This class represents left and right shift instructions.
98 class ShiftInst : public Instruction {
99 ShiftInst(const ShiftInst &SI) : Instruction(SI.getType(), SI.getOpcode()) {
101 Operands.push_back(Use(SI.Operands[0], this));
102 Operands.push_back(Use(SI.Operands[1], this));
105 ShiftInst(OtherOps Opcode, Value *S, Value *SA, const std::string &Name = "",
106 Instruction *InsertBefore = 0)
107 : Instruction(S->getType(), Opcode, Name, InsertBefore) {
108 assert((Opcode == Shl || Opcode == Shr) && "ShiftInst Opcode invalid!");
110 Operands.push_back(Use(S, this));
111 Operands.push_back(Use(SA, this));
114 OtherOps getOpcode() const { return (OtherOps)Instruction::getOpcode(); }
116 virtual Instruction *clone() const { return new ShiftInst(*this); }
118 // Methods for support type inquiry through isa, cast, and dyn_cast:
119 static inline bool classof(const ShiftInst *) { return true; }
120 static inline bool classof(const Instruction *I) {
121 return (I->getOpcode() == Instruction::Shr) |
122 (I->getOpcode() == Instruction::Shl);
124 static inline bool classof(const Value *V) {
125 return isa<Instruction>(V) && classof(cast<Instruction>(V));
130 //===----------------------------------------------------------------------===//
132 //===----------------------------------------------------------------------===//
134 /// VANextInst - This class represents the va_next llvm instruction, which
135 /// advances a vararg list passed an argument of the specified type, returning
136 /// the resultant list.
138 class VANextInst : public Instruction {
140 VANextInst(const VANextInst &VAN)
141 : Instruction(VAN.getType(), VANext), ArgTy(VAN.getArgType()) {
143 Operands.push_back(Use(VAN.Operands[0], this));
146 VANextInst(Value *List, const Type *Ty, const std::string &Name = "",
147 Instruction *InsertBefore = 0)
148 : Instruction(List->getType(), VANext, Name, InsertBefore), ArgTy(Ty) {
150 Operands.push_back(Use(List, this));
153 const Type *getArgType() const { return ArgTy; }
155 virtual Instruction *clone() const { return new VANextInst(*this); }
157 // Methods for support type inquiry through isa, cast, and dyn_cast:
158 static inline bool classof(const VANextInst *) { return true; }
159 static inline bool classof(const Instruction *I) {
160 return I->getOpcode() == VANext;
162 static inline bool classof(const Value *V) {
163 return isa<Instruction>(V) && classof(cast<Instruction>(V));
167 /// VAArgInst - This class represents the va_arg llvm instruction, which returns
168 /// an argument of the specified type given a va_list.
170 class VAArgInst : public Instruction {
171 VAArgInst(const VAArgInst &VAA)
172 : Instruction(VAA.getType(), VAArg) {
174 Operands.push_back(Use(VAA.Operands[0], this));
177 VAArgInst(Value *List, const Type *Ty, const std::string &Name = "",
178 Instruction *InsertBefore = 0)
179 : Instruction(Ty, VAArg, Name, InsertBefore) {
181 Operands.push_back(Use(List, this));
184 virtual Instruction *clone() const { return new VAArgInst(*this); }
186 bool mayWriteToMemory() const { return true; }
188 // Methods for support type inquiry through isa, cast, and dyn_cast:
189 static inline bool classof(const VAArgInst *) { return true; }
190 static inline bool classof(const Instruction *I) {
191 return I->getOpcode() == VAArg;
193 static inline bool classof(const Value *V) {
194 return isa<Instruction>(V) && classof(cast<Instruction>(V));