Renamed inst_const_iterator -> const_inst_iterator
[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
17 class User : public Value {
18   User(const User &);             // Do not implement
19 protected:
20   vector<Use> Operands;
21 public:
22   User(const Type *Ty, ValueTy vty, const string &name = "");
23   virtual ~User() { dropAllReferences(); }
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 vector<Use>::iterator       op_iterator;
43   typedef vector<Use>::const_iterator const_op_iterator;
44
45   inline op_iterator       op_begin()       { return Operands.begin(); }
46   inline const_op_iterator op_begin() const { return Operands.begin(); }
47   inline op_iterator       op_end()         { return Operands.end(); }
48   inline const_op_iterator op_end()   const { return Operands.end(); }
49
50   // dropAllReferences() - This function is in charge of "letting go" of all
51   // objects that this User refers to.  This allows one to
52   // 'delete' a whole class at a time, even though there may be circular
53   // references... first all references are dropped, and all use counts go to
54   // zero.  Then everything is delete'd for real.  Note that no operations are
55   // valid on an object that has "dropped all references", except operator 
56   // delete.
57   //
58   inline void dropAllReferences() {
59     Operands.clear();
60   }
61
62   // replaceUsesOfWith - Replaces all references to the "From" definition with
63   // references to the "To" definition.  (defined in Value.cpp)
64   //
65   void replaceUsesOfWith(Value *From, Value *To);
66
67   // Methods for support type inquiry through isa, cast, and dyn_cast:
68   static inline bool classof(const User *) { return true; }
69   static inline bool classof(const Value *V) {
70     return V->getValueType() == Value::GlobalVariableVal ||
71            V->getValueType() == Value::ConstantVal ||
72            V->getValueType() == Value::InstructionVal;
73   }
74
75   // addOperand - This is a special purpose API that should not be used in most
76   // cases.  It adds an empty (null) operand to the instruction specified.  This
77   // is currently used by the back end as part of the "lowering" process... most
78   // optimizations will not handle instructions that are not in their normal
79   // form, so this method should be used with care.
80   //
81   void addOperand() {
82     Operands.push_back(Use(0, this));
83   }
84 };
85
86 #endif