14 #ifndef LLVM_ADT_STRINGMAP_H 15 #define LLVM_ADT_STRINGMAP_H 28 #include <initializer_list> 56 unsigned NumBuckets = 0;
57 unsigned NumItems = 0;
58 unsigned NumTombstones = 0;
63 : ItemSize(itemSize) {}
65 : TheTable(RHS.TheTable), NumBuckets(RHS.NumBuckets),
66 NumItems(RHS.NumItems), NumTombstones(RHS.NumTombstones),
67 ItemSize(RHS.ItemSize) {
68 RHS.TheTable =
nullptr;
71 RHS.NumTombstones = 0;
75 unsigned RehashTable(
unsigned BucketNo = 0);
103 uintptr_t Val =
static_cast<uintptr_t
>(-1);
104 Val <<= PointerLikeTypeTraits<StringMapEntryBase *>::NumLowBitsAvailable;
111 bool empty()
const {
return NumItems == 0; }
112 unsigned size()
const {
return NumItems; }
125 template<
typename ValueTy>
132 template <
typename... InitTy>
149 const char *
getKeyData()
const {
return reinterpret_cast<const char*
>(
this+1);}
155 template <
typename AllocatorTy,
typename... InitTy>
157 InitTy &&... InitVals) {
158 size_t KeyLength = Key.
size();
166 static_cast<StringMapEntry*
>(Allocator.Allocate(AllocSize,Alignment));
167 assert(NewItem &&
"Unhandled out-of-memory");
170 new (NewItem)
StringMapEntry(KeyLength, std::forward<InitTy>(InitVals)...);
173 char *StrBuffer =
const_cast<char*
>(NewItem->
getKeyData());
176 StrBuffer[KeyLength] = 0;
181 template <
typename... InitType>
184 return Create(Key, A, std::forward<InitType>(InitVal)...);
188 return Create(Key, ValueTy());
200 template<
typename AllocatorTy>
205 Allocator.Deallocate(static_cast<void *>(
this), AllocSize);
219 template<
typename ValueTy,
typename AllocatorTy = MallocAllocator>
240 for (
const auto &
P :
List) {
250 Allocator(RHS.Allocator) {
257 unsigned *HashTable = (
unsigned *)(TheTable + NumBuckets + 1),
258 *RHSHashTable = (
unsigned *)(RHS.
TheTable + NumBuckets + 1);
262 for (
unsigned I = 0,
E = NumBuckets;
I !=
E; ++
I) {
264 if (!Bucket || Bucket == getTombstoneVal()) {
265 TheTable[
I] = Bucket;
269 TheTable[
I] = MapEntryTy::Create(
270 static_cast<MapEntryTy *>(Bucket)->getKey(), Allocator,
271 static_cast<MapEntryTy *>(Bucket)->getValue());
272 HashTable[
I] = RHSHashTable[
I];
294 for (
unsigned I = 0,
E = NumBuckets;
I !=
E; ++
I) {
296 if (Bucket && Bucket != getTombstoneVal()) {
297 static_cast<MapEntryTy*
>(Bucket)->Destroy(Allocator);
316 return iterator(TheTable, NumBuckets == 0);
319 return iterator(TheTable+NumBuckets,
true);
334 int Bucket = FindKey(Key);
335 if (Bucket == -1)
return end();
336 return iterator(TheTable+Bucket,
true);
340 int Bucket = FindKey(Key);
341 if (Bucket == -1)
return end();
360 return find(Key) ==
end() ? 0 : 1;
367 unsigned BucketNo = LookupBucketFor(KeyValue->
getKey());
369 if (Bucket && Bucket != getTombstoneVal())
372 if (Bucket == getTombstoneVal())
376 assert(NumItems + NumTombstones <= NumBuckets);
386 std::pair<iterator, bool>
insert(std::pair<StringRef, ValueTy> KV) {
387 return try_emplace(KV.first, std::move(KV.second));
394 template <
typename... ArgsTy>
396 unsigned BucketNo = LookupBucketFor(Key);
398 if (Bucket && Bucket != getTombstoneVal())
399 return std::make_pair(
iterator(TheTable + BucketNo,
false),
402 if (Bucket == getTombstoneVal())
404 Bucket = MapEntryTy::Create(Key, Allocator, std::forward<ArgsTy>(
Args)...);
406 assert(NumItems + NumTombstones <= NumBuckets);
408 BucketNo = RehashTable(BucketNo);
409 return std::make_pair(
iterator(TheTable + BucketNo,
false),
true);
418 for (
unsigned I = 0,
E = NumBuckets;
I !=
E; ++
I) {
420 if (Bucket && Bucket != getTombstoneVal()) {
421 static_cast<MapEntryTy*
>(Bucket)->Destroy(Allocator);
444 if (I ==
end())
return false;
450 template <
typename DerivedTy,
typename ValueTy>
461 bool NoAdvance =
false)
463 if (!NoAdvance) AdvancePastEmptyBuckets();
468 return static_cast<DerivedTy &
>(*this);
471 bool operator==(
const DerivedTy &RHS)
const {
return Ptr == RHS.Ptr; }
475 AdvancePastEmptyBuckets();
476 return static_cast<DerivedTy &
>(*this);
486 void AdvancePastEmptyBuckets() {
492 template <
typename ValueTy>
495 const StringMapEntry<ValueTy>> {
502 bool NoAdvance =
false)
503 :
base(Bucket, NoAdvance) {}
506 return *
static_cast<const StringMapEntry<ValueTy> *
>(*this->Ptr);
510 template <
typename ValueTy>
512 StringMapEntry<ValueTy>> {
519 bool NoAdvance =
false)
520 :
base(Bucket, NoAdvance) {}
523 return *
static_cast<StringMapEntry<ValueTy> *
>(*this->Ptr);
531 template <
typename ValueTy>
534 StringMapConstIterator<ValueTy>,
535 std::forward_iterator_tag, StringRef> {
546 Key = this->wrapped()->getKey();
556 #endif // LLVM_ADT_STRINGMAP_H const_iterator end(StringRef path)
Get end iterator over path.
iterator_range< StringMapKeyIterator< ValueTy > > keys() const
StringMapImpl(unsigned itemSize)
const_iterator begin(StringRef path, Style style=Style::native)
Get begin iterator over path.
This class represents lattice values for constants.
StringMapEntry - This is used to represent one value that is inserted into a StringMap.
void setValue(const ValueTy &V)
This provides a very simple, boring adaptor for a begin and end iterator into a range type...
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t size() const
size - Get the string size.
iterator find(StringRef Key)
const_iterator end() const
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
This file defines the MallocAllocator and BumpPtrAllocator interfaces.
StringMap(const StringMap &RHS)
const_iterator find(StringRef Key) const
StringMapKeyIterator(StringMapConstIterator< ValueTy > Iter)
const ValueTy & getValue() const
StringMap & operator=(StringMap RHS)
static StringMapEntry & GetStringMapEntryFromKeyData(const char *KeyData)
GetStringMapEntryFromKeyData - Given key data that is known to be embedded into a StringMapEntry...
StringMapIterator(StringMapEntryBase **Bucket, bool NoAdvance=false)
static StringMapEntry * Create(StringRef Key, AllocatorTy &Allocator, InitTy &&... InitVals)
Create a StringMapEntry for the specified key construct the value using InitiVals.
StringMapImpl - This is the base class of StringMap that is shared among all of its instantiations...
StringMapEntry< ValueTy > & operator*() const
void Destroy(AllocatorTy &Allocator)
Destroy - Destroy this StringMapEntry, releasing memory back to the specified allocator.
StringMapIterBase(StringMapEntryBase **Bucket, bool NoAdvance=false)
void swap(StringMapImpl &Other)
std::pair< iterator, bool > try_emplace(StringRef Key, ArgsTy &&... Args)
Emplace a new element for the specified key into the map if the key isn't already in the map...
CRTP base class which implements the entire standard iterator facade in terms of a minimal subset of ...
StringMap(StringMap &&RHS)
StringMapEntryBase ** TheTable
initializer< Ty > init(const Ty &Val)
size_type count(StringRef Key) const
count - Return 1 if the element is in the map, 0 otherwise.
CRTP base class for adapting an iterator to a different type.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
const_iterator begin() const
void Destroy()
Destroy this object, releasing memory back to the malloc allocator.
StringMap(unsigned InitialSize)
ValueTy lookup(StringRef Key) const
lookup - Return the entry for the specified key, or a default constructed value if no such entry exis...
auto find(R &&Range, const T &Val) -> decltype(adl_begin(Range))
Provide wrappers to std::find which take ranges instead of having to pass begin/end explicitly...
bool erase(StringRef Key)
constexpr bool empty(const T &RangeOrContainer)
Test whether RangeOrContainer is empty. Similar to C++17 std::empty.
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
auto size(R &&Range, typename std::enable_if< std::is_same< typename std::iterator_traits< decltype(Range.begin())>::iterator_category, std::random_access_iterator_tag >::value, void >::type *=nullptr) -> decltype(std::distance(Range.begin(), Range.end()))
Get the size of a range.
StringMapEntryBase(size_t Len)
StringMapEntry(size_t strLen, InitTy &&... InitVals)
AllocatorTy & getAllocator()
std::pair< iterator, bool > insert(std::pair< StringRef, ValueTy > KV)
insert - Inserts the specified key/value pair into the map if the key isn't already in the map...
const AllocatorTy & getAllocator() const
static StringMapEntryBase * getTombstoneVal()
bool insert(MapEntryTy *KeyValue)
insert - Insert the specified key/value pair into the map.
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
A range adaptor for a pair of iterators.
StringMap - This is an unconventional map that is specialized for handling keys that are "strings"...
StringMap(unsigned InitialSize, AllocatorTy A)
bool operator==(const DerivedTy &RHS) const
unsigned getNumBuckets() const
StringMapConstIterator(StringMapEntryBase **Bucket, bool NoAdvance=false)
size_t getKeyLength() const
DerivedTy & operator=(const DerivedTy &Other)
StringMapEntry(size_t strLen)
const char * getKeyData() const
getKeyData - Return the start of the string data that is the key for this value.
static StringMapEntry * Create(StringRef Key, InitType &&... InitVal)
Create - Create a StringMapEntry with normal malloc/free.
static StringMapEntry * Create(StringRef Key)
DerivedTy operator++(int)
StringMap(std::initializer_list< std::pair< StringRef, ValueTy >> List)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
StringMapImpl(StringMapImpl &&RHS)
unsigned getNumItems() const
StringMapEntryBase - Shared base class of StringMapEntry instances.
StringRef - Represent a constant reference to a string, i.e.
ValueTy & operator[](StringRef Key)
Lookup the ValueTy for the Key, or create a default constructed value if the key is not in the map...
const StringMapEntry< ValueTy > & operator*() const
constexpr char Args[]
Key for Kernel::Metadata::mArgs.