1 //===-- llvm/User.h - User class definition ----------------------*- C++ -*--=//
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
7 // * Instructions are the largest class of User's.
8 // * Constants may be users of other constants (think arrays and stuff)
10 //===----------------------------------------------------------------------===//
15 #include "llvm/Value.h"
17 class User : public Value {
18 User(const User &); // Do not implement
20 std::vector<Use> Operands;
22 User(const Type *Ty, ValueTy vty, const std::string &name = "");
23 virtual ~User() { dropAllReferences(); }
25 inline Value *getOperand(unsigned i) {
26 assert(i < Operands.size() && "getOperand() out of range!");
29 inline const Value *getOperand(unsigned i) const {
30 assert(i < Operands.size() && "getOperand() const out of range!");
33 inline void setOperand(unsigned i, Value *Val) {
34 assert(i < Operands.size() && "setOperand() out of range!");
37 inline unsigned getNumOperands() const { return Operands.size(); }
39 inline std::vector<Value*> copyOperands() const {
40 return std::vector<Value*>(op_begin(), op_end());
43 // ---------------------------------------------------------------------------
44 // Operand Iterator interface...
46 typedef std::vector<Use>::iterator op_iterator;
47 typedef std::vector<Use>::const_iterator const_op_iterator;
49 inline op_iterator op_begin() { return Operands.begin(); }
50 inline const_op_iterator op_begin() const { return Operands.begin(); }
51 inline op_iterator op_end() { return Operands.end(); }
52 inline const_op_iterator op_end() const { return Operands.end(); }
54 // dropAllReferences() - This function is in charge of "letting go" of all
55 // objects that this User refers to. This allows one to
56 // 'delete' a whole class at a time, even though there may be circular
57 // references... first all references are dropped, and all use counts go to
58 // zero. Then everything is delete'd for real. Note that no operations are
59 // valid on an object that has "dropped all references", except operator
62 inline void dropAllReferences() {
66 // replaceUsesOfWith - Replaces all references to the "From" definition with
67 // references to the "To" definition. (defined in Value.cpp)
69 void replaceUsesOfWith(Value *From, Value *To);
71 // Methods for support type inquiry through isa, cast, and dyn_cast:
72 static inline bool classof(const User *) { return true; }
73 static inline bool classof(const Value *V) {
74 return V->getValueType() == Value::GlobalVariableVal ||
75 V->getValueType() == Value::ConstantVal ||
76 V->getValueType() == Value::InstructionVal;