30#ifndef LLVM_ADT_SCOPEDHASHTABLE_H
31#define LLVM_ADT_SCOPEDHASHTABLE_H
41template <
typename K,
typename V,
typename KInfo = DenseMapInfo<K>,
42 typename AllocatorTy = MallocAllocator>
45template <
typename K,
typename V>
46class ScopedHashTableVal {
47 ScopedHashTableVal *NextInScope;
48 ScopedHashTableVal *NextForKey;
49 ScopedHashTableVal *PreInScope;
53 ScopedHashTableVal(
const K &key,
const V &val) :
Key(key), Val(val) {}
56 const K &
getKey()
const {
return Key; }
65 template <
typename AllocatorTy>
66 static ScopedHashTableVal *
Create(ScopedHashTableVal *nextInScope,
67 ScopedHashTableVal *nextForKey,
68 const K &key,
const V &val,
70 ScopedHashTableVal *New =
Allocator.template Allocate<ScopedHashTableVal>();
72 new (New) ScopedHashTableVal(key, val);
73 New->NextInScope = nextInScope;
74 New->NextForKey = nextForKey;
75 New->PreInScope =
nullptr;
77 nextInScope->PreInScope = New;
83 this->~ScopedHashTableVal();
87 template <
typename AllocatorTy>
88 static void erase(ScopedHashTableVal<K, V> *&ThisEntry,
90 ScopedHashTableVal<K, V> *ToDestroy = ThisEntry;
91 ScopedHashTableVal<K, V> *NextInScope = ThisEntry->NextInScope;
92 ScopedHashTableVal<K, V> *PrevInScope = ThisEntry->PreInScope;
94 PrevInScope->NextInScope = NextInScope;
96 NextInScope->PreInScope = PrevInScope;
97 ThisEntry = ThisEntry->NextForKey;
102template <
typename K,
typename V,
typename KInfo = DenseMapInfo<K>,
103 typename AllocatorTy = MallocAllocator>
129 return LastValInScope;
133 LastValInScope = Val;
137template <
typename K,
typename V,
typename KInfo = DenseMapInfo<K>>
145 assert(Node &&
"Dereference end()");
146 return Node->getValue();
149 return &Node->getValue();
153 return Node ==
RHS.Node;
156 return Node !=
RHS.Node;
160 assert(Node &&
"incrementing past end()");
161 Node = Node->getNextForKey();
169template <
typename K,
typename V,
typename KInfo,
typename AllocatorTy>
194 assert(!CurScope && TopLevelMap.empty() &&
"Scope imbalance!");
202 return TopLevelMap.count(
Key);
206 auto I = TopLevelMap.find(
Key);
207 if (
I != TopLevelMap.end())
208 return I->second->getValue();
223 TopLevelMap.find(
Key);
224 if (
I == TopLevelMap.end())
return end();
236 assert(S &&
"No scope active!");
240 S->setLastValInScope(KeyEntry);
243 void erase(
const K &key) { CurScope->erase(key); }
248template <
typename K,
typename V,
typename KInfo,
typename Allocator>
251 PrevScope = HT.CurScope;
253 LastValInScope =
nullptr;
256template <
typename K,
typename V,
typename KInfo,
typename Allocator>
258 assert(HT.CurScope ==
this &&
"Scope imbalance!");
259 HT.CurScope = PrevScope;
264 if (!ThisEntry->getNextForKey()) {
265 assert(HT.TopLevelMap[ThisEntry->getKey()] == ThisEntry &&
267 HT.TopLevelMap.erase(ThisEntry->getKey());
270 assert(KeyEntry == ThisEntry &&
"Scope imbalance!");
275 LastValInScope = ThisEntry->getNextInScope();
278 ThisEntry->Destroy(HT.getAllocator());
287template <
typename K,
typename V,
typename KInfo,
typename Allocator>
289 auto It = HT.TopLevelMap.find(
Key);
290 if (It == HT.TopLevelMap.end())
299 if (ThisEntry == S->LastValInScope) {
306 HT.TopLevelMap.
erase(It);
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file defines MallocAllocator.
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
This file defines DenseMapInfo traits for DenseMap.
This file defines the DenseMap class.
DenseMapIterator< KeyT, ValueT, KeyInfoT, BucketT > iterator
ScopedHashTableIterator(ScopedHashTableVal< K, V > *node)
bool operator==(const ScopedHashTableIterator &RHS) const
ScopedHashTableIterator & operator++()
bool operator!=(const ScopedHashTableIterator &RHS) const
ScopedHashTableIterator operator++(int)
ScopedHashTableScope & operator=(ScopedHashTableScope &)=delete
void erase(const K &key)
This method undoes the latest binding of the given key, effectively reverting to the previous state f...
ScopedHashTableScope(ScopedHashTableScope &)=delete
const ScopedHashTableScope * getParentScope() const
ScopedHashTableScope * getParentScope()
ScopedHashTableScope(ScopedHashTable< K, V, KInfo, AllocatorTy > &HT)
ScopedHashTableVal * getNextInScope()
ScopedHashTableVal * getNextForKey()
ScopedHashTableVal * getPreInScope()
static ScopedHashTableVal * Create(ScopedHashTableVal *nextInScope, ScopedHashTableVal *nextForKey, const K &key, const V &val, AllocatorTy &Allocator)
const ScopedHashTableVal * getNextForKey() const
static void erase(ScopedHashTableVal< K, V > *&ThisEntry, AllocatorTy &Allocator)
const V & getValue() const
void Destroy(AllocatorTy &Allocator)
iterator begin(const K &Key)
ScopedHashTable(AllocatorTy A)
ScopedHashTable()=default
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...
size_type count(const K &Key) const
Return 1 if the specified key is in the table, 0 otherwise.
const ScopeTy * getCurScope() const
void insert(const K &Key, const V &Val)
V lookup(const K &Key) const
ScopedHashTableScope< K, V, KInfo, AllocatorTy > ScopeTy
ScopeTy - A type alias for easy access to the name of the scope for this hash table.
ScopedHashTable(const ScopedHashTable &)=delete
ScopedHashTable & operator=(const ScopedHashTable &)=delete
ScopedHashTableIterator< K, V, KInfo > iterator
AllocatorTy & getAllocator()
AllocatorTy & getAllocator()
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ATTRIBUTE_VISIBILITY_DEFAULT AnalysisKey InnerAnalysisManagerProxy< AnalysisManagerT, IRUnitT, ExtraArgTs... >::Key