a0f920d2e55adf8a3755d3492900252b7011ab34
[oota-llvm.git] / include / llvm / Use.h
1 //===-- llvm/Use.h - Definition of the Use class ----------------*- C++ -*-===//
2 //
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.
6 //
7 //===----------------------------------------------------------------------===//
8
9 #ifndef LLVM_USE_H
10 #define LLVM_USE_H
11
12 #include "Support/ilist"
13 template<typename NodeTy> struct ilist_traits;
14 class Value;
15 class User;
16
17
18 //===----------------------------------------------------------------------===//
19 //                                  Use Class
20 //===----------------------------------------------------------------------===//
21
22 // Use is here to make keeping the "use" list of a Value up-to-date really easy.
23 //
24 class Use {
25   Value *Val;
26   User *U;
27   Use *Prev, *Next;
28   friend class ilist_traits<Use>;
29 public:
30   inline Use(Value *v, User *user);
31   inline Use(const Use &u);
32   inline ~Use();
33
34   operator Value*() const { return Val; }
35   Value *get() const { return Val; }
36   User *getUser() const { return U; }
37
38   inline void set(Value *Val);
39
40   Value *operator=(Value *RHS) {
41     set(RHS);
42     return RHS;
43   }
44   const Use &operator=(const Use &RHS) {
45     set(RHS.Val);
46     return *this;
47   }
48
49         Value *operator->()       { return Val; }
50   const Value *operator->() const { return Val; }
51 };
52
53 template<>
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; }
61
62   // createNode - this is used to create the end marker for the use list
63   static Use *createNode() { return new Use(0,0); }
64
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) {}
70 };
71
72
73 template<> struct simplify_type<Use> {
74   typedef Value* SimpleType;
75   static SimpleType getSimplifiedValue(const Use &Val) {
76     return (SimpleType)Val.get();
77   }
78 };
79 template<> struct simplify_type<const Use> {
80   typedef Value* SimpleType;
81   static SimpleType getSimplifiedValue(const Use &Val) {
82     return (SimpleType)Val.get();
83   }
84 };
85
86 struct UseListIteratorWrapper : public iplist<Use>::iterator {
87   typedef iplist<Use>::iterator Super;
88   UseListIteratorWrapper() {}
89   UseListIteratorWrapper(const Super &RHS) : Super(RHS) {}
90
91   UseListIteratorWrapper &operator=(const Super &RHS) {
92     Super::operator=(RHS);
93     return *this;
94   }
95
96   inline User *operator*() const;
97   User *operator->() const { return operator*(); }
98
99   UseListIteratorWrapper operator--() { return Super::operator--(); }
100   UseListIteratorWrapper operator++() { return Super::operator++(); }
101
102   UseListIteratorWrapper operator--(int) {    // postdecrement operators...
103     UseListIteratorWrapper tmp = *this;
104     --*this;
105     return tmp;
106   }
107   UseListIteratorWrapper operator++(int) {    // postincrement operators...
108     UseListIteratorWrapper tmp = *this;
109     ++*this;
110     return tmp;
111   }
112 };
113
114 struct UseListConstIteratorWrapper : public iplist<Use>::const_iterator {
115   typedef iplist<Use>::const_iterator Super;
116   UseListConstIteratorWrapper() {}
117   UseListConstIteratorWrapper(const Super &RHS) : Super(RHS) {}
118
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) {}
122
123   UseListConstIteratorWrapper &operator=(const Super &RHS) {
124     Super::operator=(RHS);
125     return *this;
126   }
127
128   inline const User *operator*() const;
129   const User *operator->() const { return operator*(); }
130
131   UseListConstIteratorWrapper operator--() { return Super::operator--(); }
132   UseListConstIteratorWrapper operator++() { return Super::operator++(); }
133
134   UseListConstIteratorWrapper operator--(int) {    // postdecrement operators...
135     UseListConstIteratorWrapper tmp = *this;
136     --*this;
137     return tmp;
138   }
139   UseListConstIteratorWrapper operator++(int) {    // postincrement operators...
140     UseListConstIteratorWrapper tmp = *this;
141     ++*this;
142     return tmp;
143   }
144 };
145
146 #endif