1 //===-- llvm/iOther.h - "Other" instruction node definitions -----*- C++ -*--=//
3 // This file contains the declarations for instructions that fall into the
4 // grandios 'other' catagory...
6 //===----------------------------------------------------------------------===//
11 #include "llvm/InstrTypes.h"
12 #include "llvm/Method.h"
14 //===----------------------------------------------------------------------===//
16 //===----------------------------------------------------------------------===//
18 // PHINode - The PHINode class is used to represent the magical mystical PHI
19 // node, that can not exist in nature, but can be synthesized in a computer
20 // scientist's overactive imagination.
22 class PHINode : public Instruction {
23 PHINode(const PHINode &PN);
25 PHINode(const Type *Ty, const string &Name = "");
27 virtual Instruction *clone() const { return new PHINode(*this); }
28 virtual const char *getOpcodeName() const { return "phi"; }
30 // getNumIncomingValues - Return the number of incoming edges the PHI node has
31 inline unsigned getNumIncomingValues() const { return Operands.size()/2; }
33 // getIncomingValue - Return incoming value #x
34 inline const Value *getIncomingValue(unsigned i) const {
37 inline Value *getIncomingValue(unsigned i) {
40 inline void setIncomingValue(unsigned i, Value *V) {
44 // getIncomingBlock - Return incoming basic block #x
45 inline const BasicBlock *getIncomingBlock(unsigned i) const {
46 return cast<const BasicBlock>(Operands[i*2+1]);
48 inline BasicBlock *getIncomingBlock(unsigned i) {
49 return cast<BasicBlock>(Operands[i*2+1]);
51 inline void setIncomingBlock(unsigned i, BasicBlock *BB) {
55 // addIncoming - Add an incoming value to the end of the PHI list
56 void addIncoming(Value *D, BasicBlock *BB);
58 // removeIncomingValue - Remove an incoming value. This is useful if a
59 // predecessor basic block is deleted. The value removed is returned.
60 Value *removeIncomingValue(const BasicBlock *BB);
62 // getBasicBlockIndex - Return the first index of the specified basic
63 // block in the value list for this PHI. Returns -1 if no instance.
65 int getBasicBlockIndex(const BasicBlock *BB) const {
66 for (unsigned i = 0; i < Operands.size()/2; ++i)
67 if (getIncomingBlock(i) == BB) return i;
71 // Methods for support type inquiry through isa, cast, and dyn_cast:
72 static inline bool classof(const PHINode *) { return true; }
73 static inline bool classof(const Instruction *I) {
74 return I->getOpcode() == Instruction::PHINode;
76 static inline bool classof(const Value *V) {
77 return isa<Instruction>(V) && classof(cast<Instruction>(V));
82 //===----------------------------------------------------------------------===//
84 //===----------------------------------------------------------------------===//
86 // CastInst - This class represents a cast from Operand[0] to the type of
87 // the instruction (i->getType()).
89 class CastInst : public Instruction {
90 CastInst(const CastInst &CI) : Instruction(CI.getType(), Cast) {
92 Operands.push_back(Use(CI.Operands[0], this));
95 CastInst(Value *S, const Type *Ty, const string &Name = "")
96 : Instruction(Ty, Cast, Name) {
98 Operands.push_back(Use(S, this));
101 virtual Instruction *clone() const { return new CastInst(*this); }
102 virtual const char *getOpcodeName() const { return "cast"; }
104 // Methods for support type inquiry through isa, cast, and dyn_cast:
105 static inline bool classof(const CastInst *) { return true; }
106 static inline bool classof(const Instruction *I) {
107 return I->getOpcode() == Cast;
109 static inline bool classof(const Value *V) {
110 return isa<Instruction>(V) && classof(cast<Instruction>(V));
115 //===----------------------------------------------------------------------===//
116 // MethodArgument Class
117 //===----------------------------------------------------------------------===//
119 class MethodArgument : public Value { // Defined in the InstrType.cpp file
122 friend class ValueHolder<MethodArgument,Method,Method>;
123 inline void setParent(Method *parent) { Parent = parent; }
126 MethodArgument(const Type *Ty, const string &Name = "")
127 : Value(Ty, Value::MethodArgumentVal, Name) {
131 // Specialize setName to handle symbol table majik...
132 virtual void setName(const string &name, SymbolTable *ST = 0);
134 inline const Method *getParent() const { return Parent; }
135 inline Method *getParent() { return Parent; }
137 // Methods for support type inquiry through isa, cast, and dyn_cast:
138 static inline bool classof(const MethodArgument *) { return true; }
139 static inline bool classof(const Value *V) {
140 return V->getValueType() == MethodArgumentVal;
145 //===----------------------------------------------------------------------===//
146 // Classes to function calls and method invocations
147 //===----------------------------------------------------------------------===//
149 class CallInst : public Instruction {
150 CallInst(const CallInst &CI);
152 CallInst(Value *Meth, const vector<Value*> ¶ms, const string &Name = "");
154 virtual const char *getOpcodeName() const { return "call"; }
156 virtual Instruction *clone() const { return new CallInst(*this); }
157 bool hasSideEffects() const { return true; }
159 const Method *getCalledMethod() const {
160 return dyn_cast<Method>(Operands[0]);
162 Method *getCalledMethod() {
163 return dyn_cast<Method>(Operands[0]);
166 // getCalledValue - Get a pointer to a method that is invoked by this inst.
167 inline const Value *getCalledValue() const { return Operands[0]; }
168 inline Value *getCalledValue() { return Operands[0]; }
170 // Methods for support type inquiry through isa, cast, and dyn_cast:
171 static inline bool classof(const CallInst *) { return true; }
172 static inline bool classof(const Instruction *I) {
173 return I->getOpcode() == Instruction::Call;
175 static inline bool classof(const Value *V) {
176 return isa<Instruction>(V) && classof(cast<Instruction>(V));
181 //===----------------------------------------------------------------------===//
183 //===----------------------------------------------------------------------===//
185 // ShiftInst - This class represents left and right shift instructions.
187 class ShiftInst : public Instruction {
188 ShiftInst(const ShiftInst &SI) : Instruction(SI.getType(), SI.getOpcode()) {
190 Operands.push_back(Use(SI.Operands[0], this));
191 Operands.push_back(Use(SI.Operands[1], this));
194 ShiftInst(OtherOps Opcode, Value *S, Value *SA, const string &Name = "")
195 : Instruction(S->getType(), Opcode, Name) {
196 assert((Opcode == Shl || Opcode == Shr) && "ShiftInst Opcode invalid!");
198 Operands.push_back(Use(S, this));
199 Operands.push_back(Use(SA, this));
202 OtherOps getOpcode() const { return (OtherOps)Instruction::getOpcode(); }
204 virtual Instruction *clone() const { return new ShiftInst(*this); }
205 virtual const char *getOpcodeName() const {
206 return getOpcode() == Shl ? "shl" : "shr";
209 // Methods for support type inquiry through isa, cast, and dyn_cast:
210 static inline bool classof(const ShiftInst *) { return true; }
211 static inline bool classof(const Instruction *I) {
212 return (I->getOpcode() == Instruction::Shr) |
213 (I->getOpcode() == Instruction::Shl);
215 static inline bool classof(const Value *V) {
216 return isa<Instruction>(V) && classof(cast<Instruction>(V));