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.end(); }
48 inline op_iterator op_end() { return Operands.end(); }
49 inline op_const_iterator op_end() const { return Operands.end(); }
51 // dropAllReferences() - This virtual function should be overridden to "let
52 // go" of all references that this user is maintaining. 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 virtual 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);