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