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 PHINode(const PHINode &PN);
26 PHINode(const Type *Ty, const string &Name = "");
28 virtual Instruction *clone() const { return new PHINode(*this); }
29 virtual const char *getOpcodeName() const { return "phi"; }
31 // getNumIncomingValues - Return the number of incoming edges the PHI node has
32 inline unsigned getNumIncomingValues() const { return Operands.size()/2; }
34 // getIncomingValue - Return incoming value #x
35 inline const Value *getIncomingValue(unsigned i) const {
38 inline Value *getIncomingValue(unsigned i) {
42 // getIncomingBlock - Return incoming basic block #x
43 inline const BasicBlock *getIncomingBlock(unsigned i) const {
44 return Operands[i*2+1]->castBasicBlockAsserting();
46 inline BasicBlock *getIncomingBlock(unsigned i) {
47 return Operands[i*2+1]->castBasicBlockAsserting();
50 // addIncoming - Add an incoming value to the end of the PHI list
51 void addIncoming(Value *D, BasicBlock *BB);
53 // removeIncomingValue - Remove an incoming value. This is useful if a
54 // predecessor basic block is deleted. The value removed is returned.
55 Value *removeIncomingValue(const BasicBlock *BB);
59 //===----------------------------------------------------------------------===//
61 //===----------------------------------------------------------------------===//
63 // CastInst - This class represents a cast from Operand[0] to the type of
64 // the instruction (i->getType()).
66 class CastInst : public Instruction {
67 CastInst(const CastInst &CI) : Instruction(CI.getType(), Cast) {
69 Operands.push_back(Use(Operands[0], this));
72 CastInst(Value *S, const Type *Ty, const string &Name = "")
73 : Instruction(Ty, Cast, Name) {
75 Operands.push_back(Use(S, this));
78 virtual Instruction *clone() const { return new CastInst(*this); }
79 virtual const char *getOpcodeName() const { return "cast"; }
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();
131 //===----------------------------------------------------------------------===//
133 //===----------------------------------------------------------------------===//
135 // ShiftInst - This class represents left and right shift instructions.
137 class ShiftInst : public Instruction {
138 ShiftInst(const ShiftInst &CI) : Instruction(CI.getType(), CI.getOpcode()) {
140 Operands.push_back(Use(Operands[0], this));
141 Operands.push_back(Use(Operands[1], this));
144 ShiftInst(OtherOps Opcode, Value *S, Value *SA, const string &Name = "")
145 : Instruction(S->getType(), Opcode, Name) {
146 assert((Opcode == Shl || Opcode == Shr) && "ShiftInst Opcode invalid!");
148 Operands.push_back(Use(S, this));
149 Operands.push_back(Use(SA, this));
152 virtual Instruction *clone() const { return new ShiftInst(*this); }
153 virtual const char *getOpcodeName() const {
154 return getOpcode() == Shl ? "shl" : "shr";