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;
52 ScopedHashTableVal(
const K &key,
const V &val) :
Key(key), Val(val) {}
55 const K &
getKey()
const {
return Key; }
63 template <
typename AllocatorTy>
64 static ScopedHashTableVal *
Create(ScopedHashTableVal *nextInScope,
65 ScopedHashTableVal *nextForKey,
66 const K &key,
const V &val,
68 ScopedHashTableVal *New =
Allocator.template Allocate<ScopedHashTableVal>();
70 new (New) ScopedHashTableVal(key, val);
71 New->NextInScope = nextInScope;
72 New->NextForKey = nextForKey;
78 this->~ScopedHashTableVal();
83template <
typename K,
typename V,
typename KInfo = DenseMapInfo<K>,
84 typename AllocatorTy = MallocAllocator>
109 return LastValInScope;
112 void setLastValInScope(ScopedHashTableVal<K, V> *Val) {
113 LastValInScope = Val;
117template <
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();
149template <
typename K,
typename V,
typename KInfo,
typename AllocatorTy>
174 assert(!CurScope && TopLevelMap.empty() &&
"Scope imbalance!");
182 return TopLevelMap.count(
Key);
186 auto I = TopLevelMap.find(
Key);
187 if (
I != TopLevelMap.end())
188 return I->second->getValue();
203 TopLevelMap.find(
Key);
204 if (
I == TopLevelMap.end())
return end();
216 assert(S &&
"No scope active!");
220 S->setLastValInScope(KeyEntry);
226template <
typename K,
typename V,
typename KInfo,
typename Allocator>
229 PrevScope = HT.CurScope;
231 LastValInScope =
nullptr;
234template <
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!");
253 LastValInScope = ThisEntry->getNextInScope();
256 ThisEntry->Destroy(HT.getAllocator());
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
ScopedHashTableScope(ScopedHashTableScope &)=delete
const ScopedHashTableScope * getParentScope() const
ScopedHashTableScope * getParentScope()
ScopedHashTableScope(ScopedHashTable< K, V, KInfo, AllocatorTy > &HT)
ScopedHashTableVal * getNextInScope()
ScopedHashTableVal * getNextForKey()
static ScopedHashTableVal * Create(ScopedHashTableVal *nextInScope, ScopedHashTableVal *nextForKey, const K &key, const V &val, AllocatorTy &Allocator)
const ScopedHashTableVal * getNextForKey() const
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 - This is a helpful typedef that allows clients to get easy access to the name of the scope f...
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