1 //===-- llvm/Use.h - Definition of the Use class ----------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This defines the Use class. The Use class represents the operand of an
11 // instruction or some other User instance which refers to a Value. The Use
12 // class keeps the "use list" of the referenced value up to date.
14 //===----------------------------------------------------------------------===//
19 #include "Support/ilist"
20 template<typename NodeTy> struct ilist_traits;
25 //===----------------------------------------------------------------------===//
27 //===----------------------------------------------------------------------===//
29 // Use is here to make keeping the "use" list of a Value up-to-date really easy.
35 friend class ilist_traits<Use>;
37 inline Use(Value *v, User *user);
38 inline Use(const Use &u);
41 operator Value*() const { return Val; }
42 Value *get() const { return Val; }
43 User *getUser() const { return U; }
45 inline void set(Value *Val);
47 Value *operator=(Value *RHS) {
51 const Use &operator=(const Use &RHS) {
56 Value *operator->() { return Val; }
57 const Value *operator->() const { return Val; }
61 struct ilist_traits<Use> {
62 static Use *getPrev(Use *N) { return N->Prev; }
63 static Use *getNext(Use *N) { return N->Next; }
64 static const Use *getPrev(const Use *N) { return N->Prev; }
65 static const Use *getNext(const Use *N) { return N->Next; }
66 static void setPrev(Use *N, Use *Prev) { N->Prev = Prev; }
67 static void setNext(Use *N, Use *Next) { N->Next = Next; }
69 // createNode - this is used to create the end marker for the use list
70 static Use *createNode() { return new Use(0,0); }
72 void addNodeToList(Use *NTy) {}
73 void removeNodeFromList(Use *NTy) {}
74 void transferNodesFromList(iplist<Use, ilist_traits> &L2,
75 ilist_iterator<Use> first,
76 ilist_iterator<Use> last) {}
80 template<> struct simplify_type<Use> {
81 typedef Value* SimpleType;
82 static SimpleType getSimplifiedValue(const Use &Val) {
83 return (SimpleType)Val.get();
86 template<> struct simplify_type<const Use> {
87 typedef Value* SimpleType;
88 static SimpleType getSimplifiedValue(const Use &Val) {
89 return (SimpleType)Val.get();
93 struct UseListIteratorWrapper : public iplist<Use>::iterator {
94 typedef iplist<Use>::iterator Super;
95 UseListIteratorWrapper() {}
96 UseListIteratorWrapper(const Super &RHS) : Super(RHS) {}
98 UseListIteratorWrapper &operator=(const Super &RHS) {
99 Super::operator=(RHS);
103 inline User *operator*() const;
104 User *operator->() const { return operator*(); }
106 UseListIteratorWrapper operator--() { return Super::operator--(); }
107 UseListIteratorWrapper operator++() { return Super::operator++(); }
109 UseListIteratorWrapper operator--(int) { // postdecrement operators...
110 UseListIteratorWrapper tmp = *this;
114 UseListIteratorWrapper operator++(int) { // postincrement operators...
115 UseListIteratorWrapper tmp = *this;
121 struct UseListConstIteratorWrapper : public iplist<Use>::const_iterator {
122 typedef iplist<Use>::const_iterator Super;
123 UseListConstIteratorWrapper() {}
124 UseListConstIteratorWrapper(const Super &RHS) : Super(RHS) {}
126 // Allow conversion from non-const to const iterators
127 UseListConstIteratorWrapper(const UseListIteratorWrapper &RHS) : Super(RHS) {}
128 UseListConstIteratorWrapper(const iplist<Use>::iterator &RHS) : Super(RHS) {}
130 UseListConstIteratorWrapper &operator=(const Super &RHS) {
131 Super::operator=(RHS);
135 inline const User *operator*() const;
136 const User *operator->() const { return operator*(); }
138 UseListConstIteratorWrapper operator--() { return Super::operator--(); }
139 UseListConstIteratorWrapper operator++() { return Super::operator++(); }
141 UseListConstIteratorWrapper operator--(int) { // postdecrement operators...
142 UseListConstIteratorWrapper tmp = *this;
146 UseListConstIteratorWrapper operator++(int) { // postincrement operators...
147 UseListConstIteratorWrapper tmp = *this;