25#ifndef LLVM_IR_VALUEMAP_H
26#define LLVM_IR_VALUEMAP_H
45template <
typename KeyT,
typename ValueT,
typename Config>
47template <
typename DenseMapT,
typename KeyT,
bool IsConst>
53template <
typename KeyT,
typename MutexT = sys::Mutex>
struct ValueMapConfig {
66 template <
typename ExtraDataT>
68 template <
typename ExtraDataT>
75 template <
typename ExtraDataT>
82template <
typename KeyT,
typename ValueT,
83 typename Config = ValueMapConfig<KeyT>>
92 using ExtraData =
typename Config::ExtraData;
95 std::optional<MDMapT> MDMap;
105 : Map(NumInitBuckets), Data() {}
106 explicit ValueMap(
const ExtraData &Data,
unsigned NumInitBuckets = 64)
107 : Map(NumInitBuckets), Data(Data) {}
121 std::optional<MDMapT> &
getMDMap() {
return MDMap; }
129 auto Where = MDMap->find(
MD);
130 if (Where == MDMap->end())
132 return Where->second.get();
143 bool empty()
const {
return Map.empty(); }
157 return Map.find_as(Val) == Map.end() ? 0 : 1;
169 return I != Map.end() ?
I->second : ValueT();
175 std::pair<iterator, bool>
insert(
const std::pair<KeyT, ValueT> &KV) {
176 return Map.insert(std::make_pair(Wrap(KV.first), KV.second));
179 std::pair<iterator, bool>
insert(std::pair<KeyT, ValueT> &&KV) {
180 return Map.insert(std::make_pair(Wrap(KV.first), std::move(KV.second)));
184 template <
typename InputIt>
void insert(InputIt
I, InputIt
E) {
200 return Map.FindAndConstruct(Wrap(
Key));
209 return Map.isPointerIntoBucketsArray(Ptr);
216 return Map.getPointerIntoBucketsArray();
223 ValueMapCVH Wrap(
KeyT key)
const {
228 return ValueMapCVH(key,
const_cast<ValueMap *
>(
this));
234template <
typename KeyT,
typename ValueT,
typename Config>
240 using KeySansPointerT = std::remove_pointer_t<KeyT>;
244 ValueMapCallbackVH(
KeyT Key, ValueMapT *Map)
256 ValueMapCallbackVH Copy(*
this);
257 typename Config::mutex_type *M = Config::getMutex(Copy.Map->Data);
258 std::unique_lock<typename Config::mutex_type> Guard;
260 Guard = std::unique_lock<typename Config::mutex_type>(*M);
261 Config::onDelete(Copy.Map->Data, Copy.Unwrap());
262 Copy.Map->Map.erase(Copy);
267 "Invalid RAUW on key of ValueMap<>");
269 ValueMapCallbackVH Copy(*
this);
270 typename Config::mutex_type *M = Config::getMutex(Copy.Map->Data);
271 std::unique_lock<typename Config::mutex_type> Guard;
273 Guard = std::unique_lock<typename Config::mutex_type>(*M);
277 Config::onRAUW(Copy.Map->Data, Copy.Unwrap(), typed_new_key);
278 if (Config::FollowRAUW) {
282 if (
I != Copy.Map->Map.end()) {
283 ValueT
Target(std::move(
I->second));
284 Copy.Map->Map.erase(
I);
285 Copy.Map->insert(std::make_pair(typed_new_key, std::move(
Target)));
291template <
typename KeyT,
typename ValueT,
typename Config>
314 return LHS ==
RHS.getValPtr();
318template <
typename DenseMapT,
typename KeyT,
bool IsConst>
320 using BaseT = std::conditional_t<IsConst,
typename DenseMapT::const_iterator,
321 typename DenseMapT::iterator>;
322 using ValueT =
typename DenseMapT::mapped_type;
328 using value_type = std::pair<KeyT, typename DenseMapT::mapped_type>;
337 template <
bool C = IsConst,
typename = std::enable_if_t<C>>
342 BaseT
base()
const {
return I; }
346 std::conditional_t<IsConst, const ValueT &, ValueT &>
second;
350 operator std::pair<KeyT, ValueT>()
const {
356 ValueTypeProxy Result = {I->first.Unwrap(), I->second};
376template <
typename DenseMapT,
typename KeyT>
379template <
typename DenseMapT,
typename KeyT>
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This file defines DenseMapInfo traits for DenseMap.
This file defines the DenseMap class.
CallbackVH(const CallbackVH &)=default
DenseMapIterator< KeyT, ValueT, KeyInfoT, BucketT > iterator
DenseMapIterator< KeyT, ValueT, KeyInfoT, BucketT, true > const_iterator
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.
ValueTypeProxy operator*() const
ValueMapIteratorImpl operator++(int)
bool operator!=(const ValueMapIteratorImpl &RHS) const
std::pair< KeyT, typename MapT::mapped_type > value_type
bool operator==(const ValueMapIteratorImpl &RHS) const
ValueTypeProxy operator->() const
std::forward_iterator_tag iterator_category
ValueMapIteratorImpl(const ValueMapIteratorImpl< DenseMapT, KeyT, false > &Other)
ValueMapIteratorImpl(BaseT I)
ValueMapIteratorImpl & operator++()
ValueMapIteratorImpl()=default
std::ptrdiff_t difference_type
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...
WeakTrackingVH mapped_type
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< const Value *, WeakTrackingVH > value_type
std::optional< MDMapT > & getMDMap()
ValueMap & operator=(ValueMap &&)=delete
value_type & FindAndConstruct(const KeyT &Key)
ValueMapIteratorImpl< MapT, const Value *, true > const_iterator
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)
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
ValueMapIteratorImpl< MapT, const Value *, false > iterator
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.
ValueMapIteratorImpl< DenseMapT, KeyT, false > ValueMapIterator
auto cast_or_null(const Y &Val)
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
LLVM_ATTRIBUTE_VISIBILITY_DEFAULT AnalysisKey InnerAnalysisManagerProxy< AnalysisManagerT, IRUnitT, ExtraArgTs... >::Key
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
ValueMapIteratorImpl< DenseMapT, KeyT, true > ValueMapConstIterator
static unsigned getHashValue(const KeyT &Val)
static VH getTombstoneKey()
ValueMapCallbackVH< KeyT, ValueT, Config > VH
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->()
std::conditional_t< IsConst, const ValueT &, ValueT & > second