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]);
52 // addIncoming - Add an incoming value to the end of the PHI list
53 void addIncoming(Value *D, BasicBlock *BB);
55 // removeIncomingValue - Remove an incoming value. This is useful if a
56 // predecessor basic block is deleted. The value removed is returned.
57 Value *removeIncomingValue(const BasicBlock *BB);
60 // Methods for support type inquiry through isa, cast, and dyn_cast:
61 static inline bool classof(const PHINode *) { return true; }
62 static inline bool classof(const Instruction *I) {
63 return I->getOpcode() == Instruction::PHINode;
65 static inline bool classof(const Value *V) {
66 return isa<Instruction>(V) && classof(cast<Instruction>(V));
71 //===----------------------------------------------------------------------===//
73 //===----------------------------------------------------------------------===//
75 // CastInst - This class represents a cast from Operand[0] to the type of
76 // the instruction (i->getType()).
78 class CastInst : public Instruction {
79 CastInst(const CastInst &CI) : Instruction(CI.getType(), Cast) {
81 Operands.push_back(Use(CI.Operands[0], this));
84 CastInst(Value *S, const Type *Ty, const string &Name = "")
85 : Instruction(Ty, Cast, Name) {
87 Operands.push_back(Use(S, this));
90 virtual Instruction *clone() const { return new CastInst(*this); }
91 virtual const char *getOpcodeName() const { return "cast"; }
93 // Methods for support type inquiry through isa, cast, and dyn_cast:
94 static inline bool classof(const CastInst *) { return true; }
95 static inline bool classof(const Instruction *I) {
96 return I->getOpcode() == Cast;
98 static inline bool classof(const Value *V) {
99 return isa<Instruction>(V) && classof(cast<Instruction>(V));
104 //===----------------------------------------------------------------------===//
105 // MethodArgument Class
106 //===----------------------------------------------------------------------===//
108 class MethodArgument : public Value { // Defined in the InstrType.cpp file
111 friend class ValueHolder<MethodArgument,Method,Method>;
112 inline void setParent(Method *parent) { Parent = parent; }
115 MethodArgument(const Type *Ty, const string &Name = "")
116 : Value(Ty, Value::MethodArgumentVal, Name) {
120 // Specialize setName to handle symbol table majik...
121 virtual void setName(const string &name, SymbolTable *ST = 0);
123 inline const Method *getParent() const { return Parent; }
124 inline Method *getParent() { return Parent; }
126 // Methods for support type inquiry through isa, cast, and dyn_cast:
127 static inline bool classof(const MethodArgument *) { return true; }
128 static inline bool classof(const Value *V) {
129 return V->getValueType() == MethodArgumentVal;
134 //===----------------------------------------------------------------------===//
135 // Classes to function calls and method invocations
136 //===----------------------------------------------------------------------===//
138 class CallInst : public Instruction {
139 CallInst(const CallInst &CI);
141 CallInst(Method *M, const vector<Value*> ¶ms, const string &Name = "");
143 virtual const char *getOpcodeName() const { return "call"; }
145 virtual Instruction *clone() const { return new CallInst(*this); }
146 bool hasSideEffects() const { return true; }
149 const Method *getCalledMethod() const {
150 return cast<Method>(Operands[0]);
152 Method *getCalledMethod() {
153 return cast<Method>(Operands[0]);
156 // Methods for support type inquiry through isa, cast, and dyn_cast:
157 static inline bool classof(const CallInst *) { return true; }
158 static inline bool classof(const Instruction *I) {
159 return I->getOpcode() == Instruction::Call;
161 static inline bool classof(const Value *V) {
162 return isa<Instruction>(V) && classof(cast<Instruction>(V));
167 //===----------------------------------------------------------------------===//
169 //===----------------------------------------------------------------------===//
171 // ShiftInst - This class represents left and right shift instructions.
173 class ShiftInst : public Instruction {
174 ShiftInst(const ShiftInst &SI) : Instruction(SI.getType(), SI.getOpcode()) {
176 Operands.push_back(Use(SI.Operands[0], this));
177 Operands.push_back(Use(SI.Operands[1], this));
180 ShiftInst(OtherOps Opcode, Value *S, Value *SA, const string &Name = "")
181 : Instruction(S->getType(), Opcode, Name) {
182 assert((Opcode == Shl || Opcode == Shr) && "ShiftInst Opcode invalid!");
184 Operands.push_back(Use(S, this));
185 Operands.push_back(Use(SA, this));
188 virtual Instruction *clone() const { return new ShiftInst(*this); }
189 virtual const char *getOpcodeName() const {
190 return getOpcode() == Shl ? "shl" : "shr";
193 // Methods for support type inquiry through isa, cast, and dyn_cast:
194 static inline bool classof(const ShiftInst *) { return true; }
195 static inline bool classof(const Instruction *I) {
196 return (I->getOpcode() == Instruction::Shr) |
197 (I->getOpcode() == Instruction::Shl);
199 static inline bool classof(const Value *V) {
200 return isa<Instruction>(V) && classof(cast<Instruction>(V));