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 // CastInst - This function represents a cast from Operand[0] to the type of
20 // the instruction (i->getType()).
22 class CastInst : public Instruction {
23 CastInst(const CastInst &CI) : Instruction(CI.getType(), Cast) {
25 Operands.push_back(Use((Value*)CI.getOperand(0), this));
28 CastInst(Value *S, const Type *Ty, const string &Name = "")
29 : Instruction(Ty, Cast, Name) {
31 Operands.push_back(Use(S, this));
34 virtual Instruction *clone() const { return new CastInst(*this); }
35 virtual const char *getOpcodeName() const { return "cast"; }
39 //===----------------------------------------------------------------------===//
41 //===----------------------------------------------------------------------===//
43 // PHINode - The PHINode class is used to represent the magical mystical PHI
44 // node, that can not exist in nature, but can be synthesized in a computer
45 // scientist's overactive imagination.
47 class PHINode : public Instruction {
48 PHINode(const PHINode &PN);
50 PHINode(const Type *Ty, const string &Name = "");
52 virtual Instruction *clone() const { return new PHINode(*this); }
53 virtual const char *getOpcodeName() const { return "phi"; }
55 // getNumIncomingValues - Return the number of incoming edges the PHI node has
56 inline unsigned getNumIncomingValues() const { return Operands.size()/2; }
58 // getIncomingValue - Return incoming value #x
59 inline const Value *getIncomingValue(unsigned i) const {
62 inline Value *getIncomingValue(unsigned i) {
66 // getIncomingBlock - Return incoming basic block #x
67 inline const BasicBlock *getIncomingBlock(unsigned i) const {
68 return Operands[i*2+1]->castBasicBlockAsserting();
70 inline BasicBlock *getIncomingBlock(unsigned i) {
71 return Operands[i*2+1]->castBasicBlockAsserting();
74 // addIncoming - Add an incoming value to the end of the PHI list
75 void addIncoming(Value *D, BasicBlock *BB);
77 // removeIncomingValue - Remove an incoming value. This is useful if a
78 // predecessor basic block is deleted. The value removed is returned.
79 Value *removeIncomingValue(const BasicBlock *BB);
83 //===----------------------------------------------------------------------===//
84 // MethodArgument Class
85 //===----------------------------------------------------------------------===//
87 class MethodArgument : public Value { // Defined in the InstrType.cpp file
90 friend class ValueHolder<MethodArgument,Method>;
91 inline void setParent(Method *parent) { Parent = parent; }
94 MethodArgument(const Type *Ty, const string &Name = "")
95 : Value(Ty, Value::MethodArgumentVal, Name) {
99 // Specialize setName to handle symbol table majik...
100 virtual void setName(const string &name);
102 inline const Method *getParent() const { return Parent; }
103 inline Method *getParent() { return Parent; }
107 //===----------------------------------------------------------------------===//
108 // Classes to function calls and method invocations
109 //===----------------------------------------------------------------------===//
111 class CallInst : public Instruction {
112 CallInst(const CallInst &CI);
114 CallInst(Method *M, vector<Value*> ¶ms, const string &Name = "");
116 virtual const char *getOpcodeName() const { return "call"; }
118 virtual Instruction *clone() const { return new CallInst(*this); }
119 bool hasSideEffects() const { return true; }
122 const Method *getCalledMethod() const {
123 return Operands[0]->castMethodAsserting();
125 Method *getCalledMethod() {
126 return Operands[0]->castMethodAsserting();