Moved Cast from being a Unary instruction to being an "Other" instruction
[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 //                                 CastInst Class
17 //===----------------------------------------------------------------------===//
18
19 // CastInst - This function represents a cast from Operand[0] to the type of
20 // the instruction (i->getType()).
21 //
22 class CastInst : public Instruction {
23   CastInst(const CastInst &CI) : Instruction(CI.getType(), Cast) {
24     Operands.reserve(1);
25     Operands.push_back(Use((Value*)CI.getOperand(0), this));
26   }
27 public:
28   CastInst(Value *S, const Type *Ty, const string &Name = "")
29     : Instruction(Ty, Cast, Name) {
30     Operands.reserve(1);
31     Operands.push_back(Use(S, this));
32   }
33
34   virtual Instruction *clone() const { return new CastInst(*this); }
35   virtual const char *getOpcodeName() const { return "cast"; }
36 };
37
38
39 //===----------------------------------------------------------------------===//
40 //                               PHINode Class
41 //===----------------------------------------------------------------------===//
42
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.
46 //
47 class PHINode : public Instruction {
48   PHINode(const PHINode &PN);
49 public:
50   PHINode(const Type *Ty, const string &Name = "");
51
52   virtual Instruction *clone() const { return new PHINode(*this); }
53   virtual const char *getOpcodeName() const { return "phi"; }
54
55   // getNumIncomingValues - Return the number of incoming edges the PHI node has
56   inline unsigned getNumIncomingValues() const { return Operands.size()/2; }
57
58   // getIncomingValue - Return incoming value #x
59   inline const Value *getIncomingValue(unsigned i) const {
60     return Operands[i*2];
61   }
62   inline Value *getIncomingValue(unsigned i) {
63     return Operands[i*2];
64   }
65
66   // getIncomingBlock - Return incoming basic block #x
67   inline const BasicBlock *getIncomingBlock(unsigned i) const { 
68     return Operands[i*2+1]->castBasicBlockAsserting();
69   }
70   inline BasicBlock *getIncomingBlock(unsigned i) { 
71     return Operands[i*2+1]->castBasicBlockAsserting();
72   }
73
74   // addIncoming - Add an incoming value to the end of the PHI list
75   void addIncoming(Value *D, BasicBlock *BB);
76
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);
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 #endif