Change the Opcode enum for PHI nodes from "Instruction::PHINode" to "Instruction...
[oota-llvm.git] / include / llvm / User.h
1 //===-- llvm/User.h - User class definition ---------------------*- C++ -*-===//
2 //
3 // This class defines the interface that one who 'use's a Value must implement.
4 // Each instance of the Value class keeps track of what User's have handles
5 // to it.
6 //
7 //  * Instructions are the largest class of User's.
8 //  * Constants may be users of other constants (think arrays and stuff)
9 //
10 //===----------------------------------------------------------------------===//
11
12 #ifndef LLVM_USER_H
13 #define LLVM_USER_H
14
15 #include "llvm/Value.h"
16 #include <vector>
17
18 class User : public Value {
19   User(const User &);             // Do not implement
20 protected:
21   std::vector<Use> Operands;
22 public:
23   User(const Type *Ty, ValueTy vty, const std::string &name = "");
24
25   inline Value *getOperand(unsigned i) { 
26     assert(i < Operands.size() && "getOperand() out of range!");
27     return Operands[i];
28   }
29   inline const Value *getOperand(unsigned i) const {
30     assert(i < Operands.size() && "getOperand() const out of range!");
31     return Operands[i];
32   }
33   inline void setOperand(unsigned i, Value *Val) {
34     assert(i < Operands.size() && "setOperand() out of range!");
35     Operands[i] = Val;
36   }
37   inline unsigned getNumOperands() const { return Operands.size(); }
38
39   // ---------------------------------------------------------------------------
40   // Operand Iterator interface...
41   //
42   typedef std::vector<Use>::iterator       op_iterator;
43   typedef std::vector<Use>::const_iterator const_op_iterator;
44
45   void op_reserve(unsigned NumElements) { Operands.reserve(NumElements); }
46
47   inline op_iterator       op_begin()       { return Operands.begin(); }
48   inline const_op_iterator op_begin() const { return Operands.begin(); }
49   inline op_iterator       op_end()         { return Operands.end(); }
50   inline const_op_iterator op_end()   const { return Operands.end(); }
51
52   /// op_erase - This method is used to remove one of the arguments from the
53   /// operands list.  Only use this if you know what you are doing.
54   ///
55   op_iterator op_erase(op_iterator I) { return Operands.erase(I); }
56   op_iterator op_erase(op_iterator I, op_iterator E) {
57     return Operands.erase(I, E);
58   }
59
60   // dropAllReferences() - This function is in charge of "letting go" of all
61   // objects that this User refers to.  This allows one to
62   // 'delete' a whole class at a time, even though there may be circular
63   // references... first all references are dropped, and all use counts go to
64   // zero.  Then everything is delete'd for real.  Note that no operations are
65   // valid on an object that has "dropped all references", except operator 
66   // delete.
67   //
68   inline void dropAllReferences() {
69     Operands.clear();
70   }
71
72   /// replaceUsesOfWith - Replaces all references to the "From" definition with
73   /// references to the "To" definition.
74   ///
75   void replaceUsesOfWith(Value *From, Value *To);
76
77   // Methods for support type inquiry through isa, cast, and dyn_cast:
78   static inline bool classof(const User *) { return true; }
79   static inline bool classof(const Value *V) {
80     return V->getValueType() == Value::GlobalVariableVal ||
81            V->getValueType() == Value::ConstantVal ||
82            V->getValueType() == Value::InstructionVal;
83   }
84 };
85
86 template<> struct simplify_type<User::op_iterator> {
87   typedef Value* SimpleType;
88   
89   static SimpleType getSimplifiedValue(const User::op_iterator &Val) {
90     return (SimpleType)Val->get();
91   }
92 };
93 template<> struct simplify_type<const User::op_iterator>
94   : public simplify_type<User::op_iterator> {};
95
96 template<> struct simplify_type<User::const_op_iterator> {
97   typedef Value* SimpleType;
98   
99   static SimpleType getSimplifiedValue(const User::const_op_iterator &Val) {
100     return (SimpleType)Val->get();
101   }
102 };
103 template<> struct simplify_type<const User::const_op_iterator>
104   : public simplify_type<User::const_op_iterator> {};
105
106 #endif