1 //===-- llvm/Use.h - Definition of the Use class ----------------*- C++ -*-===//
3 // This defines the Use class. The Use class represents the operand of an
4 // instruction or some other User instance which refers to a Value. The Use
5 // class keeps the "use list" of the referenced value up to date.
7 //===----------------------------------------------------------------------===//
12 #include "Support/ilist"
13 template<typename NodeTy> struct ilist_traits;
18 //===----------------------------------------------------------------------===//
20 //===----------------------------------------------------------------------===//
22 // Use is here to make keeping the "use" list of a Value up-to-date really easy.
28 friend class ilist_traits<Use>;
30 inline Use(Value *v, User *user);
31 inline Use(const Use &u);
34 operator Value*() const { return Val; }
35 Value *get() const { return Val; }
36 User *getUser() const { return U; }
38 inline void set(Value *Val);
40 Value *operator=(Value *RHS) {
44 const Use &operator=(const Use &RHS) {
49 Value *operator->() { return Val; }
50 const Value *operator->() const { return Val; }
54 struct ilist_traits<Use> {
55 static Use *getPrev(Use *N) { return N->Prev; }
56 static Use *getNext(Use *N) { return N->Next; }
57 static const Use *getPrev(const Use *N) { return N->Prev; }
58 static const Use *getNext(const Use *N) { return N->Next; }
59 static void setPrev(Use *N, Use *Prev) { N->Prev = Prev; }
60 static void setNext(Use *N, Use *Next) { N->Next = Next; }
62 // createNode - this is used to create the end marker for the use list
63 static Use *createNode() { return new Use(0,0); }
65 void addNodeToList(Use *NTy) {}
66 void removeNodeFromList(Use *NTy) {}
67 void transferNodesFromList(iplist<Use, ilist_traits> &L2,
68 ilist_iterator<Use> first,
69 ilist_iterator<Use> last) {}
73 template<> struct simplify_type<Use> {
74 typedef Value* SimpleType;
75 static SimpleType getSimplifiedValue(const Use &Val) {
76 return (SimpleType)Val.get();
79 template<> struct simplify_type<const Use> {
80 typedef Value* SimpleType;
81 static SimpleType getSimplifiedValue(const Use &Val) {
82 return (SimpleType)Val.get();
86 struct UseListIteratorWrapper : public iplist<Use>::iterator {
87 typedef iplist<Use>::iterator Super;
88 UseListIteratorWrapper() {}
89 UseListIteratorWrapper(const Super &RHS) : Super(RHS) {}
91 UseListIteratorWrapper &operator=(const Super &RHS) {
92 Super::operator=(RHS);
96 inline User *operator*() const;
97 User *operator->() const { return operator*(); }
99 UseListIteratorWrapper operator--() { return Super::operator--(); }
100 UseListIteratorWrapper operator++() { return Super::operator++(); }
102 UseListIteratorWrapper operator--(int) { // postdecrement operators...
103 UseListIteratorWrapper tmp = *this;
107 UseListIteratorWrapper operator++(int) { // postincrement operators...
108 UseListIteratorWrapper tmp = *this;
114 struct UseListConstIteratorWrapper : public iplist<Use>::const_iterator {
115 typedef iplist<Use>::const_iterator Super;
116 UseListConstIteratorWrapper() {}
117 UseListConstIteratorWrapper(const Super &RHS) : Super(RHS) {}
119 // Allow conversion from non-const to const iterators
120 UseListConstIteratorWrapper(const UseListIteratorWrapper &RHS) : Super(RHS) {}
121 UseListConstIteratorWrapper(const iplist<Use>::iterator &RHS) : Super(RHS) {}
123 UseListConstIteratorWrapper &operator=(const Super &RHS) {
124 Super::operator=(RHS);
128 inline const User *operator*() const;
129 const User *operator->() const { return operator*(); }
131 UseListConstIteratorWrapper operator--() { return Super::operator--(); }
132 UseListConstIteratorWrapper operator++() { return Super::operator++(); }
134 UseListConstIteratorWrapper operator--(int) { // postdecrement operators...
135 UseListConstIteratorWrapper tmp = *this;
139 UseListConstIteratorWrapper operator++(int) { // postincrement operators...
140 UseListConstIteratorWrapper tmp = *this;