comparison include/llvm/IR/ValueMap.h @ 83:60c9769439b8 LLVM3.7

LLVM 3.7
author Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
date Wed, 18 Feb 2015 14:55:36 +0900
parents 54457678186b
children afa8332a0e37
comparison
equal deleted inserted replaced
78:af83660cff7b 83:60c9769439b8
25 25
26 #ifndef LLVM_IR_VALUEMAP_H 26 #ifndef LLVM_IR_VALUEMAP_H
27 #define LLVM_IR_VALUEMAP_H 27 #define LLVM_IR_VALUEMAP_H
28 28
29 #include "llvm/ADT/DenseMap.h" 29 #include "llvm/ADT/DenseMap.h"
30 #include "llvm/IR/TrackingMDRef.h"
30 #include "llvm/IR/ValueHandle.h" 31 #include "llvm/IR/ValueHandle.h"
31 #include "llvm/Support/Mutex.h" 32 #include "llvm/Support/Mutex.h"
32 #include "llvm/Support/UniqueLock.h" 33 #include "llvm/Support/UniqueLock.h"
33 #include "llvm/Support/type_traits.h" 34 #include "llvm/Support/type_traits.h"
34 #include <iterator> 35 #include <iterator>
36 #include <memory>
35 37
36 namespace llvm { 38 namespace llvm {
37 39
38 template<typename KeyT, typename ValueT, typename Config> 40 template<typename KeyT, typename ValueT, typename Config>
39 class ValueMapCallbackVH; 41 class ValueMapCallbackVH;
77 template<typename KeyT, typename ValueT, typename Config =ValueMapConfig<KeyT> > 79 template<typename KeyT, typename ValueT, typename Config =ValueMapConfig<KeyT> >
78 class ValueMap { 80 class ValueMap {
79 friend class ValueMapCallbackVH<KeyT, ValueT, Config>; 81 friend class ValueMapCallbackVH<KeyT, ValueT, Config>;
80 typedef ValueMapCallbackVH<KeyT, ValueT, Config> ValueMapCVH; 82 typedef ValueMapCallbackVH<KeyT, ValueT, Config> ValueMapCVH;
81 typedef DenseMap<ValueMapCVH, ValueT, DenseMapInfo<ValueMapCVH> > MapT; 83 typedef DenseMap<ValueMapCVH, ValueT, DenseMapInfo<ValueMapCVH> > MapT;
84 typedef DenseMap<const Metadata *, TrackingMDRef> MDMapT;
82 typedef typename Config::ExtraData ExtraData; 85 typedef typename Config::ExtraData ExtraData;
83 MapT Map; 86 MapT Map;
87 std::unique_ptr<MDMapT> MDMap;
84 ExtraData Data; 88 ExtraData Data;
85 ValueMap(const ValueMap&) LLVM_DELETED_FUNCTION; 89 ValueMap(const ValueMap&) = delete;
86 ValueMap& operator=(const ValueMap&) LLVM_DELETED_FUNCTION; 90 ValueMap& operator=(const ValueMap&) = delete;
87 public: 91 public:
88 typedef KeyT key_type; 92 typedef KeyT key_type;
89 typedef ValueT mapped_type; 93 typedef ValueT mapped_type;
90 typedef std::pair<KeyT, ValueT> value_type; 94 typedef std::pair<KeyT, ValueT> value_type;
91 typedef unsigned size_type; 95 typedef unsigned size_type;
92 96
93 explicit ValueMap(unsigned NumInitBuckets = 64) 97 explicit ValueMap(unsigned NumInitBuckets = 64)
94 : Map(NumInitBuckets), Data() {} 98 : Map(NumInitBuckets), Data() {}
95 explicit ValueMap(const ExtraData &Data, unsigned NumInitBuckets = 64) 99 explicit ValueMap(const ExtraData &Data, unsigned NumInitBuckets = 64)
96 : Map(NumInitBuckets), Data(Data) {} 100 : Map(NumInitBuckets), Data(Data) {}
97 101
98 ~ValueMap() {} 102 ~ValueMap() {}
103
104 bool hasMD() const { return MDMap; }
105 MDMapT &MD() {
106 if (!MDMap)
107 MDMap.reset(new MDMapT);
108 return *MDMap;
109 }
99 110
100 typedef ValueMapIterator<MapT, KeyT> iterator; 111 typedef ValueMapIterator<MapT, KeyT> iterator;
101 typedef ValueMapConstIterator<MapT, KeyT> const_iterator; 112 typedef ValueMapConstIterator<MapT, KeyT> const_iterator;
102 inline iterator begin() { return iterator(Map.begin()); } 113 inline iterator begin() { return iterator(Map.begin()); }
103 inline iterator end() { return iterator(Map.end()); } 114 inline iterator end() { return iterator(Map.end()); }
108 size_type size() const { return Map.size(); } 119 size_type size() const { return Map.size(); }
109 120
110 /// Grow the map so that it has at least Size buckets. Does not shrink 121 /// Grow the map so that it has at least Size buckets. Does not shrink
111 void resize(size_t Size) { Map.resize(Size); } 122 void resize(size_t Size) { Map.resize(Size); }
112 123
113 void clear() { Map.clear(); } 124 void clear() {
125 Map.clear();
126 MDMap.reset();
127 }
114 128
115 /// Return 1 if the specified key is in the map, 0 otherwise. 129 /// Return 1 if the specified key is in the map, 0 otherwise.
116 size_type count(const KeyT &Val) const { 130 size_type count(const KeyT &Val) const {
117 return Map.find_as(Val) == Map.end() ? 0 : 1; 131 return Map.find_as(Val) == Map.end() ? 0 : 1;
118 } 132 }
207 ValueMapT *Map; 221 ValueMapT *Map;
208 222
209 ValueMapCallbackVH(KeyT Key, ValueMapT *Map) 223 ValueMapCallbackVH(KeyT Key, ValueMapT *Map)
210 : CallbackVH(const_cast<Value*>(static_cast<const Value*>(Key))), 224 : CallbackVH(const_cast<Value*>(static_cast<const Value*>(Key))),
211 Map(Map) {} 225 Map(Map) {}
226
227 // Private constructor used to create empty/tombstone DenseMap keys.
228 ValueMapCallbackVH(Value *V) : CallbackVH(V), Map(nullptr) {}
212 229
213 public: 230 public:
214 KeyT Unwrap() const { return cast_or_null<KeySansPointerT>(getValPtr()); } 231 KeyT Unwrap() const { return cast_or_null<KeySansPointerT>(getValPtr()); }
215 232
216 void deleted() override { 233 void deleted() override {
250 }; 267 };
251 268
252 template<typename KeyT, typename ValueT, typename Config> 269 template<typename KeyT, typename ValueT, typename Config>
253 struct DenseMapInfo<ValueMapCallbackVH<KeyT, ValueT, Config> > { 270 struct DenseMapInfo<ValueMapCallbackVH<KeyT, ValueT, Config> > {
254 typedef ValueMapCallbackVH<KeyT, ValueT, Config> VH; 271 typedef ValueMapCallbackVH<KeyT, ValueT, Config> VH;
255 typedef DenseMapInfo<KeyT> PointerInfo;
256 272
257 static inline VH getEmptyKey() { 273 static inline VH getEmptyKey() {
258 return VH(PointerInfo::getEmptyKey(), nullptr); 274 return VH(DenseMapInfo<Value *>::getEmptyKey());
259 } 275 }
260 static inline VH getTombstoneKey() { 276 static inline VH getTombstoneKey() {
261 return VH(PointerInfo::getTombstoneKey(), nullptr); 277 return VH(DenseMapInfo<Value *>::getTombstoneKey());
262 } 278 }
263 static unsigned getHashValue(const VH &Val) { 279 static unsigned getHashValue(const VH &Val) {
264 return PointerInfo::getHashValue(Val.Unwrap()); 280 return DenseMapInfo<KeyT>::getHashValue(Val.Unwrap());
265 } 281 }
266 static unsigned getHashValue(const KeyT &Val) { 282 static unsigned getHashValue(const KeyT &Val) {
267 return PointerInfo::getHashValue(Val); 283 return DenseMapInfo<KeyT>::getHashValue(Val);
268 } 284 }
269 static bool isEqual(const VH &LHS, const VH &RHS) { 285 static bool isEqual(const VH &LHS, const VH &RHS) {
270 return LHS == RHS; 286 return LHS == RHS;
271 } 287 }
272 static bool isEqual(const KeyT &LHS, const VH &RHS) { 288 static bool isEqual(const KeyT &LHS, const VH &RHS) {