31 #ifndef LLVM_ADT_SCOPEDHASHTABLE_H
32 #define LLVM_ADT_SCOPEDHASHTABLE_H
42 template <
typename K,
typename V,
typename KInfo = DenseMapInfo<K>,
43 typename AllocatorTy = MallocAllocator>
46 template <
typename K,
typename V>
56 const K &
getKey()
const {
return Key; }
64 template <
typename AllocatorTy>
67 const K &key,
const V &val,
72 New->NextInScope = nextInScope;
73 New->NextForKey = nextForKey;
80 Allocator.Deallocate(
this);
84 template <
typename K,
typename V,
typename KInfo = DenseMapInfo<K>,
85 typename AllocatorTy = MallocAllocator>
110 return LastValInScope;
114 LastValInScope = Val;
118 template <
typename K,
typename V,
typename KInfo = DenseMapInfo<K>>
126 assert(Node &&
"Dereference end()");
127 return Node->getValue();
130 return &Node->getValue();
134 return Node == RHS.Node;
137 return Node != RHS.Node;
141 assert(Node &&
"incrementing past end()");
142 Node = Node->getNextForKey();
150 template <
typename K,
typename V,
typename KInfo,
typename AllocatorTy>
151 class ScopedHashTable {
175 assert(!CurScope && TopLevelMap.empty() &&
"Scope imbalance!");
184 return TopLevelMap.count(Key);
188 auto I = TopLevelMap.find(Key);
189 if (
I != TopLevelMap.end())
190 return I->second->getValue();
195 void insert(
const K &Key,
const V &Val) {
205 TopLevelMap.find(Key);
206 if (I == TopLevelMap.end())
return end();
218 assert(S &&
"No scope active!");
220 KeyEntry =
ValTy::Create(S->getLastValInScope(), KeyEntry, Key, Val,
222 S->setLastValInScope(KeyEntry);
228 template <
typename K,
typename V,
typename KInfo,
typename Allocator>
231 PrevScope = HT.CurScope;
233 LastValInScope =
nullptr;
236 template <
typename K,
typename V,
typename KInfo,
typename Allocator>
238 assert(HT.CurScope ==
this &&
"Scope imbalance!");
239 HT.CurScope = PrevScope;
244 if (!ThisEntry->getNextForKey()) {
245 assert(HT.TopLevelMap[ThisEntry->getKey()] == ThisEntry &&
247 HT.TopLevelMap.erase(ThisEntry->getKey());
250 assert(KeyEntry == ThisEntry &&
"Scope imbalance!");
258 ThisEntry->
Destroy(HT.getAllocator());
264 #endif // LLVM_ADT_SCOPEDHASHTABLE_H
ScopedHashTableVal * getNextInScope()
ScopedHashTableIterator operator++(int)
void insertIntoScope(ScopeTy *S, const K &Key, const V &Val)
insertIntoScope - This inserts the specified key/value at the specified (possibly not the current) sc...
const V & getValue() const
bool operator!=(const ScopedHashTableIterator &RHS) const
This file defines the MallocAllocator and BumpPtrAllocator interfaces.
static ScopedHashTableVal * Create(ScopedHashTableVal *nextInScope, ScopedHashTableVal *nextForKey, const K &key, const V &val, AllocatorTy &Allocator)
bool operator==(const ScopedHashTableIterator &RHS) const
size_type count(const K &Key) const
Return 1 if the specified key is in the table, 0 otherwise.
ScopedHashTableScope * getParentScope()
ScopedHashTable & operator=(const ScopedHashTable &)=delete
const ScopedHashTableVal * getNextForKey() const
AllocatorTy & getAllocator()
Access to the allocator.
ScopedHashTableVal * getNextForKey()
const ScopeTy * getCurScope() const
const AllocatorTy & getAllocator() const
ScopedHashTable(AllocatorTy A)
void insert(const K &Key, const V &Val)
iterator begin(const K &Key)
ScopedHashTableIterator & operator++()
ScopedHashTableScope & operator=(ScopedHashTableScope &)=delete
ScopedHashTableScope(ScopedHashTable< K, V, KInfo, AllocatorTy > &HT)
ScopedHashTableIterator(ScopedHashTableVal< K, V > *node)
ScopedHashTableIterator< K, V, KInfo > iterator
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
void Destroy(AllocatorTy &Allocator)
ScopedHashTable()=default
const ScopedHashTableScope * getParentScope() const
V lookup(const K &Key) const