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 class CallInst : public Instruction {
60 CallInst(const CallInst &CI);
62 CallInst(Value *F, const std::vector<Value*> &Par,
63 const std::string &Name = "", Instruction *InsertBefore = 0);
65 // Alternate CallInst ctors w/ no actuals & one actual, respectively.
66 CallInst(Value *F, const std::string &Name = "",
67 Instruction *InsertBefore = 0);
68 CallInst(Value *F, Value *Actual, const std::string& Name = "",
69 Instruction* InsertBefore = 0);
71 virtual Instruction *clone() const { return new CallInst(*this); }
72 bool mayWriteToMemory() const { return true; }
74 // FIXME: These methods should be inline once we eliminate
75 // ConstantPointerRefs!
76 const Function *getCalledFunction() const;
77 Function *getCalledFunction();
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 {
117 return static_cast<OtherOps>(Instruction::getOpcode());
120 virtual Instruction *clone() const { return new ShiftInst(*this); }
122 // Methods for support type inquiry through isa, cast, and dyn_cast:
123 static inline bool classof(const ShiftInst *) { return true; }
124 static inline bool classof(const Instruction *I) {
125 return (I->getOpcode() == Instruction::Shr) |
126 (I->getOpcode() == Instruction::Shl);
128 static inline bool classof(const Value *V) {
129 return isa<Instruction>(V) && classof(cast<Instruction>(V));
134 //===----------------------------------------------------------------------===//
136 //===----------------------------------------------------------------------===//
138 /// VANextInst - This class represents the va_next llvm instruction, which
139 /// advances a vararg list passed an argument of the specified type, returning
140 /// the resultant list.
142 class VANextInst : public Instruction {
144 VANextInst(const VANextInst &VAN)
145 : Instruction(VAN.getType(), VANext), ArgTy(VAN.getArgType()) {
147 Operands.push_back(Use(VAN.Operands[0], this));
150 VANextInst(Value *List, const Type *Ty, const std::string &Name = "",
151 Instruction *InsertBefore = 0)
152 : Instruction(List->getType(), VANext, Name, InsertBefore), ArgTy(Ty) {
154 Operands.push_back(Use(List, this));
157 const Type *getArgType() const { return ArgTy; }
159 virtual Instruction *clone() const { return new VANextInst(*this); }
161 // Methods for support type inquiry through isa, cast, and dyn_cast:
162 static inline bool classof(const VANextInst *) { return true; }
163 static inline bool classof(const Instruction *I) {
164 return I->getOpcode() == VANext;
166 static inline bool classof(const Value *V) {
167 return isa<Instruction>(V) && classof(cast<Instruction>(V));
171 /// VAArgInst - This class represents the va_arg llvm instruction, which returns
172 /// an argument of the specified type given a va_list.
174 class VAArgInst : public Instruction {
175 VAArgInst(const VAArgInst &VAA)
176 : Instruction(VAA.getType(), VAArg) {
178 Operands.push_back(Use(VAA.Operands[0], this));
181 VAArgInst(Value *List, const Type *Ty, const std::string &Name = "",
182 Instruction *InsertBefore = 0)
183 : Instruction(Ty, VAArg, Name, InsertBefore) {
185 Operands.push_back(Use(List, this));
188 virtual Instruction *clone() const { return new VAArgInst(*this); }
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));
200 } // End llvm namespace