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"
18 class User : public Value {
19 User(const User &); // Do not implement
23 User(const Type *Ty, ValueTy vty, const string &name = "");
24 virtual ~User() { dropAllReferences(); }
26 inline Value *getOperand(unsigned i) {
27 assert(i < Operands.size() && "getOperand() out of range!");
30 inline const Value *getOperand(unsigned i) const {
31 assert(i < Operands.size() && "getOperand() const out of range!");
34 inline void setOperand(unsigned i, Value *Val) {
35 assert(i < Operands.size() && "setOperand() out of range!");
38 inline unsigned getNumOperands() const { return Operands.size(); }
40 // ---------------------------------------------------------------------------
41 // Operand Iterator interface...
43 typedef vector<Use>::iterator op_iterator;
44 typedef vector<Use>::const_iterator op_const_iterator;
46 inline op_iterator op_begin() { return Operands.begin(); }
47 inline op_const_iterator op_begin() const { return Operands.begin(); }
48 inline op_iterator op_end() { return Operands.end(); }
49 inline op_const_iterator op_end() const { return Operands.end(); }
51 // dropAllReferences() - This function is in charge of "letting go" of all
52 // objects that this User refers to. This allows one to
53 // 'delete' a whole class at a time, even though there may be circular
54 // references... first all references are dropped, and all use counts go to
55 // zero. Then everything is delete'd for real. Note that no operations are
56 // valid on an object that has "dropped all references", except operator
59 inline void dropAllReferences() {
63 // replaceUsesOfWith - Replaces all references to the "From" definition with
64 // references to the "To" definition. (defined in Value.cpp)
66 void replaceUsesOfWith(Value *From, Value *To);
68 // addOperand - This is a special purpose API that should not be used in most
69 // cases. It adds an empty (null) operand to the instruction specified. This
70 // is currently used by the back end as part of the "lowering" process... most
71 // optimizations will not handle instructions that are not in their normal
72 // form, so this method should be used with care.
75 Operands.push_back(Use(0, this));