97f326258101744252a2d9054315603fcd23bd5d
[oota-llvm.git] / include / llvm / iOther.h
1 //===-- llvm/iOther.h - "Other" instruction node definitions -----*- C++ -*--=//
2 //
3 // This file contains the declarations for instructions that fall into the 
4 // grandios 'other' catagory...
5 //
6 //===----------------------------------------------------------------------===//
7
8 #ifndef LLVM_IOTHER_H
9 #define LLVM_IOTHER_H
10
11 #include "llvm/InstrTypes.h"
12 #include "llvm/Method.h"
13 #include <vector>
14
15 //===----------------------------------------------------------------------===//
16 //                               PHINode Class
17 //===----------------------------------------------------------------------===//
18
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.
22 //
23 class PHINode : public Instruction {
24   PHINode(const PHINode &PN);
25 public:
26   PHINode(const Type *Ty, const string &Name = "");
27
28   virtual Instruction *clone() const { return new PHINode(*this); }
29   virtual const char *getOpcodeName() const { return "phi"; }
30
31   // getNumIncomingValues - Return the number of incoming edges the PHI node has
32   inline unsigned getNumIncomingValues() const { return Operands.size()/2; }
33
34   // getIncomingValue - Return incoming value #x
35   inline const Value *getIncomingValue(unsigned i) const {
36     return Operands[i*2];
37   }
38   inline Value *getIncomingValue(unsigned i) {
39     return Operands[i*2];
40   }
41   inline void setIncomingValue(unsigned i, Value *V) {
42     Operands[i*2] = V;
43   }
44
45   // getIncomingBlock - Return incoming basic block #x
46   inline const BasicBlock *getIncomingBlock(unsigned i) const { 
47     return Operands[i*2+1]->castBasicBlockAsserting();
48   }
49   inline BasicBlock *getIncomingBlock(unsigned i) { 
50     return Operands[i*2+1]->castBasicBlockAsserting();
51   }
52
53   // addIncoming - Add an incoming value to the end of the PHI list
54   void addIncoming(Value *D, BasicBlock *BB);
55
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);
59 };
60
61
62 //===----------------------------------------------------------------------===//
63 //                                 CastInst Class
64 //===----------------------------------------------------------------------===//
65
66 // CastInst - This class represents a cast from Operand[0] to the type of
67 // the instruction (i->getType()).
68 //
69 class CastInst : public Instruction {
70   CastInst(const CastInst &CI) : Instruction(CI.getType(), Cast) {
71     Operands.reserve(1);
72     Operands.push_back(Use(CI.Operands[0], this));
73   }
74 public:
75   CastInst(Value *S, const Type *Ty, const string &Name = "")
76     : Instruction(Ty, Cast, Name) {
77     Operands.reserve(1);
78     Operands.push_back(Use(S, this));
79   }
80
81   virtual Instruction *clone() const { return new CastInst(*this); }
82   virtual const char *getOpcodeName() const { return "cast"; }
83 };
84
85
86 //===----------------------------------------------------------------------===//
87 //                           MethodArgument Class
88 //===----------------------------------------------------------------------===//
89
90 class MethodArgument : public Value {  // Defined in the InstrType.cpp file
91   Method *Parent;
92
93   friend class ValueHolder<MethodArgument,Method,Method>;
94   inline void setParent(Method *parent) { Parent = parent; }
95
96 public:
97   MethodArgument(const Type *Ty, const string &Name = "") 
98     : Value(Ty, Value::MethodArgumentVal, Name) {
99     Parent = 0;
100   }
101
102   // Specialize setName to handle symbol table majik...
103   virtual void setName(const string &name, SymbolTable *ST = 0);
104
105   inline const Method *getParent() const { return Parent; }
106   inline       Method *getParent()       { return Parent; }
107 };
108
109
110 //===----------------------------------------------------------------------===//
111 //             Classes to function calls and method invocations
112 //===----------------------------------------------------------------------===//
113
114 class CallInst : public Instruction {
115   CallInst(const CallInst &CI);
116 public:
117   CallInst(Method *M, const vector<Value*> &params, const string &Name = "");
118
119   virtual const char *getOpcodeName() const { return "call"; }
120
121   virtual Instruction *clone() const { return new CallInst(*this); }
122   bool hasSideEffects() const { return true; }
123
124
125   const Method *getCalledMethod() const {
126     return Operands[0]->castMethodAsserting(); 
127   }
128   Method *getCalledMethod() {
129     return Operands[0]->castMethodAsserting(); 
130   }
131 };
132
133
134 //===----------------------------------------------------------------------===//
135 //                                 ShiftInst Class
136 //===----------------------------------------------------------------------===//
137
138 // ShiftInst - This class represents left and right shift instructions.
139 //
140 class ShiftInst : public Instruction {
141   ShiftInst(const ShiftInst &SI) : Instruction(SI.getType(), SI.getOpcode()) {
142     Operands.reserve(2);
143     Operands.push_back(Use(SI.Operands[0], this));
144     Operands.push_back(Use(SI.Operands[1], this));
145   }
146 public:
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!");
150     Operands.reserve(2);
151     Operands.push_back(Use(S, this));
152     Operands.push_back(Use(SA, this));
153   }
154
155   virtual Instruction *clone() const { return new ShiftInst(*this); }
156   virtual const char *getOpcodeName() const {
157     return getOpcode() == Shl ? "shl" : "shr"; 
158   }
159 };
160
161 #endif