25#ifndef LLVM_IR_VALUEMAP_H
26#define LLVM_IR_VALUEMAP_H
45template<
typename KeyT,
typename ValueT,
typename Config>
46class ValueMapCallbackVH;
47template<
typename DenseMapT,
typename KeyT>
48class ValueMapIterator;
49template<
typename DenseMapT,
typename KeyT>
50class ValueMapConstIterator;
55template<
typename KeyT,
typename MutexT = sys::Mutex>
69 template<
typename ExtraDataT>
71 template<
typename ExtraDataT>
78 template<
typename ExtraDataT>
83template<
typename KeyT,
typename ValueT,
typename Config =ValueMapConfig<KeyT>>
90 using ExtraData =
typename Config::ExtraData;
93 std::optional<MDMapT> MDMap;
103 : Map(NumInitBuckets), Data() {}
104 explicit ValueMap(
const ExtraData &Data,
unsigned NumInitBuckets = 64)
105 : Map(NumInitBuckets), Data(Data) {}
119 std::optional<MDMapT> &
getMDMap() {
return MDMap; }
125 auto Where = MDMap->find(
MD);
126 if (Where == MDMap->end())
128 return Where->second.get();
139 bool empty()
const {
return Map.empty(); }
152 return Map.find_as(Val) == Map.end() ? 0 : 1;
166 return I != Map.end() ?
I->second :
ValueT();
172 std::pair<iterator, bool>
insert(
const std::pair<KeyT, ValueT> &KV) {
173 auto MapResult = Map.insert(std::make_pair(Wrap(KV.first), KV.second));
174 return std::make_pair(
iterator(MapResult.first), MapResult.second);
177 std::pair<iterator, bool>
insert(std::pair<KeyT, ValueT> &&KV) {
179 Map.insert(std::make_pair(Wrap(KV.first), std::move(KV.second)));
180 return std::make_pair(
iterator(MapResult.first), MapResult.second);
184 template<
typename InputIt>
199 return Map.erase(
I.base());
203 return Map.FindAndConstruct(Wrap(Key));
207 return Map[Wrap(Key)];
214 return Map.isPointerIntoBucketsArray(
Ptr);
221 return Map.getPointerIntoBucketsArray();
228 ValueMapCVH Wrap(
KeyT key)
const {
233 return ValueMapCVH(key,
const_cast<ValueMap*
>(
this));
239template <
typename KeyT,
typename ValueT,
typename Config>
245 using KeySansPointerT = std::remove_pointer_t<KeyT>;
262 typename Config::mutex_type *M = Config::getMutex(Copy.Map->Data);
263 std::unique_lock<typename Config::mutex_type> Guard;
265 Guard = std::unique_lock<typename Config::mutex_type>(*M);
266 Config::onDelete(Copy.Map->Data, Copy.Unwrap());
267 Copy.Map->Map.erase(Copy);
271 assert(isa<KeySansPointerT>(new_key) &&
272 "Invalid RAUW on key of ValueMap<>");
275 typename Config::mutex_type *M = Config::getMutex(Copy.Map->Data);
276 std::unique_lock<typename Config::mutex_type> Guard;
278 Guard = std::unique_lock<typename Config::mutex_type>(*M);
280 KeyT typed_new_key = cast<KeySansPointerT>(new_key);
282 Config::onRAUW(Copy.Map->Data, Copy.Unwrap(), typed_new_key);
283 if (Config::FollowRAUW) {
287 if (
I != Copy.Map->Map.end()) {
289 Copy.Map->Map.erase(
I);
290 Copy.Map->insert(std::make_pair(typed_new_key, std::move(
Target)));
296template<
typename KeyT,
typename ValueT,
typename Config>
321 return LHS ==
RHS.getValPtr();
326 using BaseT =
typename DenseMapT::iterator;
327 using ValueT =
typename DenseMapT::mapped_type;
333 using value_type = std::pair<KeyT, typename DenseMapT::mapped_type>;
349 operator std::pair<KeyT, ValueT>()
const {
380 using BaseT =
typename DenseMapT::const_iterator;
381 using ValueT =
typename DenseMapT::mapped_type;
387 using value_type = std::pair<KeyT, typename DenseMapT::mapped_type>;
403 operator std::pair<KeyT, ValueT>()
const {
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This file defines DenseMapInfo traits for DenseMap.
This file defines the DenseMap class.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Value handle with callbacks on RAUW and destruction.
Target - Wrapper for Target specific information.
Value * getValPtr() const
void allUsesReplacedWith(Value *new_key) override
Callback for Value RAUW.
void deleted() override
Callback for Value destruction.
ValueMapConstIterator operator++(int)
std::ptrdiff_t difference_type
ValueMapConstIterator & operator++()
bool operator!=(const ValueMapConstIterator &RHS) const
ValueTypeProxy operator*() const
std::pair< KeyT, typename DenseMapT::mapped_type > value_type
bool operator==(const ValueMapConstIterator &RHS) const
ValueMapConstIterator(ValueMapIterator< DenseMapT, KeyT > Other)
std::forward_iterator_tag iterator_category
ValueMapConstIterator(BaseT I)
ValueTypeProxy operator->() const
ValueTypeProxy operator*() const
ValueMapIterator(BaseT I)
std::forward_iterator_tag iterator_category
std::ptrdiff_t difference_type
ValueMapIterator & operator++()
std::pair< KeyT, typename DenseMapT::mapped_type > value_type
bool operator!=(const ValueMapIterator &RHS) const
bool operator==(const ValueMapIterator &RHS) const
ValueTypeProxy operator->() const
ValueMapIterator operator++(int)
void insert(InputIt I, InputIt E)
insert - Range insertion of pairs.
ValueT lookup(const KeyT &Val) const
lookup - Return the entry for the specified key, or a default constructed value if no such entry exis...
ValueMapIterator< MapT, KeyT > iterator
bool isPointerIntoBucketsArray(const void *Ptr) const
isPointerIntoBucketsArray - Return true if the specified pointer points somewhere into the ValueMap's...
size_type count(const KeyT &Val) const
Return 1 if the specified key is in the map, 0 otherwise.
std::pair< KeyT, ValueT > value_type
std::optional< MDMapT > & getMDMap()
ValueMap & operator=(ValueMap &&)=delete
value_type & FindAndConstruct(const KeyT &Key)
iterator find(const KeyT &Val)
std::optional< Metadata * > getMappedMD(const Metadata *MD) const
Get the mapped metadata, if it's in the map.
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
const void * getPointerIntoBucketsArray() const
getPointerIntoBucketsArray() - Return an opaque pointer into the buckets array.
std::pair< iterator, bool > insert(std::pair< KeyT, ValueT > &&KV)
ValueMapConstIterator< MapT, KeyT > const_iterator
const_iterator find(const KeyT &Val) const
ValueMap(unsigned NumInitBuckets=64)
ValueT & operator[](const KeyT &Key)
void reserve(size_t Size)
Grow the map so that it has at least Size buckets. Does not shrink.
ValueMap(const ExtraData &Data, unsigned NumInitBuckets=64)
const_iterator end() const
const_iterator begin() const
bool erase(const KeyT &Val)
ValueMap & operator=(const ValueMap &)=delete
ValueMap(const ValueMap &)=delete
ValueMap(ValueMap &&)=delete
LLVM Value Representation.
This is an optimization pass for GlobalISel generic memory operations.
static unsigned getHashValue(const KeyT &Val)
static VH getTombstoneKey()
static bool isEqual(const KeyT &LHS, const VH &RHS)
static unsigned getHashValue(const VH &Val)
static bool isEqual(const VH &LHS, const VH &RHS)
An information struct used to provide DenseMap with the various necessary components for a given valu...
This class defines the default behavior for configurable aspects of ValueMap<>.
static mutex_type * getMutex(const ExtraDataT &)
Returns a mutex that should be acquired around any changes to the map.
static void onDelete(const ExtraDataT &, KeyT)
static void onRAUW(const ExtraDataT &, KeyT, KeyT)
ValueTypeProxy * operator->()
ValueTypeProxy * operator->()