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>
55 const K &
getKey()
const {
return Key; }
63 template <
typename AllocatorTy>
66 const K &key,
const V &val,
71 New->NextInScope = nextInScope;
72 New->NextForKey = nextForKey;
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>>
126 return Node->getValue();
129 return &
Node->getValue();
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();
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);
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!");
256 ThisEntry->
Destroy(HT.getAllocator());
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.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
iterator find(const_arg_type_t< KeyT > Val)
size_type count(const_arg_type_t< KeyT > Val) const
Return 1 if the specified key is in the map, 0 otherwise.
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
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.