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));
137 //===----------------------------------------------------------------------===//
139 //===----------------------------------------------------------------------===//
141 /// VANextInst - This class represents the va_next llvm instruction, which
142 /// advances a vararg list passed an argument of the specified type, returning
143 /// the resultant list.
145 class VANextInst : public Instruction {
147 VANextInst(const VANextInst &VAN)
148 : Instruction(VAN.getType(), VANext), ArgTy(VAN.getArgType()) {
150 Operands.push_back(Use(VAN.Operands[0], this));
153 VANextInst(Value *List, const Type *Ty, const std::string &Name = "",
154 Instruction *InsertBefore = 0)
155 : Instruction(List->getType(), VANext, Name, InsertBefore), ArgTy(Ty) {
157 Operands.push_back(Use(List, this));
160 const Type *getArgType() const { return ArgTy; }
162 virtual Instruction *clone() const { return new VANextInst(*this); }
164 // Methods for support type inquiry through isa, cast, and dyn_cast:
165 static inline bool classof(const VANextInst *) { return true; }
166 static inline bool classof(const Instruction *I) {
167 return I->getOpcode() == VANext;
169 static inline bool classof(const Value *V) {
170 return isa<Instruction>(V) && classof(cast<Instruction>(V));
174 /// VAArgInst - This class represents the va_arg llvm instruction, which returns
175 /// an argument of the specified type given a va_list.
177 class VAArgInst : public Instruction {
178 VAArgInst(const VAArgInst &VAA)
179 : Instruction(VAA.getType(), VAArg) {
181 Operands.push_back(Use(VAA.Operands[0], this));
184 VAArgInst(Value *List, const Type *Ty, const std::string &Name = "",
185 Instruction *InsertBefore = 0)
186 : Instruction(Ty, VAArg, Name, InsertBefore) {
188 Operands.push_back(Use(List, this));
191 virtual Instruction *clone() const { return new VAArgInst(*this); }
193 // Methods for support type inquiry through isa, cast, and dyn_cast:
194 static inline bool classof(const VAArgInst *) { return true; }
195 static inline bool classof(const Instruction *I) {
196 return I->getOpcode() == VAArg;
198 static inline bool classof(const Value *V) {
199 return isa<Instruction>(V) && classof(cast<Instruction>(V));
203 } // End llvm namespace