1 //===-- llvm/Value.h - Definition of the Value class -------------*- C++ -*--=//
3 // This file defines the very important Value class. This is subclassed by a
4 // bunch of other important classes, like Def, Method, Module, Type, etc...
6 //===----------------------------------------------------------------------===//
16 template<class ValueSubclass, class ItemParentType> class ValueHolder;
18 //===----------------------------------------------------------------------===//
20 //===----------------------------------------------------------------------===//
25 TypeVal, // This is an instance of Type
26 ConstantVal, // This is an instance of ConstPoolVal
27 MethodArgumentVal, // This is an instance of MethodArgument
28 InstructionVal, // This is an instance of Instruction
30 BasicBlockVal, // This is an instance of BasicBlock
31 MethodVal, // This is an instance of Method
32 ModuleVal, // This is an instance of Module
41 Value(const Value &); // Do not implement
43 inline void setType(const Type *ty) { Ty = ty; }
45 Value(const Type *Ty, ValueTy vty, const string &name = "");
48 inline const Type *getType() const { return Ty; }
49 inline ValueTy getValueType() const { return VTy; }
51 inline bool hasName() const { return Name != ""; }
52 inline const string &getName() const { return Name; }
53 virtual void setName(const string &name) { Name = name; }
56 // replaceAllUsesWith - Go through the uses list for this definition and make
57 // each use point to "D" instead of "this". After this completes, 'this's
58 // use list should be empty.
60 void replaceAllUsesWith(Value *D);
62 //----------------------------------------------------------------------
63 // Methods for handling the list of uses of this DEF.
65 typedef list<User*>::iterator use_iterator;
66 typedef list<User*>::const_iterator use_const_iterator;
68 inline bool use_size() const { return Uses.size(); }
69 inline bool use_empty() const { return Uses.empty(); }
70 inline use_iterator use_begin() { return Uses.begin(); }
71 inline use_const_iterator use_begin() const { return Uses.begin(); }
72 inline use_iterator use_end() { return Uses.end(); }
73 inline use_const_iterator use_end() const { return Uses.end(); }
75 inline void use_push_back(User *I) { Uses.push_back(I); }
76 User *use_remove(use_iterator &I);
78 inline void addUse(User *I) { Uses.push_back(I); }
79 void killUse(User *I);
82 // UseTy and it's friendly typedefs (Use) are here to make keeping the "use"
83 // list of a definition node up-to-date really easy.
85 template<class ValueSubclass>
90 inline UseTy<ValueSubclass>(ValueSubclass *v, User *user) {
92 if (Val) Val->addUse(U);
95 inline ~UseTy<ValueSubclass>() { if (Val) Val->killUse(U); }
97 inline operator ValueSubclass *() const { return Val; }
99 inline UseTy<ValueSubclass>(const UseTy<ValueSubclass> &user) {
104 inline ValueSubclass *operator=(ValueSubclass *V) {
105 if (Val) Val->killUse(U);
111 inline ValueSubclass *operator->() { return Val; }
112 inline const ValueSubclass *operator->() const { return Val; }
114 inline UseTy<ValueSubclass> &operator=(const UseTy<ValueSubclass> &user) {
115 if (Val) Val->killUse(U);
122 typedef UseTy<Value> Use;