llvm.org GIT mirror llvm / 7225e27
[Modules] Move ValueMap to the IR library. While this class does not directly care about the Value class (it is templated so that the key can be any arbitrary Value subclass), it is in fact concretely tied to the Value class through the ValueHandle's CallbackVH interface which relies on the key type being some Value subclass to establish the value handle chain. Ironically, the unittest is already in the right library. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@202824 91177308-0d34-0410-b5e6-96231b3b80d8 Chandler Carruth 5 years ago
16 changed file(s) with 391 addition(s) and 391 deletion(s). Raw diff Collapse all Expand all
13171317
13181318 .. _dss_valuemap:
13191319
1320 llvm/ADT/ValueMap.h
1320 llvm/IR/ValueMap.h
13211321 ^^^^^^^^^^^^^^^^^^^
13221322
13231323 ValueMap is a wrapper around a :ref:`DenseMap ` mapping
+0
-377
include/llvm/ADT/ValueMap.h less more
None //===- llvm/ADT/ValueMap.h - Safe map from Values to data -------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines the ValueMap class. ValueMap maps Value* or any subclass
10 // to an arbitrary other type. It provides the DenseMap interface but updates
11 // itself to remain safe when keys are RAUWed or deleted. By default, when a
12 // key is RAUWed from V1 to V2, the old mapping V1->target is removed, and a new
13 // mapping V2->target is added. If V2 already existed, its old target is
14 // overwritten. When a key is deleted, its mapping is removed.
15 //
16 // You can override a ValueMap's Config parameter to control exactly what
17 // happens on RAUW and destruction and to get called back on each event. It's
18 // legal to call back into the ValueMap from a Config's callbacks. Config
19 // parameters should inherit from ValueMapConfig to get default
20 // implementations of all the methods ValueMap uses. See ValueMapConfig for
21 // documentation of the functions you can override.
22 //
23 //===----------------------------------------------------------------------===//
24
25 #ifndef LLVM_ADT_VALUEMAP_H
26 #define LLVM_ADT_VALUEMAP_H
27
28 #include "llvm/ADT/DenseMap.h"
29 #include "llvm/IR/ValueHandle.h"
30 #include "llvm/Support/Mutex.h"
31 #include "llvm/Support/type_traits.h"
32 #include
33
34 namespace llvm {
35
36 template
37 class ValueMapCallbackVH;
38
39 template
40 class ValueMapIterator;
41 template
42 class ValueMapConstIterator;
43
44 /// This class defines the default behavior for configurable aspects of
45 /// ValueMap<>. User Configs should inherit from this class to be as compatible
46 /// as possible with future versions of ValueMap.
47 template
48 struct ValueMapConfig {
49 /// If FollowRAUW is true, the ValueMap will update mappings on RAUW. If it's
50 /// false, the ValueMap will leave the original mapping in place.
51 enum { FollowRAUW = true };
52
53 // All methods will be called with a first argument of type ExtraData. The
54 // default implementations in this class take a templated first argument so
55 // that users' subclasses can use any type they want without having to
56 // override all the defaults.
57 struct ExtraData {};
58
59 template
60 static void onRAUW(const ExtraDataT & /*Data*/, KeyT /*Old*/, KeyT /*New*/) {}
61 template
62 static void onDelete(const ExtraDataT &/*Data*/, KeyT /*Old*/) {}
63
64 /// Returns a mutex that should be acquired around any changes to the map.
65 /// This is only acquired from the CallbackVH (and held around calls to onRAUW
66 /// and onDelete) and not inside other ValueMap methods. NULL means that no
67 /// mutex is necessary.
68 template
69 static sys::Mutex *getMutex(const ExtraDataT &/*Data*/) { return NULL; }
70 };
71
72 /// See the file comment.
73 template >
74 class ValueMap {
75 friend class ValueMapCallbackVH;
76 typedef ValueMapCallbackVH ValueMapCVH;
77 typedef DenseMap > MapT;
78 typedef typename Config::ExtraData ExtraData;
79 MapT Map;
80 ExtraData Data;
81 ValueMap(const ValueMap&) LLVM_DELETED_FUNCTION;
82 ValueMap& operator=(const ValueMap&) LLVM_DELETED_FUNCTION;
83 public:
84 typedef KeyT key_type;
85 typedef ValueT mapped_type;
86 typedef std::pair value_type;
87
88 explicit ValueMap(unsigned NumInitBuckets = 64)
89 : Map(NumInitBuckets), Data() {}
90 explicit ValueMap(const ExtraData &Data, unsigned NumInitBuckets = 64)
91 : Map(NumInitBuckets), Data(Data) {}
92
93 ~ValueMap() {}
94
95 typedef ValueMapIterator iterator;
96 typedef ValueMapConstIterator const_iterator;
97 inline iterator begin() { return iterator(Map.begin()); }
98 inline iterator end() { return iterator(Map.end()); }
99 inline const_iterator begin() const { return const_iterator(Map.begin()); }
100 inline const_iterator end() const { return const_iterator(Map.end()); }
101
102 bool empty() const { return Map.empty(); }
103 unsigned size() const { return Map.size(); }
104
105 /// Grow the map so that it has at least Size buckets. Does not shrink
106 void resize(size_t Size) { Map.resize(Size); }
107
108 void clear() { Map.clear(); }
109
110 /// count - Return true if the specified key is in the map.
111 bool count(const KeyT &Val) const {
112 return Map.find_as(Val) != Map.end();
113 }
114
115 iterator find(const KeyT &Val) {
116 return iterator(Map.find_as(Val));
117 }
118 const_iterator find(const KeyT &Val) const {
119 return const_iterator(Map.find_as(Val));
120 }
121
122 /// lookup - Return the entry for the specified key, or a default
123 /// constructed value if no such entry exists.
124 ValueT lookup(const KeyT &Val) const {
125 typename MapT::const_iterator I = Map.find_as(Val);
126 return I != Map.end() ? I->second : ValueT();
127 }
128
129 // Inserts key,value pair into the map if the key isn't already in the map.
130 // If the key is already in the map, it returns false and doesn't update the
131 // value.
132 std::pair insert(const std::pair &KV) {
133 std::pair map_result=
134 Map.insert(std::make_pair(Wrap(KV.first), KV.second));
135 return std::make_pair(iterator(map_result.first), map_result.second);
136 }
137
138 /// insert - Range insertion of pairs.
139 template
140 void insert(InputIt I, InputIt E) {
141 for (; I != E; ++I)
142 insert(*I);
143 }
144
145
146 bool erase(const KeyT &Val) {
147 typename MapT::iterator I = Map.find_as(Val);
148 if (I == Map.end())
149 return false;
150
151 Map.erase(I);
152 return true;
153 }
154 void erase(iterator I) {
155 return Map.erase(I.base());
156 }
157
158 value_type& FindAndConstruct(const KeyT &Key) {
159 return Map.FindAndConstruct(Wrap(Key));
160 }
161
162 ValueT &operator[](const KeyT &Key) {
163 return Map[Wrap(Key)];
164 }
165
166 /// isPointerIntoBucketsArray - Return true if the specified pointer points
167 /// somewhere into the ValueMap's array of buckets (i.e. either to a key or
168 /// value in the ValueMap).
169 bool isPointerIntoBucketsArray(const void *Ptr) const {
170 return Map.isPointerIntoBucketsArray(Ptr);
171 }
172
173 /// getPointerIntoBucketsArray() - Return an opaque pointer into the buckets
174 /// array. In conjunction with the previous method, this can be used to
175 /// determine whether an insertion caused the ValueMap to reallocate.
176 const void *getPointerIntoBucketsArray() const {
177 return Map.getPointerIntoBucketsArray();
178 }
179
180 private:
181 // Takes a key being looked up in the map and wraps it into a
182 // ValueMapCallbackVH, the actual key type of the map. We use a helper
183 // function because ValueMapCVH is constructed with a second parameter.
184 ValueMapCVH Wrap(KeyT key) const {
185 // The only way the resulting CallbackVH could try to modify *this (making
186 // the const_cast incorrect) is if it gets inserted into the map. But then
187 // this function must have been called from a non-const method, making the
188 // const_cast ok.
189 return ValueMapCVH(key, const_cast(this));
190 }
191 };
192
193 // This CallbackVH updates its ValueMap when the contained Value changes,
194 // according to the user's preferences expressed through the Config object.
195 template
196 class ValueMapCallbackVH : public CallbackVH {
197 friend class ValueMap;
198 friend struct DenseMapInfo;
199 typedef ValueMap ValueMapT;
200 typedef typename llvm::remove_pointer::type KeySansPointerT;
201
202 ValueMapT *Map;
203
204 ValueMapCallbackVH(KeyT Key, ValueMapT *Map)
205 : CallbackVH(const_cast(static_cast(Key))),
206 Map(Map) {}
207
208 public:
209 KeyT Unwrap() const { return cast_or_null(getValPtr()); }
210
211 virtual void deleted() {
212 // Make a copy that won't get changed even when *this is destroyed.
213 ValueMapCallbackVH Copy(*this);
214 sys::Mutex *M = Config::getMutex(Copy.Map->Data);
215 if (M)
216 M->acquire();
217 Config::onDelete(Copy.Map->Data, Copy.Unwrap()); // May destroy *this.
218 Copy.Map->Map.erase(Copy); // Definitely destroys *this.
219 if (M)
220 M->release();
221 }
222 virtual void allUsesReplacedWith(Value *new_key) {
223 assert(isa(new_key) &&
224 "Invalid RAUW on key of ValueMap<>");
225 // Make a copy that won't get changed even when *this is destroyed.
226 ValueMapCallbackVH Copy(*this);
227 sys::Mutex *M = Config::getMutex(Copy.Map->Data);
228 if (M)
229 M->acquire();
230
231 KeyT typed_new_key = cast(new_key);
232 // Can destroy *this:
233 Config::onRAUW(Copy.Map->Data, Copy.Unwrap(), typed_new_key);
234 if (Config::FollowRAUW) {
235 typename ValueMapT::MapT::iterator I = Copy.Map->Map.find(Copy);
236 // I could == Copy.Map->Map.end() if the onRAUW callback already
237 // removed the old mapping.
238 if (I != Copy.Map->Map.end()) {
239 ValueT Target(I->second);
240 Copy.Map->Map.erase(I); // Definitely destroys *this.
241 Copy.Map->insert(std::make_pair(typed_new_key, Target));
242 }
243 }
244 if (M)
245 M->release();
246 }
247 };
248
249 template
250 struct DenseMapInfo > {
251 typedef ValueMapCallbackVH VH;
252 typedef DenseMapInfo PointerInfo;
253
254 static inline VH getEmptyKey() {
255 return VH(PointerInfo::getEmptyKey(), NULL);
256 }
257 static inline VH getTombstoneKey() {
258 return VH(PointerInfo::getTombstoneKey(), NULL);
259 }
260 static unsigned getHashValue(const VH &Val) {
261 return PointerInfo::getHashValue(Val.Unwrap());
262 }
263 static unsigned getHashValue(const KeyT &Val) {
264 return PointerInfo::getHashValue(Val);
265 }
266 static bool isEqual(const VH &LHS, const VH &RHS) {
267 return LHS == RHS;
268 }
269 static bool isEqual(const KeyT &LHS, const VH &RHS) {
270 return LHS == RHS.getValPtr();
271 }
272 };
273
274
275 template
276 class ValueMapIterator :
277 public std::iterator
278 std::pair,
279 ptrdiff_t> {
280 typedef typename DenseMapT::iterator BaseT;
281 typedef typename DenseMapT::mapped_type ValueT;
282 BaseT I;
283 public:
284 ValueMapIterator() : I() {}
285
286 ValueMapIterator(BaseT I) : I(I) {}
287
288 BaseT base() const { return I; }
289
290 struct ValueTypeProxy {
291 const KeyT first;
292 ValueT& second;
293 ValueTypeProxy *operator->() { return this; }
294 operator std::pair() const {
295 return std::make_pair(first, second);
296 }
297 };
298
299 ValueTypeProxy operator*() const {
300 ValueTypeProxy Result = {I->first.Unwrap(), I->second};
301 return Result;
302 }
303
304 ValueTypeProxy operator->() const {
305 return operator*();
306 }
307
308 bool operator==(const ValueMapIterator &RHS) const {
309 return I == RHS.I;
310 }
311 bool operator!=(const ValueMapIterator &RHS) const {
312 return I != RHS.I;
313 }
314
315 inline ValueMapIterator& operator++() { // Preincrement
316 ++I;
317 return *this;
318 }
319 ValueMapIterator operator++(int) { // Postincrement
320 ValueMapIterator tmp = *this; ++*this; return tmp;
321 }
322 };
323
324 template
325 class ValueMapConstIterator :
326 public std::iterator
327 std::pair,
328 ptrdiff_t> {
329 typedef typename DenseMapT::const_iterator BaseT;
330 typedef typename DenseMapT::mapped_type ValueT;
331 BaseT I;
332 public:
333 ValueMapConstIterator() : I() {}
334 ValueMapConstIterator(BaseT I) : I(I) {}
335 ValueMapConstIterator(ValueMapIterator Other)
336 : I(Other.base()) {}
337
338 BaseT base() const { return I; }
339
340 struct ValueTypeProxy {
341 const KeyT first;
342 const ValueT& second;
343 ValueTypeProxy *operator->() { return this; }
344 operator std::pair() const {
345 return std::make_pair(first, second);
346 }
347 };
348
349 ValueTypeProxy operator*() const {
350 ValueTypeProxy Result = {I->first.Unwrap(), I->second};
351 return Result;
352 }
353
354 ValueTypeProxy operator->() const {
355 return operator*();
356 }
357
358 bool operator==(const ValueMapConstIterator &RHS) const {
359 return I == RHS.I;
360 }
361 bool operator!=(const ValueMapConstIterator &RHS) const {
362 return I != RHS.I;
363 }
364
365 inline ValueMapConstIterator& operator++() { // Preincrement
366 ++I;
367 return *this;
368 }
369 ValueMapConstIterator operator++(int) { // Postincrement
370 ValueMapConstIterator tmp = *this; ++*this; return tmp;
371 }
372 };
373
374 } // end namespace llvm
375
376 #endif
1818
1919 #include "llvm/ADT/SmallPtrSet.h"
2020 #include "llvm/ADT/Triple.h"
21 #include "llvm/ADT/ValueMap.h"
2221 #include "llvm/IR/Dominators.h"
22 #include "llvm/IR/ValueMap.h"
2323 #include "llvm/Pass.h"
2424 #include "llvm/Target/TargetLowering.h"
2525
1717 #include "llvm-c/ExecutionEngine.h"
1818 #include "llvm/ADT/SmallVector.h"
1919 #include "llvm/ADT/StringRef.h"
20 #include "llvm/ADT/ValueMap.h"
2120 #include "llvm/IR/ValueHandle.h"
21 #include "llvm/IR/ValueMap.h"
2222 #include "llvm/MC/MCCodeGenInfo.h"
2323 #include "llvm/Support/ErrorHandling.h"
2424 #include "llvm/Support/Mutex.h"
0 //===- ValueMap.h - Safe map from Values to data ----------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines the ValueMap class. ValueMap maps Value* or any subclass
10 // to an arbitrary other type. It provides the DenseMap interface but updates
11 // itself to remain safe when keys are RAUWed or deleted. By default, when a
12 // key is RAUWed from V1 to V2, the old mapping V1->target is removed, and a new
13 // mapping V2->target is added. If V2 already existed, its old target is
14 // overwritten. When a key is deleted, its mapping is removed.
15 //
16 // You can override a ValueMap's Config parameter to control exactly what
17 // happens on RAUW and destruction and to get called back on each event. It's
18 // legal to call back into the ValueMap from a Config's callbacks. Config
19 // parameters should inherit from ValueMapConfig to get default
20 // implementations of all the methods ValueMap uses. See ValueMapConfig for
21 // documentation of the functions you can override.
22 //
23 //===----------------------------------------------------------------------===//
24
25 #ifndef LLVM_IR_VALUEMAP_H
26 #define LLVM_IR_VALUEMAP_H
27
28 #include "llvm/ADT/DenseMap.h"
29 #include "llvm/IR/ValueHandle.h"
30 #include "llvm/Support/Mutex.h"
31 #include "llvm/Support/type_traits.h"
32 #include
33
34 namespace llvm {
35
36 template
37 class ValueMapCallbackVH;
38
39 template
40 class ValueMapIterator;
41 template
42 class ValueMapConstIterator;
43
44 /// This class defines the default behavior for configurable aspects of
45 /// ValueMap<>. User Configs should inherit from this class to be as compatible
46 /// as possible with future versions of ValueMap.
47 template
48 struct ValueMapConfig {
49 /// If FollowRAUW is true, the ValueMap will update mappings on RAUW. If it's
50 /// false, the ValueMap will leave the original mapping in place.
51 enum { FollowRAUW = true };
52
53 // All methods will be called with a first argument of type ExtraData. The
54 // default implementations in this class take a templated first argument so
55 // that users' subclasses can use any type they want without having to
56 // override all the defaults.
57 struct ExtraData {};
58
59 template
60 static void onRAUW(const ExtraDataT & /*Data*/, KeyT /*Old*/, KeyT /*New*/) {}
61 template
62 static void onDelete(const ExtraDataT &/*Data*/, KeyT /*Old*/) {}
63
64 /// Returns a mutex that should be acquired around any changes to the map.
65 /// This is only acquired from the CallbackVH (and held around calls to onRAUW
66 /// and onDelete) and not inside other ValueMap methods. NULL means that no
67 /// mutex is necessary.
68 template
69 static sys::Mutex *getMutex(const ExtraDataT &/*Data*/) { return NULL; }
70 };
71
72 /// See the file comment.
73 template >
74 class ValueMap {
75 friend class ValueMapCallbackVH;
76 typedef ValueMapCallbackVH ValueMapCVH;
77 typedef DenseMap > MapT;
78 typedef typename Config::ExtraData ExtraData;
79 MapT Map;
80 ExtraData Data;
81 ValueMap(const ValueMap&) LLVM_DELETED_FUNCTION;
82 ValueMap& operator=(const ValueMap&) LLVM_DELETED_FUNCTION;
83 public:
84 typedef KeyT key_type;
85 typedef ValueT mapped_type;
86 typedef std::pair value_type;
87
88 explicit ValueMap(unsigned NumInitBuckets = 64)
89 : Map(NumInitBuckets), Data() {}
90 explicit ValueMap(const ExtraData &Data, unsigned NumInitBuckets = 64)
91 : Map(NumInitBuckets), Data(Data) {}
92
93 ~ValueMap() {}
94
95 typedef ValueMapIterator iterator;
96 typedef ValueMapConstIterator const_iterator;
97 inline iterator begin() { return iterator(Map.begin()); }
98 inline iterator end() { return iterator(Map.end()); }
99 inline const_iterator begin() const { return const_iterator(Map.begin()); }
100 inline const_iterator end() const { return const_iterator(Map.end()); }
101
102 bool empty() const { return Map.empty(); }
103 unsigned size() const { return Map.size(); }
104
105 /// Grow the map so that it has at least Size buckets. Does not shrink
106 void resize(size_t Size) { Map.resize(Size); }
107
108 void clear() { Map.clear(); }
109
110 /// count - Return true if the specified key is in the map.
111 bool count(const KeyT &Val) const {
112 return Map.find_as(Val) != Map.end();
113 }
114
115 iterator find(const KeyT &Val) {
116 return iterator(Map.find_as(Val));
117 }
118 const_iterator find(const KeyT &Val) const {
119 return const_iterator(Map.find_as(Val));
120 }
121
122 /// lookup - Return the entry for the specified key, or a default
123 /// constructed value if no such entry exists.
124 ValueT lookup(const KeyT &Val) const {
125 typename MapT::const_iterator I = Map.find_as(Val);
126 return I != Map.end() ? I->second : ValueT();
127 }
128
129 // Inserts key,value pair into the map if the key isn't already in the map.
130 // If the key is already in the map, it returns false and doesn't update the
131 // value.
132 std::pair insert(const std::pair &KV) {
133 std::pair map_result=
134 Map.insert(std::make_pair(Wrap(KV.first), KV.second));
135 return std::make_pair(iterator(map_result.first), map_result.second);
136 }
137
138 /// insert - Range insertion of pairs.
139 template
140 void insert(InputIt I, InputIt E) {
141 for (; I != E; ++I)
142 insert(*I);
143 }
144
145
146 bool erase(const KeyT &Val) {
147 typename MapT::iterator I = Map.find_as(Val);
148 if (I == Map.end())
149 return false;
150
151 Map.erase(I);
152 return true;
153 }
154 void erase(iterator I) {
155 return Map.erase(I.base());
156 }
157
158 value_type& FindAndConstruct(const KeyT &Key) {
159 return Map.FindAndConstruct(Wrap(Key));
160 }
161
162 ValueT &operator[](const KeyT &Key) {
163 return Map[Wrap(Key)];
164 }
165
166 /// isPointerIntoBucketsArray - Return true if the specified pointer points
167 /// somewhere into the ValueMap's array of buckets (i.e. either to a key or
168 /// value in the ValueMap).
169 bool isPointerIntoBucketsArray(const void *Ptr) const {
170 return Map.isPointerIntoBucketsArray(Ptr);
171 }
172
173 /// getPointerIntoBucketsArray() - Return an opaque pointer into the buckets
174 /// array. In conjunction with the previous method, this can be used to
175 /// determine whether an insertion caused the ValueMap to reallocate.
176 const void *getPointerIntoBucketsArray() const {
177 return Map.getPointerIntoBucketsArray();
178 }
179
180 private:
181 // Takes a key being looked up in the map and wraps it into a
182 // ValueMapCallbackVH, the actual key type of the map. We use a helper
183 // function because ValueMapCVH is constructed with a second parameter.
184 ValueMapCVH Wrap(KeyT key) const {
185 // The only way the resulting CallbackVH could try to modify *this (making
186 // the const_cast incorrect) is if it gets inserted into the map. But then
187 // this function must have been called from a non-const method, making the
188 // const_cast ok.
189 return ValueMapCVH(key, const_cast(this));
190 }
191 };
192
193 // This CallbackVH updates its ValueMap when the contained Value changes,
194 // according to the user's preferences expressed through the Config object.
195 template
196 class ValueMapCallbackVH : public CallbackVH {
197 friend class ValueMap;
198 friend struct DenseMapInfo;
199 typedef ValueMap ValueMapT;
200 typedef typename llvm::remove_pointer::type KeySansPointerT;
201
202 ValueMapT *Map;
203
204 ValueMapCallbackVH(KeyT Key, ValueMapT *Map)
205 : CallbackVH(const_cast(static_cast(Key))),
206 Map(Map) {}
207
208 public:
209 KeyT Unwrap() const { return cast_or_null(getValPtr()); }
210
211 virtual void deleted() {
212 // Make a copy that won't get changed even when *this is destroyed.
213 ValueMapCallbackVH Copy(*this);
214 sys::Mutex *M = Config::getMutex(Copy.Map->Data);
215 if (M)
216 M->acquire();
217 Config::onDelete(Copy.Map->Data, Copy.Unwrap()); // May destroy *this.
218 Copy.Map->Map.erase(Copy); // Definitely destroys *this.
219 if (M)
220 M->release();
221 }
222 virtual void allUsesReplacedWith(Value *new_key) {
223 assert(isa(new_key) &&
224 "Invalid RAUW on key of ValueMap<>");
225 // Make a copy that won't get changed even when *this is destroyed.
226 ValueMapCallbackVH Copy(*this);
227 sys::Mutex *M = Config::getMutex(Copy.Map->Data);
228 if (M)
229 M->acquire();
230
231 KeyT typed_new_key = cast(new_key);
232 // Can destroy *this:
233 Config::onRAUW(Copy.Map->Data, Copy.Unwrap(), typed_new_key);
234 if (Config::FollowRAUW) {
235 typename ValueMapT::MapT::iterator I = Copy.Map->Map.find(Copy);
236 // I could == Copy.Map->Map.end() if the onRAUW callback already
237 // removed the old mapping.
238 if (I != Copy.Map->Map.end()) {
239 ValueT Target(I->second);
240 Copy.Map->Map.erase(I); // Definitely destroys *this.
241 Copy.Map->insert(std::make_pair(typed_new_key, Target));
242 }
243 }
244 if (M)
245 M->release();
246 }
247 };
248
249 template
250 struct DenseMapInfo > {
251 typedef ValueMapCallbackVH VH;
252 typedef DenseMapInfo PointerInfo;
253
254 static inline VH getEmptyKey() {
255 return VH(PointerInfo::getEmptyKey(), NULL);
256 }
257 static inline VH getTombstoneKey() {
258 return VH(PointerInfo::getTombstoneKey(), NULL);
259 }
260 static unsigned getHashValue(const VH &Val) {
261 return PointerInfo::getHashValue(Val.Unwrap());
262 }
263 static unsigned getHashValue(const KeyT &Val) {
264 return PointerInfo::getHashValue(Val);
265 }
266 static bool isEqual(const VH &LHS, const VH &RHS) {
267 return LHS == RHS;
268 }
269 static bool isEqual(const KeyT &LHS, const VH &RHS) {
270 return LHS == RHS.getValPtr();
271 }
272 };
273
274
275 template
276 class ValueMapIterator :
277 public std::iterator
278 std::pair,
279 ptrdiff_t> {
280 typedef typename DenseMapT::iterator BaseT;
281 typedef typename DenseMapT::mapped_type ValueT;
282 BaseT I;
283 public:
284 ValueMapIterator() : I() {}
285
286 ValueMapIterator(BaseT I) : I(I) {}
287
288 BaseT base() const { return I; }
289
290 struct ValueTypeProxy {
291 const KeyT first;
292 ValueT& second;
293 ValueTypeProxy *operator->() { return this; }
294 operator std::pair() const {
295 return std::make_pair(first, second);
296 }
297 };
298
299 ValueTypeProxy operator*() const {
300 ValueTypeProxy Result = {I->first.Unwrap(), I->second};
301 return Result;
302 }
303
304 ValueTypeProxy operator->() const {
305 return operator*();
306 }
307
308 bool operator==(const ValueMapIterator &RHS) const {
309 return I == RHS.I;
310 }
311 bool operator!=(const ValueMapIterator &RHS) const {
312 return I != RHS.I;
313 }
314
315 inline ValueMapIterator& operator++() { // Preincrement
316 ++I;
317 return *this;
318 }
319 ValueMapIterator operator++(int) { // Postincrement
320 ValueMapIterator tmp = *this; ++*this; return tmp;
321 }
322 };
323
324 template
325 class ValueMapConstIterator :
326 public std::iterator
327 std::pair,
328 ptrdiff_t> {
329 typedef typename DenseMapT::const_iterator BaseT;
330 typedef typename DenseMapT::mapped_type ValueT;
331 BaseT I;
332 public:
333 ValueMapConstIterator() : I() {}
334 ValueMapConstIterator(BaseT I) : I(I) {}
335 ValueMapConstIterator(ValueMapIterator Other)
336 : I(Other.base()) {}
337
338 BaseT base() const { return I; }
339
340 struct ValueTypeProxy {
341 const KeyT first;
342 const ValueT& second;
343 ValueTypeProxy *operator->() { return this; }
344 operator std::pair() const {
345 return std::make_pair(first, second);
346 }
347 };
348
349 ValueTypeProxy operator*() const {
350 ValueTypeProxy Result = {I->first.Unwrap(), I->second};
351 return Result;
352 }
353
354 ValueTypeProxy operator->() const {
355 return operator*();
356 }
357
358 bool operator==(const ValueMapConstIterator &RHS) const {
359 return I == RHS.I;
360 }
361 bool operator!=(const ValueMapConstIterator &RHS) const {
362 return I != RHS.I;
363 }
364
365 inline ValueMapConstIterator& operator++() { // Preincrement
366 ++I;
367 return *this;
368 }
369 ValueMapConstIterator operator++(int) { // Postincrement
370 ValueMapConstIterator tmp = *this; ++*this; return tmp;
371 }
372 };
373
374 } // end namespace llvm
375
376 #endif
1919
2020 #include "llvm/ADT/SmallVector.h"
2121 #include "llvm/ADT/Twine.h"
22 #include "llvm/ADT/ValueMap.h"
2322 #include "llvm/IR/ValueHandle.h"
23 #include "llvm/IR/ValueMap.h"
2424 #include "llvm/Transforms/Utils/ValueMapper.h"
2525
2626 namespace llvm {
1414 #ifndef LLVM_TRANSFORMS_UTILS_VALUEMAPPER_H
1515 #define LLVM_TRANSFORMS_UTILS_VALUEMAPPER_H
1616
17 #include "llvm/ADT/ValueMap.h"
17 #include "llvm/IR/ValueMap.h"
1818
1919 namespace llvm {
2020 class Value;
1717 #include "llvm/ADT/DenseMap.h"
1818 #include "llvm/ADT/SmallSet.h"
1919 #include "llvm/ADT/Statistic.h"
20 #include "llvm/ADT/ValueMap.h"
2120 #include "llvm/Analysis/InstructionSimplify.h"
2221 #include "llvm/IR/CallSite.h"
2322 #include "llvm/IR/Constants.h"
3231 #include "llvm/IR/IntrinsicInst.h"
3332 #include "llvm/IR/PatternMatch.h"
3433 #include "llvm/IR/ValueHandle.h"
34 #include "llvm/IR/ValueMap.h"
3535 #include "llvm/Pass.h"
3636 #include "llvm/Support/CommandLine.h"
3737 #include "llvm/Support/Debug.h"
1818 #include "llvm/ADT/SmallPtrSet.h"
1919 #include "llvm/ADT/SmallVector.h"
2020 #include "llvm/ADT/Statistic.h"
21 #include "llvm/ADT/ValueMap.h"
2221 #include "llvm/CodeGen/JITCodeEmitter.h"
2322 #include "llvm/CodeGen/MachineCodeInfo.h"
2423 #include "llvm/CodeGen/MachineConstantPool.h"
3534 #include "llvm/IR/DerivedTypes.h"
3635 #include "llvm/IR/Module.h"
3736 #include "llvm/IR/ValueHandle.h"
37 #include "llvm/IR/ValueMap.h"
3838 #include "llvm/Support/Debug.h"
3939 #include "llvm/Support/Disassembler.h"
4040 #include "llvm/Support/ErrorHandling.h"
1616 #include "Mips16HardFloatInfo.h"
1717 #include "MipsSubtarget.h"
1818 #include "llvm/ADT/StringMap.h"
19 #include "llvm/ADT/ValueMap.h"
2019 #include "llvm/CodeGen/MachineFrameInfo.h"
2120 #include "llvm/CodeGen/MachineFunction.h"
2221 #include "llvm/CodeGen/MachineMemOperand.h"
2322 #include "llvm/CodeGen/PseudoSourceValue.h"
2423 #include "llvm/IR/GlobalValue.h"
24 #include "llvm/IR/ValueMap.h"
2525 #include "llvm/Target/TargetFrameLowering.h"
2626 #include "llvm/Target/TargetMachine.h"
2727 #include
1414 #include "NVPTX.h"
1515 #include "MCTargetDesc/NVPTXBaseInfo.h"
1616 #include "NVPTXUtilities.h"
17 #include "llvm/ADT/ValueMap.h"
1817 #include "llvm/CodeGen/MachineFunctionAnalysis.h"
1918 #include "llvm/CodeGen/ValueTypes.h"
2019 #include "llvm/IR/Constants.h"
2423 #include "llvm/IR/Intrinsics.h"
2524 #include "llvm/IR/Module.h"
2625 #include "llvm/IR/Operator.h"
26 #include "llvm/IR/ValueMap.h"
2727 #include "llvm/PassManager.h"
2828
2929 using namespace llvm;
1515 #include "AMDGPURegisterInfo.h"
1616 #include "R600InstrInfo.h"
1717 #include "SIISelLowering.h"
18 #include "llvm/ADT/ValueMap.h"
1918 #include "llvm/Analysis/ValueTracking.h"
2019 #include "llvm/CodeGen/MachineRegisterInfo.h"
2120 #include "llvm/CodeGen/PseudoSourceValue.h"
2221 #include "llvm/CodeGen/SelectionDAG.h"
2322 #include "llvm/CodeGen/SelectionDAGISel.h"
23 #include "llvm/IR/ValueMap.h"
2424 #include "llvm/Support/Compiler.h"
2525 #include
2626 #include
1717
1818 #define DEBUG_TYPE "debug-ir"
1919
20 #include "llvm/ADT/ValueMap.h"
20 #include "llvm/IR/ValueMap.h"
2121 #include "DebugIR.h"
2222 #include "llvm/DIBuilder.h"
2323 #include "llvm/DebugInfo.h"
9999 #include "llvm/ADT/SmallString.h"
100100 #include "llvm/ADT/SmallVector.h"
101101 #include "llvm/ADT/Triple.h"
102 #include "llvm/ADT/ValueMap.h"
103102 #include "llvm/IR/DataLayout.h"
104103 #include "llvm/IR/Function.h"
105104 #include "llvm/IR/IRBuilder.h"
109108 #include "llvm/IR/MDBuilder.h"
110109 #include "llvm/IR/Module.h"
111110 #include "llvm/IR/Type.h"
111 #include "llvm/IR/ValueMap.h"
112112 #include "llvm/InstVisitor.h"
113113 #include "llvm/Support/CommandLine.h"
114114 #include "llvm/Support/Compiler.h"
1515 #ifndef BUGDRIVER_H
1616 #define BUGDRIVER_H
1717
18 #include "llvm/ADT/ValueMap.h"
18 #include "llvm/IR/ValueMap.h"
1919 #include "llvm/Transforms/Utils/ValueMapper.h"
2020 #include
2121 #include
66 //
77 //===----------------------------------------------------------------------===//
88
9 #include "llvm/ADT/ValueMap.h"
9 #include "llvm/IR/ValueMap.h"
1010 #include "llvm/ADT/OwningPtr.h"
1111 #include "llvm/Config/llvm-config.h"
1212 #include "llvm/IR/Constants.h"