Added LLVM copyright header (for lack of a better term).
[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 template<typename NodeTy> struct ilist_traits;
21 class Value;
22 class User;
23
24
25 //===----------------------------------------------------------------------===//
26 //                                  Use Class
27 //===----------------------------------------------------------------------===//
28
29 // Use is here to make keeping the "use" list of a Value up-to-date really easy.
30 //
31 class Use {
32   Value *Val;
33   User *U;
34   Use *Prev, *Next;
35   friend class ilist_traits<Use>;
36 public:
37   inline Use(Value *v, User *user);
38   inline Use(const Use &u);
39   inline ~Use();
40
41   operator Value*() const { return Val; }
42   Value *get() const { return Val; }
43   User *getUser() const { return U; }
44
45   inline void set(Value *Val);
46
47   Value *operator=(Value *RHS) {
48     set(RHS);
49     return RHS;
50   }
51   const Use &operator=(const Use &RHS) {
52     set(RHS.Val);
53     return *this;
54   }
55
56         Value *operator->()       { return Val; }
57   const Value *operator->() const { return Val; }
58 };
59
60 template<>
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; }
68
69   // createNode - this is used to create the end marker for the use list
70   static Use *createNode() { return new Use(0,0); }
71
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) {}
77 };
78
79
80 template<> struct simplify_type<Use> {
81   typedef Value* SimpleType;
82   static SimpleType getSimplifiedValue(const Use &Val) {
83     return (SimpleType)Val.get();
84   }
85 };
86 template<> struct simplify_type<const Use> {
87   typedef Value* SimpleType;
88   static SimpleType getSimplifiedValue(const Use &Val) {
89     return (SimpleType)Val.get();
90   }
91 };
92
93 struct UseListIteratorWrapper : public iplist<Use>::iterator {
94   typedef iplist<Use>::iterator Super;
95   UseListIteratorWrapper() {}
96   UseListIteratorWrapper(const Super &RHS) : Super(RHS) {}
97
98   UseListIteratorWrapper &operator=(const Super &RHS) {
99     Super::operator=(RHS);
100     return *this;
101   }
102
103   inline User *operator*() const;
104   User *operator->() const { return operator*(); }
105
106   UseListIteratorWrapper operator--() { return Super::operator--(); }
107   UseListIteratorWrapper operator++() { return Super::operator++(); }
108
109   UseListIteratorWrapper operator--(int) {    // postdecrement operators...
110     UseListIteratorWrapper tmp = *this;
111     --*this;
112     return tmp;
113   }
114   UseListIteratorWrapper operator++(int) {    // postincrement operators...
115     UseListIteratorWrapper tmp = *this;
116     ++*this;
117     return tmp;
118   }
119 };
120
121 struct UseListConstIteratorWrapper : public iplist<Use>::const_iterator {
122   typedef iplist<Use>::const_iterator Super;
123   UseListConstIteratorWrapper() {}
124   UseListConstIteratorWrapper(const Super &RHS) : Super(RHS) {}
125
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) {}
129
130   UseListConstIteratorWrapper &operator=(const Super &RHS) {
131     Super::operator=(RHS);
132     return *this;
133   }
134
135   inline const User *operator*() const;
136   const User *operator->() const { return operator*(); }
137
138   UseListConstIteratorWrapper operator--() { return Super::operator--(); }
139   UseListConstIteratorWrapper operator++() { return Super::operator++(); }
140
141   UseListConstIteratorWrapper operator--(int) {    // postdecrement operators...
142     UseListConstIteratorWrapper tmp = *this;
143     --*this;
144     return tmp;
145   }
146   UseListConstIteratorWrapper operator++(int) {    // postincrement operators...
147     UseListConstIteratorWrapper tmp = *this;
148     ++*this;
149     return tmp;
150   }
151 };
152
153 #endif