26 #ifndef LLVM_IR_VALUEMAP_H 27 #define LLVM_IR_VALUEMAP_H 42 #include <type_traits> 47 template<
typename KeyT,
typename ValueT,
typename Config>
49 template<
typename DenseMapT,
typename KeyT>
51 template<
typename DenseMapT,
typename KeyT>
57 template<
typename KeyT,
typename MutexT = sys::Mutex>
71 template<
typename ExtraDataT>
72 static void onRAUW(
const ExtraDataT & , KeyT , KeyT ) {}
73 template<
typename ExtraDataT>
74 static void onDelete(
const ExtraDataT &, KeyT ) {}
80 template<
typename ExtraDataT>
85 template<
typename KeyT,
typename ValueT,
typename Config =ValueMapConfig<KeyT>>
92 using ExtraData =
typename Config::ExtraData;
97 bool MayMapMetadata =
true;
106 : Map(NumInitBuckets), Data() {}
107 explicit ValueMap(
const ExtraData &Data,
unsigned NumInitBuckets = 64)
108 : Map(NumInitBuckets), Data(Data) {}
132 auto Where = MDMap->find(MD);
133 if (Where == MDMap->end())
135 return Where->second.get();
173 return I != Map.
end() ? I->second :
ValueT();
179 std::pair<iterator, bool>
insert(
const std::pair<KeyT, ValueT> &KV) {
180 auto MapResult = Map.
insert(std::make_pair(Wrap(KV.first), KV.second));
181 return std::make_pair(
iterator(MapResult.first), MapResult.second);
184 std::pair<iterator, bool>
insert(std::pair<KeyT, ValueT> &&KV) {
186 Map.
insert(std::make_pair(Wrap(KV.first), std::move(KV.second)));
187 return std::make_pair(
iterator(MapResult.first), MapResult.second);
191 template<
typename InputIt>
214 return Map[Wrap(Key)];
235 ValueMapCVH Wrap(KeyT key)
const {
240 return ValueMapCVH(key, const_cast<ValueMap*>(
this));
246 template <
typename KeyT,
typename ValueT,
typename Config>
252 using KeySansPointerT =
typename std::remove_pointer<KeyT>::type;
264 KeyT
Unwrap()
const {
return cast_or_null<KeySansPointerT>(getValPtr()); }
269 typename Config::mutex_type *M = Config::getMutex(Copy.Map->Data);
273 Config::onDelete(Copy.Map->Data, Copy.
Unwrap());
274 Copy.Map->Map.
erase(Copy);
278 assert(isa<KeySansPointerT>(new_key) &&
279 "Invalid RAUW on key of ValueMap<>");
282 typename Config::mutex_type *M = Config::getMutex(Copy.Map->Data);
287 KeyT typed_new_key = cast<KeySansPointerT>(new_key);
289 Config::onRAUW(Copy.Map->Data, Copy.
Unwrap(), typed_new_key);
290 if (Config::FollowRAUW) {
294 if (I != Copy.Map->Map.
end()) {
296 Copy.Map->Map.
erase(I);
297 Copy.Map->
insert(std::make_pair(typed_new_key, std::move(Target)));
303 template<
typename KeyT,
typename ValueT,
typename Config>
332 template<
typename DenseMapT,
typename KeyT>
334 public std::iterator<std::forward_iterator_tag,
335 std::pair<KeyT, typename DenseMapT::mapped_type>,
337 using BaseT =
typename DenseMapT::iterator;
338 using ValueT =
typename DenseMapT::mapped_type;
354 operator std::pair<KeyT, ValueT>()
const {
355 return std::make_pair(first, second);
384 template<
typename DenseMapT,
typename KeyT>
386 public std::iterator<std::forward_iterator_tag,
387 std::pair<KeyT, typename DenseMapT::mapped_type>,
389 using BaseT =
typename DenseMapT::const_iterator;
390 using ValueT =
typename DenseMapT::mapped_type;
406 operator std::pair<KeyT, ValueT>()
const {
407 return std::make_pair(first, second);
438 #endif // LLVM_IR_VALUEMAP_H
This class represents lattice values for constants.
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
ValueTypeProxy * operator->()
static void onDelete(const ExtraDataT &, KeyT)
const void * getPointerIntoBucketsArray() const
getPointerIntoBucketsArray() - Return an opaque pointer into the buckets array.
void emplace(ArgTypes &&... Args)
Create a new object by constructing it in place with the given arguments.
This class defines the default behavior for configurable aspects of ValueMap<>.
ValueTypeProxy operator*() const
const void * getPointerIntoBucketsArray() const
getPointerIntoBucketsArray() - Return an opaque pointer into the buckets array.
const_iterator end() const
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
ValueMap(unsigned NumInitBuckets=64)
static unsigned getHashValue(const VH &Val)
bool operator!=(const ValueMapConstIterator &RHS) const
APInt operator*(APInt a, uint64_t RHS)
ValueMapConstIterator(ValueMapIterator< DenseMapT, KeyT > Other)
std::pair< iterator, bool > insert(std::pair< KeyT, ValueT > &&KV)
iterator find(const KeyT &Val)
ValueT lookup(const KeyT &Val) const
lookup - Return the entry for the specified key, or a default constructed value if no such entry exis...
bool operator!=(const ValueMapIterator &RHS) const
value_type & FindAndConstruct(const KeyT &Key)
void allUsesReplacedWith(Value *new_key) override
Callback for Value RAUW.
bool isPointerIntoBucketsArray(const void *Ptr) const
isPointerIntoBucketsArray - Return true if the specified pointer points somewhere into the ValueMap's...
value_type & FindAndConstruct(const KeyT &Key)
iterator find(const_arg_type_t< KeyT > Val)
ValueMap(const ExtraData &Data, unsigned NumInitBuckets=64)
bool erase(const KeyT &Val)
Optional< Metadata * > getMappedMD(const Metadata *MD) const
Get the mapped metadata, if it's in the map.
ValueMapIterator & operator++()
std::pair< const Function *, FuncInfo > value_type
ValueTypeProxy operator->() const
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
const_iterator find(const KeyT &Val) const
Optional< MDMapT > & getMDMap()
static bool isEqual(const VH &LHS, const VH &RHS)
A pared-down imitation of std::unique_lock from C++11.
static mutex_type * getMutex(const ExtraDataT &)
Returns a mutex that should be acquired around any changes to the map.
void disableMapMetadata()
const_iterator begin() const
ValueTypeProxy * operator->()
ValueMapConstIterator operator++(int)
ValueMapIterator operator++(int)
bool operator==(const ValueMapIterator &RHS) const
void insert(InputIt I, InputIt E)
insert - Range insertion of pairs.
static void onRAUW(const ExtraDataT &, KeyT, KeyT)
ValueTypeProxy operator*() const
ValueMapIterator(BaseT I)
bool isPointerIntoBucketsArray(const void *Ptr) const
isPointerIntoBucketsArray - Return true if the specified pointer points somewhere into the DenseMap's...
ValueMapConstIterator(BaseT I)
void resize(size_t Size)
Grow the map so that it has at least Size buckets. Does not shrink.
Target - Wrapper for Target specific information.
static VH getTombstoneKey()
static bool isEqual(const KeyT &LHS, const VH &RHS)
bool mayMapMetadata() const
LLVM_NODISCARD bool empty() const
iterator find_as(const LookupKeyT &Val)
Alternate version of find() which allows a different, and possibly less expensive, key type.
size_type count(const KeyT &Val) const
Return 1 if the specified key is in the map, 0 otherwise.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
LLVM Value Representation.
ValueMapConstIterator & operator++()
Value handle with callbacks on RAUW and destruction.
static unsigned getHashValue(const KeyT &Val)
ValueTypeProxy operator->() const
ValueT & operator[](const KeyT &Key)
bool operator==(const ValueMapConstIterator &RHS) const
void deleted() override
Callback for Value destruction.
bool erase(const KeyT &Val)
Value * getValPtr() const