14
14
#define LLVM_ADT_DENSEMAP_H
15
15
16
16
#include " llvm/ADT/DenseMapInfo.h"
17
- #include " llvm/ADT/EpochTracker.h"
18
17
#include " llvm/Support/AlignOf.h"
19
18
#include " llvm/Support/Compiler.h"
20
19
#include " llvm/Support/MathExtras.h"
21
20
#include " llvm/Support/MemAlloc.h"
22
- #include " llvm/Support/ReverseIteration.h"
23
21
#include " llvm/Support/type_traits.h"
24
22
#include < algorithm>
25
23
#include < cassert>
@@ -58,7 +56,7 @@ class DenseMapIterator;
58
56
59
57
template <typename DerivedT, typename KeyT, typename ValueT, typename KeyInfoT,
60
58
typename BucketT>
61
- class DenseMapBase : public DebugEpochBase {
59
+ class DenseMapBase {
62
60
template <typename T>
63
61
using const_arg_type_t = typename const_pointer_or_const_ref<T>::type;
64
62
@@ -77,22 +75,18 @@ class DenseMapBase : public DebugEpochBase {
77
75
// empty buckets.
78
76
if (empty ())
79
77
return end ();
80
- if (shouldReverseIterate<KeyT>())
81
- return makeIterator (getBucketsEnd () - 1 , getBuckets (), *this );
82
- return makeIterator (getBuckets (), getBucketsEnd (), *this );
78
+ return makeIterator (getBuckets (), getBucketsEnd ());
83
79
}
84
80
inline iterator end () {
85
- return makeIterator (getBucketsEnd (), getBucketsEnd (), * this , true );
81
+ return makeIterator (getBucketsEnd (), getBucketsEnd (), true );
86
82
}
87
83
inline const_iterator begin () const {
88
84
if (empty ())
89
85
return end ();
90
- if (shouldReverseIterate<KeyT>())
91
- return makeConstIterator (getBucketsEnd () - 1 , getBuckets (), *this );
92
- return makeConstIterator (getBuckets (), getBucketsEnd (), *this );
86
+ return makeConstIterator (getBuckets (), getBucketsEnd ());
93
87
}
94
88
inline const_iterator end () const {
95
- return makeConstIterator (getBucketsEnd (), getBucketsEnd (), * this , true );
89
+ return makeConstIterator (getBucketsEnd (), getBucketsEnd (), true );
96
90
}
97
91
98
92
LLVM_NODISCARD bool empty () const {
@@ -104,13 +98,11 @@ class DenseMapBase : public DebugEpochBase {
104
98
// / before resizing again.
105
99
void reserve (size_type NumEntries) {
106
100
auto NumBuckets = getMinBucketToReserveForEntries (NumEntries);
107
- incrementEpoch ();
108
101
if (NumBuckets > getNumBuckets ())
109
102
grow (NumBuckets);
110
103
}
111
104
112
105
void clear () {
113
- incrementEpoch ();
114
106
if (getNumEntries () == 0 && getNumTombstones () == 0 ) return ;
115
107
116
108
// If the capacity of the array is huge, and the # elements used is small,
@@ -151,19 +143,13 @@ class DenseMapBase : public DebugEpochBase {
151
143
iterator find (const_arg_type_t <KeyT> Val) {
152
144
BucketT *TheBucket;
153
145
if (LookupBucketFor (Val, TheBucket))
154
- return makeIterator (TheBucket,
155
- shouldReverseIterate<KeyT>() ? getBuckets ()
156
- : getBucketsEnd (),
157
- *this , true );
146
+ return makeIterator (TheBucket, getBucketsEnd (), true );
158
147
return end ();
159
148
}
160
149
const_iterator find (const_arg_type_t <KeyT> Val) const {
161
150
const BucketT *TheBucket;
162
151
if (LookupBucketFor (Val, TheBucket))
163
- return makeConstIterator (TheBucket,
164
- shouldReverseIterate<KeyT>() ? getBuckets ()
165
- : getBucketsEnd (),
166
- *this , true );
152
+ return makeConstIterator (TheBucket, getBucketsEnd (), true );
167
153
return end ();
168
154
}
169
155
@@ -176,20 +162,14 @@ class DenseMapBase : public DebugEpochBase {
176
162
iterator find_as (const LookupKeyT &Val) {
177
163
BucketT *TheBucket;
178
164
if (LookupBucketFor (Val, TheBucket))
179
- return makeIterator (TheBucket,
180
- shouldReverseIterate<KeyT>() ? getBuckets ()
181
- : getBucketsEnd (),
182
- *this , true );
165
+ return makeIterator (TheBucket, getBucketsEnd (), true );
183
166
return end ();
184
167
}
185
168
template <class LookupKeyT >
186
169
const_iterator find_as (const LookupKeyT &Val) const {
187
170
const BucketT *TheBucket;
188
171
if (LookupBucketFor (Val, TheBucket))
189
- return makeConstIterator (TheBucket,
190
- shouldReverseIterate<KeyT>() ? getBuckets ()
191
- : getBucketsEnd (),
192
- *this , true );
172
+ return makeConstIterator (TheBucket, getBucketsEnd (), true );
193
173
return end ();
194
174
}
195
175
@@ -223,22 +203,13 @@ class DenseMapBase : public DebugEpochBase {
223
203
std::pair<iterator, bool > try_emplace (KeyT &&Key, Ts &&... Args) {
224
204
BucketT *TheBucket;
225
205
if (LookupBucketFor (Key, TheBucket))
226
- return std::make_pair (makeIterator (TheBucket,
227
- shouldReverseIterate<KeyT>()
228
- ? getBuckets ()
229
- : getBucketsEnd (),
230
- *this , true ),
206
+ return std::make_pair (makeIterator (TheBucket, getBucketsEnd (), true ),
231
207
false ); // Already in map.
232
208
233
209
// Otherwise, insert the new element.
234
210
TheBucket =
235
211
InsertIntoBucket (TheBucket, std::move (Key), std::forward<Ts>(Args)...);
236
- return std::make_pair (makeIterator (TheBucket,
237
- shouldReverseIterate<KeyT>()
238
- ? getBuckets ()
239
- : getBucketsEnd (),
240
- *this , true ),
241
- true );
212
+ return std::make_pair (makeIterator (TheBucket, getBucketsEnd (), true ), true );
242
213
}
243
214
244
215
// Inserts key,value pair into the map if the key isn't already in the map.
@@ -248,21 +219,12 @@ class DenseMapBase : public DebugEpochBase {
248
219
std::pair<iterator, bool > try_emplace (const KeyT &Key, Ts &&... Args) {
249
220
BucketT *TheBucket;
250
221
if (LookupBucketFor (Key, TheBucket))
251
- return std::make_pair (makeIterator (TheBucket,
252
- shouldReverseIterate<KeyT>()
253
- ? getBuckets ()
254
- : getBucketsEnd (),
255
- *this , true ),
222
+ return std::make_pair (makeIterator (TheBucket, getBucketsEnd (), true ),
256
223
false ); // Already in map.
257
224
258
225
// Otherwise, insert the new element.
259
226
TheBucket = InsertIntoBucket (TheBucket, Key, std::forward<Ts>(Args)...);
260
- return std::make_pair (makeIterator (TheBucket,
261
- shouldReverseIterate<KeyT>()
262
- ? getBuckets ()
263
- : getBucketsEnd (),
264
- *this , true ),
265
- true );
227
+ return std::make_pair (makeIterator (TheBucket, getBucketsEnd (), true ), true );
266
228
}
267
229
268
230
// / Alternate version of insert() which allows a different, and possibly
@@ -275,21 +237,13 @@ class DenseMapBase : public DebugEpochBase {
275
237
const LookupKeyT &Val) {
276
238
BucketT *TheBucket;
277
239
if (LookupBucketFor (Val, TheBucket))
278
- return std::make_pair (makeIterator (TheBucket,
279
- shouldReverseIterate<KeyT>()
280
- ? getBuckets ()
281
- : getBucketsEnd (),
282
- *this , true ),
240
+ return std::make_pair (makeIterator (TheBucket, getBucketsEnd (), *this , true ),
283
241
false ); // Already in map.
284
242
285
243
// Otherwise, insert the new element.
286
244
TheBucket = InsertIntoBucketWithLookup (TheBucket, std::move (KV.first ),
287
245
std::move (KV.second ), Val);
288
- return std::make_pair (makeIterator (TheBucket,
289
- shouldReverseIterate<KeyT>()
290
- ? getBuckets ()
291
- : getBucketsEnd (),
292
- *this , true ),
246
+ return std::make_pair (makeIterator (TheBucket, getBucketsEnd (), *this , true ),
293
247
true );
294
248
}
295
249
@@ -462,24 +416,13 @@ class DenseMapBase : public DebugEpochBase {
462
416
}
463
417
464
418
private:
465
- iterator makeIterator (BucketT *P, BucketT *E,
466
- DebugEpochBase &Epoch,
467
- bool NoAdvance=false ) {
468
- if (shouldReverseIterate<KeyT>()) {
469
- BucketT *B = P == getBucketsEnd () ? getBuckets () : P + 1 ;
470
- return iterator (B, E, Epoch, NoAdvance);
471
- }
472
- return iterator (P, E, Epoch, NoAdvance);
419
+ iterator makeIterator (BucketT *P, BucketT *E, bool NoAdvance=false ) {
420
+ return iterator (P, E, NoAdvance);
473
421
}
474
422
475
423
const_iterator makeConstIterator (const BucketT *P, const BucketT *E,
476
- const DebugEpochBase &Epoch,
477
424
const bool NoAdvance=false ) const {
478
- if (shouldReverseIterate<KeyT>()) {
479
- const BucketT *B = P == getBucketsEnd () ? getBuckets () : P + 1 ;
480
- return const_iterator (B, E, Epoch, NoAdvance);
481
- }
482
- return const_iterator (P, E, Epoch, NoAdvance);
425
+ return const_iterator (P, E, NoAdvance);
483
426
}
484
427
485
428
unsigned getNumEntries () const {
@@ -565,8 +508,6 @@ class DenseMapBase : public DebugEpochBase {
565
508
template <typename LookupKeyT>
566
509
BucketT *InsertIntoBucketImpl (const KeyT &Key, const LookupKeyT &Lookup,
567
510
BucketT *TheBucket) {
568
- incrementEpoch ();
569
-
570
511
// If the load of the hash table is more than 3/4, or if fewer than 1/8 of
571
512
// the buckets are empty (meaning that many are filled with tombstones),
572
513
// grow the table.
@@ -757,8 +698,6 @@ class DenseMap : public DenseMapBase<DenseMap<KeyT, ValueT, KeyInfoT, BucketT>,
757
698
}
758
699
759
700
void swap (DenseMap& RHS) {
760
- this ->incrementEpoch ();
761
- RHS.incrementEpoch ();
762
701
std::swap (Buckets, RHS.Buckets );
763
702
std::swap (NumEntries, RHS.NumEntries );
764
703
std::swap (NumTombstones, RHS.NumTombstones );
@@ -1190,7 +1129,7 @@ class SmallDenseMap
1190
1129
1191
1130
template <typename KeyT, typename ValueT, typename KeyInfoT, typename Bucket,
1192
1131
bool IsConst>
1193
- class DenseMapIterator : DebugEpochBase::HandleBase {
1132
+ class DenseMapIterator {
1194
1133
friend class DenseMapIterator <KeyT, ValueT, KeyInfoT, Bucket, true >;
1195
1134
friend class DenseMapIterator <KeyT, ValueT, KeyInfoT, Bucket, false >;
1196
1135
@@ -1209,16 +1148,9 @@ class DenseMapIterator : DebugEpochBase::HandleBase {
1209
1148
public:
1210
1149
DenseMapIterator () = default ;
1211
1150
1212
- DenseMapIterator (pointer Pos, pointer E, const DebugEpochBase &Epoch,
1213
- bool NoAdvance = false )
1214
- : DebugEpochBase::HandleBase(&Epoch), Ptr(Pos), End(E) {
1215
- assert (isHandleInSync () && " invalid construction!" );
1216
-
1151
+ DenseMapIterator (pointer Pos, pointer E, bool NoAdvance = false )
1152
+ : Ptr(Pos), End(E) {
1217
1153
if (NoAdvance) return ;
1218
- if (shouldReverseIterate<KeyT>()) {
1219
- RetreatPastEmptyBuckets ();
1220
- return ;
1221
- }
1222
1154
AdvancePastEmptyBuckets ();
1223
1155
}
1224
1156
@@ -1229,29 +1161,19 @@ class DenseMapIterator : DebugEpochBase::HandleBase {
1229
1161
typename = std::enable_if_t <!IsConstSrc && IsConst>>
1230
1162
DenseMapIterator (
1231
1163
const DenseMapIterator<KeyT, ValueT, KeyInfoT, Bucket, IsConstSrc> &I)
1232
- : DebugEpochBase::HandleBase(I), Ptr(I.Ptr), End(I.End) {}
1164
+ : Ptr(I.Ptr), End(I.End) {}
1233
1165
1234
1166
reference operator *() const {
1235
- assert (isHandleInSync () && " invalid iterator access!" );
1236
1167
assert (Ptr != End && " dereferencing end() iterator" );
1237
- if (shouldReverseIterate<KeyT>())
1238
- return Ptr[-1 ];
1239
1168
return *Ptr;
1240
1169
}
1241
1170
pointer operator ->() const {
1242
- assert (isHandleInSync () && " invalid iterator access!" );
1243
1171
assert (Ptr != End && " dereferencing end() iterator" );
1244
- if (shouldReverseIterate<KeyT>())
1245
- return &(Ptr[-1 ]);
1246
1172
return Ptr;
1247
1173
}
1248
1174
1249
1175
friend bool operator ==(const DenseMapIterator &LHS,
1250
1176
const DenseMapIterator &RHS) {
1251
- assert ((!LHS.Ptr || LHS.isHandleInSync ()) && " handle not in sync!" );
1252
- assert ((!RHS.Ptr || RHS.isHandleInSync ()) && " handle not in sync!" );
1253
- assert (LHS.getEpochAddress () == RHS.getEpochAddress () &&
1254
- " comparing incomparable iterators!" );
1255
1177
return LHS.Ptr == RHS.Ptr ;
1256
1178
}
1257
1179
@@ -1261,19 +1183,12 @@ class DenseMapIterator : DebugEpochBase::HandleBase {
1261
1183
}
1262
1184
1263
1185
inline DenseMapIterator& operator ++() { // Preincrement
1264
- assert (isHandleInSync () && " invalid iterator access!" );
1265
1186
assert (Ptr != End && " incrementing end() iterator" );
1266
- if (shouldReverseIterate<KeyT>()) {
1267
- --Ptr;
1268
- RetreatPastEmptyBuckets ();
1269
- return *this ;
1270
- }
1271
1187
++Ptr;
1272
1188
AdvancePastEmptyBuckets ();
1273
1189
return *this ;
1274
1190
}
1275
1191
DenseMapIterator operator ++(int ) { // Postincrement
1276
- assert (isHandleInSync () && " invalid iterator access!" );
1277
1192
DenseMapIterator tmp = *this ; ++*this ; return tmp;
1278
1193
}
1279
1194
0 commit comments