comparison include/llvm/IR/ValueMap.h @ 95:afa8332a0e37 LLVM3.8

LLVM 3.8
author Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
date Tue, 13 Oct 2015 17:48:58 +0900
parents 60c9769439b8
children 1172e4bd9c6f
comparison
equal deleted inserted replaced
84:f3e34b893a5f 95:afa8332a0e37
97 explicit ValueMap(unsigned NumInitBuckets = 64) 97 explicit ValueMap(unsigned NumInitBuckets = 64)
98 : Map(NumInitBuckets), Data() {} 98 : Map(NumInitBuckets), Data() {}
99 explicit ValueMap(const ExtraData &Data, unsigned NumInitBuckets = 64) 99 explicit ValueMap(const ExtraData &Data, unsigned NumInitBuckets = 64)
100 : Map(NumInitBuckets), Data(Data) {} 100 : Map(NumInitBuckets), Data(Data) {}
101 101
102 ~ValueMap() {}
103
104 bool hasMD() const { return MDMap; } 102 bool hasMD() const { return MDMap; }
105 MDMapT &MD() { 103 MDMapT &MD() {
106 if (!MDMap) 104 if (!MDMap)
107 MDMap.reset(new MDMapT); 105 MDMap.reset(new MDMapT);
108 return *MDMap; 106 return *MDMap;
147 145
148 // Inserts key,value pair into the map if the key isn't already in the map. 146 // Inserts key,value pair into the map if the key isn't already in the map.
149 // If the key is already in the map, it returns false and doesn't update the 147 // If the key is already in the map, it returns false and doesn't update the
150 // value. 148 // value.
151 std::pair<iterator, bool> insert(const std::pair<KeyT, ValueT> &KV) { 149 std::pair<iterator, bool> insert(const std::pair<KeyT, ValueT> &KV) {
152 std::pair<typename MapT::iterator, bool> map_result= 150 auto MapResult = Map.insert(std::make_pair(Wrap(KV.first), KV.second));
153 Map.insert(std::make_pair(Wrap(KV.first), KV.second)); 151 return std::make_pair(iterator(MapResult.first), MapResult.second);
154 return std::make_pair(iterator(map_result.first), map_result.second); 152 }
153
154 std::pair<iterator, bool> insert(std::pair<KeyT, ValueT> &&KV) {
155 auto MapResult =
156 Map.insert(std::make_pair(Wrap(KV.first), std::move(KV.second)));
157 return std::make_pair(iterator(MapResult.first), MapResult.second);
155 } 158 }
156 159
157 /// insert - Range insertion of pairs. 160 /// insert - Range insertion of pairs.
158 template<typename InputIt> 161 template<typename InputIt>
159 void insert(InputIt I, InputIt E) { 162 void insert(InputIt I, InputIt E) {
209 } 212 }
210 }; 213 };
211 214
212 // This CallbackVH updates its ValueMap when the contained Value changes, 215 // This CallbackVH updates its ValueMap when the contained Value changes,
213 // according to the user's preferences expressed through the Config object. 216 // according to the user's preferences expressed through the Config object.
214 template<typename KeyT, typename ValueT, typename Config> 217 template <typename KeyT, typename ValueT, typename Config>
215 class ValueMapCallbackVH : public CallbackVH { 218 class ValueMapCallbackVH final : public CallbackVH {
216 friend class ValueMap<KeyT, ValueT, Config>; 219 friend class ValueMap<KeyT, ValueT, Config>;
217 friend struct DenseMapInfo<ValueMapCallbackVH>; 220 friend struct DenseMapInfo<ValueMapCallbackVH>;
218 typedef ValueMap<KeyT, ValueT, Config> ValueMapT; 221 typedef ValueMap<KeyT, ValueT, Config> ValueMapT;
219 typedef typename std::remove_pointer<KeyT>::type KeySansPointerT; 222 typedef typename std::remove_pointer<KeyT>::type KeySansPointerT;
220 223
256 if (Config::FollowRAUW) { 259 if (Config::FollowRAUW) {
257 typename ValueMapT::MapT::iterator I = Copy.Map->Map.find(Copy); 260 typename ValueMapT::MapT::iterator I = Copy.Map->Map.find(Copy);
258 // I could == Copy.Map->Map.end() if the onRAUW callback already 261 // I could == Copy.Map->Map.end() if the onRAUW callback already
259 // removed the old mapping. 262 // removed the old mapping.
260 if (I != Copy.Map->Map.end()) { 263 if (I != Copy.Map->Map.end()) {
261 ValueT Target(I->second); 264 ValueT Target(std::move(I->second));
262 Copy.Map->Map.erase(I); // Definitely destroys *this. 265 Copy.Map->Map.erase(I); // Definitely destroys *this.
263 Copy.Map->insert(std::make_pair(typed_new_key, Target)); 266 Copy.Map->insert(std::make_pair(typed_new_key, std::move(Target)));
264 } 267 }
265 } 268 }
266 } 269 }
267 }; 270 };
268 271