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) {
41 inline void setIncomingValue(unsigned i, Value *V) {
45 // getIncomingBlock - Return incoming basic block #x
46 inline const BasicBlock *getIncomingBlock(unsigned i) const {
47 return Operands[i*2+1]->castBasicBlockAsserting();
49 inline BasicBlock *getIncomingBlock(unsigned i) {
50 return Operands[i*2+1]->castBasicBlockAsserting();
53 // addIncoming - Add an incoming value to the end of the PHI list
54 void addIncoming(Value *D, BasicBlock *BB);
56 // removeIncomingValue - Remove an incoming value. This is useful if a
57 // predecessor basic block is deleted. The value removed is returned.
58 Value *removeIncomingValue(const BasicBlock *BB);
62 //===----------------------------------------------------------------------===//
64 //===----------------------------------------------------------------------===//
66 // CastInst - This class represents a cast from Operand[0] to the type of
67 // the instruction (i->getType()).
69 class CastInst : public Instruction {
70 CastInst(const CastInst &CI) : Instruction(CI.getType(), Cast) {
72 Operands.push_back(Use(CI.Operands[0], this));
75 CastInst(Value *S, const Type *Ty, const string &Name = "")
76 : Instruction(Ty, Cast, Name) {
78 Operands.push_back(Use(S, this));
81 virtual Instruction *clone() const { return new CastInst(*this); }
82 virtual const char *getOpcodeName() const { return "cast"; }
86 //===----------------------------------------------------------------------===//
87 // MethodArgument Class
88 //===----------------------------------------------------------------------===//
90 class MethodArgument : public Value { // Defined in the InstrType.cpp file
93 friend class ValueHolder<MethodArgument,Method,Method>;
94 inline void setParent(Method *parent) { Parent = parent; }
97 MethodArgument(const Type *Ty, const string &Name = "")
98 : Value(Ty, Value::MethodArgumentVal, Name) {
102 // Specialize setName to handle symbol table majik...
103 virtual void setName(const string &name, SymbolTable *ST = 0);
105 inline const Method *getParent() const { return Parent; }
106 inline Method *getParent() { return Parent; }
110 //===----------------------------------------------------------------------===//
111 // Classes to function calls and method invocations
112 //===----------------------------------------------------------------------===//
114 class CallInst : public Instruction {
115 CallInst(const CallInst &CI);
117 CallInst(Method *M, const vector<Value*> ¶ms, const string &Name = "");
119 virtual const char *getOpcodeName() const { return "call"; }
121 virtual Instruction *clone() const { return new CallInst(*this); }
122 bool hasSideEffects() const { return true; }
125 const Method *getCalledMethod() const {
126 return Operands[0]->castMethodAsserting();
128 Method *getCalledMethod() {
129 return Operands[0]->castMethodAsserting();
134 //===----------------------------------------------------------------------===//
136 //===----------------------------------------------------------------------===//
138 // ShiftInst - This class represents left and right shift instructions.
140 class ShiftInst : public Instruction {
141 ShiftInst(const ShiftInst &SI) : Instruction(SI.getType(), SI.getOpcode()) {
143 Operands.push_back(Use(SI.Operands[0], this));
144 Operands.push_back(Use(SI.Operands[1], this));
147 ShiftInst(OtherOps Opcode, Value *S, Value *SA, const string &Name = "")
148 : Instruction(S->getType(), Opcode, Name) {
149 assert((Opcode == Shl || Opcode == Shr) && "ShiftInst Opcode invalid!");
151 Operands.push_back(Use(S, this));
152 Operands.push_back(Use(SA, this));
155 virtual Instruction *clone() const { return new ShiftInst(*this); }
156 virtual const char *getOpcodeName() const {
157 return getOpcode() == Shl ? "shl" : "shr";