LLVM: include/llvm/ADT/ScopedHashTable.h Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30#ifndef LLVM_ADT_SCOPEDHASHTABLE_H
31#define LLVM_ADT_SCOPEDHASHTABLE_H
32
36#include
37#include
38
39namespace llvm {
40
41template <typename K, typename V, typename KInfo = DenseMapInfo,
42 typename AllocatorTy = MallocAllocator>
44
45template <typename K, typename V>
46class ScopedHashTableVal {
47 ScopedHashTableVal *NextInScope;
48 ScopedHashTableVal *NextForKey;
49 K Key;
50 V Val;
51
52 ScopedHashTableVal(const K &key, const V &val) : Key(key), Val(val) {}
53
54public:
55 const K &getKey() const { return Key; }
56 const V &getValue() const { return Val; }
58
59 ScopedHashTableVal *getNextForKey() { return NextForKey; }
60 const ScopedHashTableVal *getNextForKey() const { return NextForKey; }
62
63 template
64 static ScopedHashTableVal *Create(ScopedHashTableVal *nextInScope,
65 ScopedHashTableVal *nextForKey,
66 const K &key, const V &val,
68 ScopedHashTableVal *New = Allocator.template Allocate();
69
70 new (New) ScopedHashTableVal(key, val);
71 New->NextInScope = nextInScope;
72 New->NextForKey = nextForKey;
73 return New;
74 }
75
76 template void Destroy(AllocatorTy &Allocator) {
77
78 this->~ScopedHashTableVal();
80 }
81};
82
83template <typename K, typename V, typename KInfo = DenseMapInfo,
84 typename AllocatorTy = MallocAllocator>
86
88
89
91
92
93
95
96public:
101
104
105private:
107
109 return LastValInScope;
110 }
111
112 void setLastValInScope(ScopedHashTableVal<K, V> *Val) {
113 LastValInScope = Val;
114 }
115};
116
117template <typename K, typename V, typename KInfo = DenseMapInfo>
120
121public:
123
125 assert(Node && "Dereference end()");
126 return Node->getValue();
127 }
129 return &Node->getValue();
130 }
131
133 return Node == RHS.Node;
134 }
136 return Node != RHS.Node;
137 }
138
140 assert(Node && "incrementing past end()");
141 Node = Node->getNextForKey();
142 return *this;
143 }
147};
148
149template <typename K, typename V, typename KInfo, typename AllocatorTy>
152
153public:
154
155
158
159private:
161
163
165 ScopeTy *CurScope = nullptr;
166
167public:
172
174 assert(!CurScope && TopLevelMap.empty() && "Scope imbalance!");
175 }
176
177
179
180
182 return TopLevelMap.count(Key);
183 }
184
186 auto I = TopLevelMap.find(Key);
187 if (I != TopLevelMap.end())
188 return I->second->getValue();
189
190 return V();
191 }
192
196
198
200
203 TopLevelMap.find(Key);
204 if (I == TopLevelMap.end()) return end();
206 }
207
210
211
212
213
214
216 assert(S && "No scope active!");
218 KeyEntry = ValTy::Create(S->getLastValInScope(), KeyEntry, Key, Val,
220 S->setLastValInScope(KeyEntry);
221 }
222};
223
224
225
226template <typename K, typename V, typename KInfo, typename Allocator>
229 PrevScope = HT.CurScope;
230 HT.CurScope = this;
231 LastValInScope = nullptr;
232}
233
234template <typename K, typename V, typename KInfo, typename Allocator>
236 assert(HT.CurScope == this && "Scope imbalance!");
237 HT.CurScope = PrevScope;
238
239
241
242 if (!ThisEntry->getNextForKey()) {
243 assert(HT.TopLevelMap[ThisEntry->getKey()] == ThisEntry &&
244 "Scope imbalance!");
245 HT.TopLevelMap.erase(ThisEntry->getKey());
246 } else {
248 assert(KeyEntry == ThisEntry && "Scope imbalance!");
250 }
251
252
253 LastValInScope = ThisEntry->getNextInScope();
254
255
256 ThisEntry->Destroy(HT.getAllocator());
257 }
258}
259
260}
261
262#endif
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
Definition ScopedHashTable.h:118
ScopedHashTableIterator(ScopedHashTableVal< K, V > *node)
Definition ScopedHashTable.h:122
bool operator==(const ScopedHashTableIterator &RHS) const
Definition ScopedHashTable.h:132
ScopedHashTableIterator & operator++()
Definition ScopedHashTable.h:139
bool operator!=(const ScopedHashTableIterator &RHS) const
Definition ScopedHashTable.h:135
V & operator*() const
Definition ScopedHashTable.h:124
V * operator->() const
Definition ScopedHashTable.h:128
ScopedHashTableIterator operator++(int)
Definition ScopedHashTable.h:144
Definition ScopedHashTable.h:85
ScopedHashTableScope & operator=(ScopedHashTableScope &)=delete
~ScopedHashTableScope()
Definition ScopedHashTable.h:235
ScopedHashTableScope(ScopedHashTableScope &)=delete
const ScopedHashTableScope * getParentScope() const
Definition ScopedHashTable.h:103
ScopedHashTableScope * getParentScope()
Definition ScopedHashTable.h:102
ScopedHashTableScope(ScopedHashTable< K, V, KInfo, AllocatorTy > &HT)
Definition ScopedHashTable.h:46
ScopedHashTableVal * getNextInScope()
Definition ScopedHashTable.h:61
V & getValue()
Definition ScopedHashTable.h:57
ScopedHashTableVal * getNextForKey()
Definition ScopedHashTable.h:59
static ScopedHashTableVal * Create(ScopedHashTableVal *nextInScope, ScopedHashTableVal *nextForKey, const K &key, const V &val, AllocatorTy &Allocator)
Definition ScopedHashTable.h:64
const ScopedHashTableVal * getNextForKey() const
Definition ScopedHashTable.h:60
const K & getKey() const
Definition ScopedHashTable.h:55
const V & getValue() const
Definition ScopedHashTable.h:56
void Destroy(AllocatorTy &Allocator)
Definition ScopedHashTable.h:76
Definition ScopedHashTable.h:150
ScopeTy * getCurScope()
Definition ScopedHashTable.h:208
iterator begin(const K &Key)
Definition ScopedHashTable.h:201
unsigned size_type
Definition ScopedHashTable.h:157
ScopedHashTable(AllocatorTy A)
Definition ScopedHashTable.h:169
ScopedHashTable()=default
iterator end()
Definition ScopedHashTable.h:199
~ScopedHashTable()
Definition ScopedHashTable.h:173
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...
Definition ScopedHashTable.h:215
size_type count(const K &Key) const
Return 1 if the specified key is in the table, 0 otherwise.
Definition ScopedHashTable.h:181
const ScopeTy * getCurScope() const
Definition ScopedHashTable.h:209
void insert(const K &Key, const V &Val)
Definition ScopedHashTable.h:193
V lookup(const K &Key) const
Definition ScopedHashTable.h:185
ScopedHashTableScope< K, V, KInfo, AllocatorTy > ScopeTy
ScopeTy - A type alias for easy access to the name of the scope for this hash table.
Definition ScopedHashTable.h:156
ScopedHashTable(const ScopedHashTable &)=delete
ScopedHashTable & operator=(const ScopedHashTable &)=delete
ScopedHashTableIterator< K, V, KInfo > iterator
Definition ScopedHashTable.h:197
AllocatorTy & getAllocator()
AllocatorTy & getAllocator()
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ATTRIBUTE_VISIBILITY_DEFAULT AnalysisKey InnerAnalysisManagerProxy< AnalysisManagerT, IRUnitT, ExtraArgTs... >::Key