ce5aa9306203029a31ed7803b460a370ffb096b2
[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
42   // getIncomingBlock - Return incoming basic block #x
43   inline const BasicBlock *getIncomingBlock(unsigned i) const { 
44     return Operands[i*2+1]->castBasicBlockAsserting();
45   }
46   inline BasicBlock *getIncomingBlock(unsigned i) { 
47     return Operands[i*2+1]->castBasicBlockAsserting();
48   }
49
50   // addIncoming - Add an incoming value to the end of the PHI list
51   void addIncoming(Value *D, BasicBlock *BB);
52
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);
56 };
57
58
59 //===----------------------------------------------------------------------===//
60 //                                 CastInst Class
61 //===----------------------------------------------------------------------===//
62
63 // CastInst - This class represents a cast from Operand[0] to the type of
64 // the instruction (i->getType()).
65 //
66 class CastInst : public Instruction {
67   CastInst(const CastInst &CI) : Instruction(CI.getType(), Cast) {
68     Operands.reserve(1);
69     Operands.push_back(Use(Operands[0], this));
70   }
71 public:
72   CastInst(Value *S, const Type *Ty, const string &Name = "")
73     : Instruction(Ty, Cast, Name) {
74     Operands.reserve(1);
75     Operands.push_back(Use(S, this));
76   }
77
78   virtual Instruction *clone() const { return new CastInst(*this); }
79   virtual const char *getOpcodeName() const { return "cast"; }
80 };
81
82
83 //===----------------------------------------------------------------------===//
84 //                           MethodArgument Class
85 //===----------------------------------------------------------------------===//
86
87 class MethodArgument : public Value {  // Defined in the InstrType.cpp file
88   Method *Parent;
89
90   friend class ValueHolder<MethodArgument,Method>;
91   inline void setParent(Method *parent) { Parent = parent; }
92
93 public:
94   MethodArgument(const Type *Ty, const string &Name = "") 
95     : Value(Ty, Value::MethodArgumentVal, Name) {
96     Parent = 0;
97   }
98
99   // Specialize setName to handle symbol table majik...
100   virtual void setName(const string &name);
101
102   inline const Method *getParent() const { return Parent; }
103   inline       Method *getParent()       { return Parent; }
104 };
105
106
107 //===----------------------------------------------------------------------===//
108 //             Classes to function calls and method invocations
109 //===----------------------------------------------------------------------===//
110
111 class CallInst : public Instruction {
112   CallInst(const CallInst &CI);
113 public:
114   CallInst(Method *M, vector<Value*> &params, const string &Name = "");
115
116   virtual const char *getOpcodeName() const { return "call"; }
117
118   virtual Instruction *clone() const { return new CallInst(*this); }
119   bool hasSideEffects() const { return true; }
120
121
122   const Method *getCalledMethod() const {
123     return Operands[0]->castMethodAsserting(); 
124   }
125   Method *getCalledMethod() {
126     return Operands[0]->castMethodAsserting(); 
127   }
128 };
129
130
131 //===----------------------------------------------------------------------===//
132 //                                 ShiftInst Class
133 //===----------------------------------------------------------------------===//
134
135 // ShiftInst - This class represents left and right shift instructions.
136 //
137 class ShiftInst : public Instruction {
138   ShiftInst(const ShiftInst &CI) : Instruction(CI.getType(), CI.getOpcode()) {
139     Operands.reserve(2);
140     Operands.push_back(Use(Operands[0], this));
141     Operands.push_back(Use(Operands[1], this));
142   }
143 public:
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!");
147     Operands.reserve(2);
148     Operands.push_back(Use(S, this));
149     Operands.push_back(Use(SA, this));
150   }
151
152   virtual Instruction *clone() const { return new ShiftInst(*this); }
153   virtual const char *getOpcodeName() const {
154     return getOpcode() == Shl ? "shl" : "shr"; 
155   }
156 };
157
158 #endif