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"
15 //===----------------------------------------------------------------------===//
17 //===----------------------------------------------------------------------===//
19 // PHINode - The PHINode class is used to represent the magical mystical PHI
20 // node, that can not exist in nature, but can be synthesized in a computer
21 // scientist's overactive imagination.
23 class PHINode : public Instruction {
24 typedef pair<Use,BasicBlockUse> PairTy;
25 vector<PairTy> IncomingValues;
27 PHINode(const PHINode &PN);
29 PHINode(const Type *Ty, const string &Name = "");
30 inline ~PHINode() { dropAllReferences(); }
32 virtual Instruction *clone() const { return new PHINode(*this); }
34 // Implement all of the functionality required by User...
36 virtual void dropAllReferences();
37 virtual const Value *getOperand(unsigned i) const {
38 if (i >= IncomingValues.size()*2) return 0;
39 if (i & 1) return IncomingValues[i/2].second;
40 else return IncomingValues[i/2].first;
42 inline Value *getOperand(unsigned i) {
43 return (Value*)((const PHINode*)this)->getOperand(i);
45 virtual unsigned getNumOperands() const { return IncomingValues.size()*2; }
46 virtual bool setOperand(unsigned i, Value *Val);
47 virtual string getOpcode() const { return "phi"; }
49 // getNumIncomingValues - Return the number of incoming edges the PHI node has
50 inline unsigned getNumIncomingValues() const { return IncomingValues.size(); }
52 // getIncomingValue - Return incoming value #x
53 inline Value *getIncomingValue(unsigned i) const { return IncomingValues[i].first; }
55 // getIncomingBlock - Return incoming basic block #x
56 inline BasicBlock *getIncomingBlock(unsigned i) const { return IncomingValues[i].second; }
58 // addIncoming - Add an incoming value to the end of the PHI list
59 void addIncoming(Value *D, BasicBlock *BB);
61 // removeIncomingValue - Remove an incoming value. This is useful if a
62 // predecessor basic block is deleted. The value removed is returned.
63 Value *removeIncomingValue(const BasicBlock *BB);
67 //===----------------------------------------------------------------------===//
68 // MethodArgument Class
69 //===----------------------------------------------------------------------===//
71 class MethodArgument : public Value { // Defined in the InstrType.cpp file
74 friend class ValueHolder<MethodArgument,Method>;
75 inline void setParent(Method *parent) { Parent = parent; }
78 MethodArgument(const Type *Ty, const string &Name = "")
79 : Value(Ty, Value::MethodArgumentVal, Name) {
83 // Specialize setName to handle symbol table majik...
84 virtual void setName(const string &name);
86 inline const Method *getParent() const { return Parent; }
87 inline Method *getParent() { return Parent; }
91 //===----------------------------------------------------------------------===//
92 // Classes to function calls and method invocations
93 //===----------------------------------------------------------------------===//
95 class CallInst : public Instruction {
98 CallInst(const CallInst &CI);
100 CallInst(Method *M, vector<Value*> ¶ms, const string &Name = "");
101 inline ~CallInst() { dropAllReferences(); }
103 virtual string getOpcode() const { return "call"; }
105 virtual Instruction *clone() const { return new CallInst(*this); }
106 bool hasSideEffects() const { return true; }
109 const Method *getCalledMethod() const { return M; }
110 Method *getCalledMethod() { return M; }
112 // Implement all of the functionality required by Instruction...
114 virtual void dropAllReferences();
115 virtual const Value *getOperand(unsigned i) const {
116 return i == 0 ? M : ((i <= Params.size()) ? Params[i-1] : 0);
118 inline Value *getOperand(unsigned i) {
119 return (Value*)((const CallInst*)this)->getOperand(i);
121 virtual unsigned getNumOperands() const { return Params.size()+1; }
123 virtual bool setOperand(unsigned i, Value *Val);