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 "llvm/ADT/ilist"
23 template<typename NodeTy> struct ilist_traits;
28 //===----------------------------------------------------------------------===//
30 //===----------------------------------------------------------------------===//
32 // Use is here to make keeping the "use" list of a Value up-to-date really easy.
38 friend struct ilist_traits<Use>;
40 inline Use(Value *v, User *user);
41 inline Use(const Use &u);
44 operator Value*() const { return Val; }
45 Value *get() const { return Val; }
46 User *getUser() const { return U; }
48 inline void set(Value *Val);
50 Value *operator=(Value *RHS) {
54 const Use &operator=(const Use &RHS) {
59 Value *operator->() { return Val; }
60 const Value *operator->() const { return Val; }
64 struct ilist_traits<Use> {
65 static Use *getPrev(Use *N) { return N->Prev; }
66 static Use *getNext(Use *N) { return N->Next; }
67 static const Use *getPrev(const Use *N) { return N->Prev; }
68 static const Use *getNext(const Use *N) { return N->Next; }
69 static void setPrev(Use *N, Use *Prev) { N->Prev = Prev; }
70 static void setNext(Use *N, Use *Next) { N->Next = Next; }
72 // createNode - this is used to create the end marker for the use list
73 static Use *createNode() { return new Use(0,0); }
75 void addNodeToList(Use *NTy) {}
76 void removeNodeFromList(Use *NTy) {}
77 void transferNodesFromList(iplist<Use, ilist_traits> &L2,
78 ilist_iterator<Use> first,
79 ilist_iterator<Use> last) {}
83 template<> struct simplify_type<Use> {
84 typedef Value* SimpleType;
85 static SimpleType getSimplifiedValue(const Use &Val) {
86 return static_cast<SimpleType>(Val.get());
89 template<> struct simplify_type<const Use> {
90 typedef Value* SimpleType;
91 static SimpleType getSimplifiedValue(const Use &Val) {
92 return static_cast<SimpleType>(Val.get());
96 struct UseListIteratorWrapper : public iplist<Use>::iterator {
97 typedef iplist<Use>::iterator Super;
98 UseListIteratorWrapper() {}
99 UseListIteratorWrapper(const Super &RHS) : Super(RHS) {}
101 UseListIteratorWrapper &operator=(const Super &RHS) {
102 Super::operator=(RHS);
106 inline User *operator*() const;
107 User *operator->() const { return operator*(); }
109 UseListIteratorWrapper operator--() { return Super::operator--(); }
110 UseListIteratorWrapper operator++() { return Super::operator++(); }
112 UseListIteratorWrapper operator--(int) { // postdecrement operators...
113 UseListIteratorWrapper tmp = *this;
117 UseListIteratorWrapper operator++(int) { // postincrement operators...
118 UseListIteratorWrapper tmp = *this;
124 struct UseListConstIteratorWrapper : public iplist<Use>::const_iterator {
125 typedef iplist<Use>::const_iterator Super;
126 UseListConstIteratorWrapper() {}
127 UseListConstIteratorWrapper(const Super &RHS) : Super(RHS) {}
129 // Allow conversion from non-const to const iterators
130 UseListConstIteratorWrapper(const UseListIteratorWrapper &RHS) : Super(RHS) {}
131 UseListConstIteratorWrapper(const iplist<Use>::iterator &RHS) : Super(RHS) {}
133 UseListConstIteratorWrapper &operator=(const Super &RHS) {
134 Super::operator=(RHS);
138 inline const User *operator*() const;
139 const User *operator->() const { return operator*(); }
141 UseListConstIteratorWrapper operator--() { return Super::operator--(); }
142 UseListConstIteratorWrapper operator++() { return Super::operator++(); }
144 UseListConstIteratorWrapper operator--(int) { // postdecrement operators...
145 UseListConstIteratorWrapper tmp = *this;
149 UseListConstIteratorWrapper operator++(int) { // postincrement operators...
150 UseListConstIteratorWrapper tmp = *this;
156 } // End llvm namespace