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;
113 LastValInScope = Val;
117 template <
typename K,
typename V,
typename KInfo = DenseMapInfo<K>>
125 assert(Node &&
"Dereference end()");
126 return Node->getValue();
129 return &Node->getValue();
133 return Node == RHS.Node;
136 return Node != RHS.Node;
140 assert(Node &&
"incrementing past end()");
141 Node = Node->getNextForKey();
149 template <
typename K,
typename V,
typename KInfo,
typename AllocatorTy>
150 class ScopedHashTable {
173 assert(!CurScope && TopLevelMap.empty() &&
"Scope imbalance!");
182 return TopLevelMap.count(Key);
187 if (I != TopLevelMap.end())
188 return I->second->getValue();
193 void insert(
const K &Key,
const V &Val) {
203 TopLevelMap.find(Key);
204 if (I == TopLevelMap.end())
return end();
216 assert(S &&
"No scope active!");
218 KeyEntry =
ValTy::Create(S->getLastValInScope(), KeyEntry, Key, Val,
220 S->setLastValInScope(KeyEntry);
226 template <
typename K,
typename V,
typename KInfo,
typename Allocator>
229 PrevScope = HT.CurScope;
231 LastValInScope =
nullptr;
234 template <
typename K,
typename V,
typename KInfo,
typename Allocator>
236 assert(HT.CurScope ==
this &&
"Scope imbalance!");
237 HT.CurScope = PrevScope;
242 if (!ThisEntry->getNextForKey()) {
243 assert(HT.TopLevelMap[ThisEntry->getKey()] == ThisEntry &&
245 HT.TopLevelMap.erase(ThisEntry->getKey());
248 assert(KeyEntry == ThisEntry &&
"Scope imbalance!");
256 ThisEntry->
Destroy(HT.getAllocator());
262 #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
ScopedHashTableScope< K, V, KInfo, AllocatorTy > ScopeTy
ScopeTy - This is a helpful typedef that allows clients to get easy access to the name of the scope f...
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
Greedy Register Allocator
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)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
void Destroy(AllocatorTy &Allocator)
ScopedHashTable()=default
ScopedHashTableIterator< K, V, KInfo > iterator
static GCRegistry::Add< ErlangGC > A("erlang","erlang-compatible garbage collector")
const ScopedHashTableScope * getParentScope() const