14 #ifndef LLVM_ADT_STRINGMAP_H
15 #define LLVM_ADT_STRINGMAP_H
27 #include <initializer_list>
67 RHS.TheTable =
nullptr;
70 RHS.NumTombstones = 0;
102 uintptr_t Val =
static_cast<uintptr_t
>(-1);
103 Val <<= PointerLikeTypeTraits<StringMapEntryBase *>::NumLowBitsAvailable;
124 template<
typename ValueTy>
131 template <
typename... InitTy>
148 const char *
getKeyData()
const {
return reinterpret_cast<const char*
>(
this+1);}
154 template <
typename AllocatorTy,
typename... InitTy>
156 InitTy &&... InitVals) {
157 unsigned KeyLength = Key.
size();
161 unsigned AllocSize =
static_cast<unsigned>(
sizeof(
StringMapEntry))+
166 static_cast<StringMapEntry*
>(Allocator.Allocate(AllocSize,Alignment));
169 new (NewItem)
StringMapEntry(KeyLength, std::forward<InitTy>(InitVals)...);
172 char *StrBuffer =
const_cast<char*
>(NewItem->
getKeyData());
174 memcpy(StrBuffer, Key.
data(), KeyLength);
175 StrBuffer[KeyLength] = 0;
180 template <
typename... InitType>
183 return Create(Key, A, std::forward<InitType>(InitVal)...);
187 return Create(Key, ValueTy());
199 template<
typename AllocatorTy>
205 Allocator.Deallocate(static_cast<void *>(
this), AllocSize);
219 template<
typename ValueTy,
typename AllocatorTy = MallocAllocator>
221 AllocatorTy Allocator;
240 for (
const auto &
P :
List) {
246 :
StringMapImpl(std::move(RHS)), Allocator(std::move(RHS.Allocator)) {}
250 Allocator(RHS.Allocator) {
270 static_cast<MapEntryTy *>(Bucket)->getKey(), Allocator,
271 static_cast<MapEntryTy *>(Bucket)->getValue());
272 HashTable[
I] = RHSHashTable[
I];
297 static_cast<MapEntryTy*
>(Bucket)->Destroy(Allocator);
335 if (Bucket == -1)
return end();
341 if (Bucket == -1)
return end();
360 return find(Key) ==
end() ? 0 : 1;
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>
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);
475 AdvancePastEmptyBuckets();
476 return static_cast<DerivedTy &
>(*this);
486 void AdvancePastEmptyBuckets() {
492 template <
typename ValueTy>
493 class StringMapConstIterator
494 :
public StringMapIterBase<StringMapConstIterator<ValueTy>,
495 const StringMapEntry<ValueTy>> {
496 using base = StringMapIterBase<StringMapConstIterator<ValueTy>,
497 const StringMapEntry<ValueTy>>;
502 bool NoAdvance =
false)
503 :
base(Bucket, NoAdvance) {}
510 template <
typename ValueTy>
511 class StringMapIterator :
public StringMapIterBase<StringMapIterator<ValueTy>,
512 StringMapEntry<ValueTy>> {
514 StringMapIterBase<StringMapIterator<ValueTy>, StringMapEntry<ValueTy>>;
519 bool NoAdvance =
false)
520 :
base(Bucket, NoAdvance) {}
531 template <
typename ValueTy>
532 class StringMapKeyIterator
533 :
public iterator_adaptor_base<StringMapKeyIterator<ValueTy>,
534 StringMapConstIterator<ValueTy>,
535 std::forward_iterator_tag, StringRef> {
536 using base = iterator_adaptor_base<StringMapKeyIterator<ValueTy>,
538 std::forward_iterator_tag, StringRef>;
543 :
base(std::move(Iter)) {}
546 Key = this->
wrapped()->getKey();
556 #endif // LLVM_ADT_STRINGMAP_H
const ValueTy & getValue() const
unsigned getNumItems() const
StringMapImpl(unsigned itemSize)
StringMapEntry - This is used to represent one value that is inserted into a StringMap.
const StringMapEntry< ValueTy > & operator*() const
const_iterator find(StringRef Key) const
void setValue(const ValueTy &V)
StringMapEntryBase(unsigned Len)
unsigned RehashTable(unsigned BucketNo=0)
RehashTable - Grow the table, redistributing values into the buckets with the appropriate mod-of-hash...
This provides a very simple, boring adaptor for a begin and end iterator into a range type...
int FindKey(StringRef Key) const
FindKey - Look up the bucket that contains the specified key.
iterator find(StringRef Key)
unsigned LookupBucketFor(StringRef Key)
LookupBucketFor - Look up the bucket that the specified string should end up in.
StringMapKeyIterator()=default
This file defines the MallocAllocator and BumpPtrAllocator interfaces.
StringMap(const StringMap &RHS)
StringMapKeyIterator(StringMapConstIterator< ValueTy > Iter)
unsigned getNumBuckets() 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)
size_type count(StringRef Key) const
count - Return 1 if the element is in the map, 0 otherwise.
const AllocatorTy & getAllocator() const
StringMapImpl - This is the base class of StringMap that is shared among all of its instantiations...
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)
StringMapConstIterator()=default
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t size() const
size - Get the string size.
CRTP base class which implements the entire standard iterator facade in terms of a minimal subset of ...
StringMap(StringMap &&RHS)
StringMapEntryBase ** TheTable
StringMapIterator()=default
StringMapEntry(unsigned strLen)
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
const_iterator end() const
void Destroy()
Destroy this object, releasing memory back to the malloc allocator.
StringMap(unsigned InitialSize)
void init(unsigned Size)
Allocate the table with the specified number of buckets and otherwise setup the map as empty...
const_iterator begin() const
static StringMapEntry * Create(StringRef Key, AllocatorTy &Allocator, InitTy &&...InitVals)
Create a StringMapEntry for the specified key construct the value using InitiVals.
StringMapIterator< ValueTy > iterator
bool erase(StringRef Key)
StringMapEntry< ValueTy > & operator*() const
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...
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
ValueTy lookup(StringRef Key) const
lookup - Return the entry for the specified key, or a default constructed value if no such entry exis...
AllocatorTy & getAllocator()
void RemoveKey(StringMapEntryBase *V)
RemoveKey - Remove the specified StringMapEntry from the table, but do not delete it...
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...
iterator_range< StringMapKeyIterator< ValueTy > > keys() const
const char * getKeyData() const
getKeyData - Return the start of the string data that is the key for this value.
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"...
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
StringMap(unsigned InitialSize, AllocatorTy A)
StringMapConstIterator(StringMapEntryBase **Bucket, bool NoAdvance=false)
DerivedTy & operator=(const DerivedTy &Other)
const StringMapConstIterator< ValueTy > & wrapped() const
bool operator==(const DerivedTy &RHS) const
StringMapEntry(unsigned strLen, InitTy &&...InitVals)
unsigned getKeyLength() const
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)
StringMapEntryBase - Shared base class of StringMapEntry instances.
static StringMapEntry * Create(StringRef Key, InitType &&...InitVal)
Create - Create a StringMapEntry with normal malloc/free.
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).
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...
StringMapConstIterator< ValueTy > const_iterator
StringMapEntryBase ** Ptr
StringMapIterBase()=default