26 #ifndef LLVM_ADT_VALUEMAP_H
27 #define LLVM_ADT_VALUEMAP_H
37 template<
typename KeyT,
typename ValueT,
typename Config>
40 template<
typename DenseMapT,
typename KeyT>
42 template<
typename DenseMapT,
typename KeyT>
48 template<
typename KeyT>
60 template<
typename ExtraDataT>
62 template<
typename ExtraDataT>
69 template<
typename ExtraDataT>
74 template<
typename KeyT,
typename ValueT,
typename Config =ValueMapConfig<KeyT> >
79 typedef typename Config::ExtraData ExtraData;
89 explicit
ValueMap(
unsigned NumInitBuckets = 64)
90 : Map(NumInitBuckets), Data() {}
91 explicit ValueMap(
const ExtraData &Data,
unsigned NumInitBuckets = 64)
92 : Map(NumInitBuckets), Data(Data) {}
127 return I != Map.
end() ? I->second : ValueT();
133 std::pair<iterator, bool>
insert(
const std::pair<KeyT, ValueT> &KV) {
134 std::pair<typename MapT::iterator, bool> map_result=
135 Map.
insert(std::make_pair(Wrap(KV.first), KV.second));
136 return std::make_pair(
iterator(map_result.first), map_result.second);
140 template<
typename InputIt>
164 return Map[Wrap(Key)];
185 ValueMapCVH Wrap(
KeyT key)
const {
190 return ValueMapCVH(key, const_cast<ValueMap*>(
this));
196 template<
typename KeyT,
typename ValueT,
typename Config>
197 class ValueMapCallbackVH :
public CallbackVH {
215 sys::Mutex *M = Config::getMutex(Copy.Map->Data);
218 Config::onDelete(Copy.Map->Data, Copy.Unwrap());
219 Copy.Map->Map.erase(Copy);
224 assert(isa<KeySansPointerT>(new_key) &&
225 "Invalid RAUW on key of ValueMap<>");
228 sys::Mutex *M = Config::getMutex(Copy.Map->Data);
232 KeyT typed_new_key = cast<KeySansPointerT>(new_key);
234 Config::onRAUW(Copy.Map->Data, Copy.Unwrap(), typed_new_key);
235 if (Config::FollowRAUW) {
239 if (I != Copy.Map->Map.end()) {
241 Copy.Map->Map.erase(I);
242 Copy.Map->insert(std::make_pair(typed_new_key, Target));
250 template<
typename KeyT,
typename ValueT,
typename Config>
256 return VH(PointerInfo::getEmptyKey(), NULL);
259 return VH(PointerInfo::getTombstoneKey(), NULL);
262 return PointerInfo::getHashValue(Val.
Unwrap());
265 return PointerInfo::getHashValue(Val);
276 template<
typename DenseMapT,
typename KeyT>
277 class ValueMapIterator :
278 public std::iterator<std::forward_iterator_tag,
279 std::pair<KeyT, typename DenseMapT::mapped_type>,
281 typedef typename DenseMapT::iterator BaseT;
282 typedef typename DenseMapT::mapped_type ValueT;
289 BaseT
base()
const {
return I; }
295 operator std::pair<KeyT, ValueT>()
const {
325 template<
typename DenseMapT,
typename KeyT>
326 class ValueMapConstIterator :
327 public std::iterator<std::forward_iterator_tag,
328 std::pair<KeyT, typename DenseMapT::mapped_type>,
330 typedef typename DenseMapT::const_iterator BaseT;
331 typedef typename DenseMapT::mapped_type ValueT;
339 BaseT
base()
const {
return I; }
345 operator std::pair<KeyT, ValueT>()
const {
DenseMapInfo< KeyT > PointerInfo
ValueTypeProxy operator->() const
bool isPointerIntoBucketsArray(const void *Ptr) const
static void onRAUW(const ExtraDataT &, KeyT, KeyT)
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
const_iterator begin() const
ValueTypeProxy * operator->()
ValueT lookup(const KeyT &Val) const
virtual void allUsesReplacedWith(Value *new_key)
std::pair< const BasicBlock *, void * > value_type
const void * getPointerIntoBucketsArray() const
static unsigned getHashValue(const VH &Val)
iterator find_as(const LookupKeyT &Val)
static void onDelete(const ExtraDataT &, KeyT)
ValueTypeProxy operator->() const
ValueMapConstIterator(ValueMapIterator< DenseMapT, KeyT > Other)
bool count(const KeyT &Val) const
count - Return true if the specified key is in the map.
iterator find(const KeyT &Val)
const void * getPointerIntoBucketsArray() const
value_type & FindAndConstruct(const KeyT &Key)
ValueMapConstIterator< MapT, KeyT > const_iterator
ValueMap(const ExtraData &Data, unsigned NumInitBuckets=64)
Value * getValPtr() const
void resize(size_t Size)
Grow the densemap so that it has at least Size buckets. Does not shrink.
LLVM Basic Block Representation.
ValueMapIterator & operator++()
bool operator==(const ValueMapConstIterator &RHS) const
static bool isEqual(const VH &LHS, const VH &RHS)
bool operator!=(const ValueMapIterator &RHS) const
ValueTypeProxy * operator->()
ValueMapCallbackVH< KeyT, ValueT, Config > VH
ValueMapConstIterator operator++(int)
ValueMapIterator operator++(int)
const_iterator end() const
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
void insert(InputIt I, InputIt E)
insert - Range insertion of pairs.
ValueMapIterator(BaseT I)
bool erase(const KeyT &Val)
ValueTypeProxy operator*() const
ValueMapConstIterator(BaseT I)
void resize(size_t Size)
Grow the map so that it has at least Size buckets. Does not shrink.
#define LLVM_DELETED_FUNCTION
bool operator!=(const ValueMapConstIterator &RHS) const
const_iterator find(const KeyT &Val) const
static sys::Mutex * getMutex(const ExtraDataT &)
static VH getTombstoneKey()
ValueMapIterator< MapT, KeyT > iterator
value_type & FindAndConstruct(const KeyT &Key)
bool LLVM_ATTRIBUTE_UNUSED_RESULT empty() const
static bool isEqual(const KeyT &LHS, const VH &RHS)
bool isPointerIntoBucketsArray(const void *Ptr) const
LLVM Value Representation.
bool operator==(const ValueMapIterator &RHS) const
ValueMapConstIterator & operator++()
static unsigned getHashValue(const KeyT &Val)
ValueT & operator[](const KeyT &Key)
bool erase(const KeyT &Val)
ValueTypeProxy operator*() const