30#ifndef LLVM_ADT_SCOPEDHASHTABLE_H
31#define LLVM_ADT_SCOPEDHASHTABLE_H
42template <
typename K,
typename V,
typename KInfo = DenseMapInfo<K>,
43 typename AllocatorTy = MallocAllocator>
46template <
typename K,
typename V>
47class ScopedHashTableVal {
48 ScopedHashTableVal *NextInScope;
49 ScopedHashTableVal *NextForKey;
50 ScopedHashTableVal *PreInScope;
54 ScopedHashTableVal(
const K &key,
const V &val) :
Key(key), Val(val) {}
66 template <
typename AllocatorTy>
67 static ScopedHashTableVal *
Create(ScopedHashTableVal *nextInScope,
68 ScopedHashTableVal *nextForKey,
69 const K &key,
const V &val,
71 ScopedHashTableVal *New =
Allocator.template Allocate<ScopedHashTableVal>();
73 new (New) ScopedHashTableVal(key, val);
74 New->NextInScope = nextInScope;
75 New->NextForKey = nextForKey;
76 New->PreInScope =
nullptr;
78 nextInScope->PreInScope = New;
84 this->~ScopedHashTableVal();
88 template <
typename AllocatorTy>
89 static void erase(ScopedHashTableVal<K, V> *&ThisEntry,
91 ScopedHashTableVal<K, V> *ToDestroy = ThisEntry;
92 ScopedHashTableVal<K, V> *NextInScope = ThisEntry->NextInScope;
93 ScopedHashTableVal<K, V> *PrevInScope = ThisEntry->PreInScope;
95 PrevInScope->NextInScope = NextInScope;
97 NextInScope->PreInScope = PrevInScope;
98 ThisEntry = ThisEntry->NextForKey;
103template <
typename K,
typename V,
typename KInfo = DenseMapInfo<K>,
104 typename AllocatorTy = MallocAllocator>
130 return LastValInScope;
134 LastValInScope = Val;
138template <
typename K,
typename V,
typename KInfo = DenseMapInfo<K>>
146 assert(Node &&
"Dereference end()");
147 return Node->getValue();
150 return &Node->getValue();
154 return Node ==
RHS.Node;
157 return Node !=
RHS.Node;
161 assert(Node &&
"incrementing past end()");
162 Node = Node->getNextForKey();
170template <
typename K,
typename V,
typename KInfo,
typename AllocatorTy>
196 assert(!CurScope && TopLevelMap.empty() &&
"Scope imbalance!");
200 using AllocTy::getAllocator;
204 return TopLevelMap.count(
Key);
208 auto I = TopLevelMap.find(
Key);
209 if (
I != TopLevelMap.end())
210 return I->second->getValue();
224 auto I = TopLevelMap.find(
Key);
225 if (
I == TopLevelMap.end())
return end();
237 assert(S &&
"No scope active!");
241 S->setLastValInScope(KeyEntry);
244 void erase(
const K &key) { CurScope->erase(key); }
249template <
typename K,
typename V,
typename KInfo,
typename Allocator>
252 PrevScope = HT.CurScope;
254 LastValInScope =
nullptr;
257template <
typename K,
typename V,
typename KInfo,
typename Allocator>
259 assert(HT.CurScope ==
this &&
"Scope imbalance!");
260 HT.CurScope = PrevScope;
265 if (!ThisEntry->getNextForKey()) {
266 assert(HT.TopLevelMap[ThisEntry->getKey()] == ThisEntry &&
268 HT.TopLevelMap.erase(ThisEntry->getKey());
271 assert(KeyEntry == ThisEntry &&
"Scope imbalance!");
276 LastValInScope = ThisEntry->getNextInScope();
279 ThisEntry->Destroy(HT.getAllocator());
288template <
typename K,
typename V,
typename KInfo,
typename Allocator>
290 auto It = HT.TopLevelMap.find(
Key);
291 if (It == HT.TopLevelMap.end())
300 if (ThisEntry == S->LastValInScope) {
307 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")
#define LLVM_ATTRIBUTE_WARN_UNUSED
This file defines DenseMapInfo traits for DenseMap.
This file defines the DenseMap class.
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 MachineInstr *&Key, const unsigned &Val)
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()
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ATTRIBUTE_VISIBILITY_DEFAULT AnalysisKey InnerAnalysisManagerProxy< AnalysisManagerT, IRUnitT, ExtraArgTs... >::Key