-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[ADT] Move initWithExactBucketCount to DenseMapBase (NFC) #168283
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ADT] Move initWithExactBucketCount to DenseMapBase (NFC) #168283
Conversation
This patch moves initWithExactBucketCount and ExactBucketCount to
DenseMapBase to share more code.
Since SmallDenseMap::allocateBuckets always returns true,
initWithExactBucketCount is equivalent to:
void initWithExactBucketCount(unsigned NewNumBuckets) {
allocateBuckets(NewNumBuckets);
initEmpty();
}
for SmallDenseMap.
Note that ExactBucketCount is not used within DenseMapBase yet.
This moves us closer to the storage policy idea outlined in llvm#168255.
|
@llvm/pr-subscribers-llvm-adt Author: Kazu Hirata (kazutakahirata) ChangesThis patch moves initWithExactBucketCount and ExactBucketCount to Since SmallDenseMap::allocateBuckets always returns true, void initWithExactBucketCount(unsigned NewNumBuckets) { for SmallDenseMap. Note that ExactBucketCount is not used within DenseMapBase yet. This moves us closer to the storage policy idea outlined in #168255. Full diff: https://github.com/llvm/llvm-project/pull/168283.diff 1 Files Affected:
diff --git a/llvm/include/llvm/ADT/DenseMap.h b/llvm/include/llvm/ADT/DenseMap.h
index 7926159c4c09c..86592f12ce62c 100644
--- a/llvm/include/llvm/ADT/DenseMap.h
+++ b/llvm/include/llvm/ADT/DenseMap.h
@@ -369,6 +369,17 @@ class DenseMapBase : public DebugEpochBase {
protected:
DenseMapBase() = default;
+ struct ExactBucketCount {};
+
+ void initWithExactBucketCount(unsigned NewNumBuckets) {
+ if (derived().allocateBuckets(NewNumBuckets)) {
+ initEmpty();
+ } else {
+ setNumEntries(0);
+ setNumTombstones(0);
+ }
+ }
+
void destroyAll() {
// No need to iterate through the buckets if both KeyT and ValueT are
// trivially destructible.
@@ -729,9 +740,8 @@ class DenseMap : public DenseMapBase<DenseMap<KeyT, ValueT, KeyInfoT, BucketT>,
unsigned NumTombstones;
unsigned NumBuckets;
- struct ExactBucketCount {};
- explicit DenseMap(unsigned NumBuckets, ExactBucketCount) {
- initWithExactBucketCount(NumBuckets);
+ explicit DenseMap(unsigned NumBuckets, typename BaseT::ExactBucketCount) {
+ this->initWithExactBucketCount(NumBuckets);
}
public:
@@ -818,18 +828,9 @@ class DenseMap : public DenseMapBase<DenseMap<KeyT, ValueT, KeyInfoT, BucketT>,
return true;
}
- void initWithExactBucketCount(unsigned NewNumBuckets) {
- if (allocateBuckets(NewNumBuckets)) {
- this->BaseT::initEmpty();
- } else {
- NumEntries = 0;
- NumTombstones = 0;
- }
- }
-
void init(unsigned InitNumEntries) {
auto InitBuckets = BaseT::getMinBucketToReserveForEntries(InitNumEntries);
- initWithExactBucketCount(InitBuckets);
+ this->initWithExactBucketCount(InitBuckets);
}
// Put the zombie instance in a known good state after a move.
@@ -841,7 +842,7 @@ class DenseMap : public DenseMapBase<DenseMap<KeyT, ValueT, KeyInfoT, BucketT>,
void grow(unsigned AtLeast) {
AtLeast = std::max<unsigned>(64, NextPowerOf2(AtLeast - 1));
- DenseMap Tmp(AtLeast, ExactBucketCount{});
+ DenseMap Tmp(AtLeast, typename BaseT::ExactBucketCount{});
Tmp.moveFrom(*this);
swapImpl(Tmp);
}
@@ -891,10 +892,8 @@ class SmallDenseMap
/// a large bucket. This union will be discriminated by the 'Small' bit.
AlignedCharArrayUnion<BucketT[InlineBuckets], LargeRep> storage;
- struct ExactBucketCount {};
- SmallDenseMap(unsigned NumBuckets, ExactBucketCount) {
- allocateBuckets(NumBuckets);
- this->BaseT::initEmpty();
+ SmallDenseMap(unsigned NumBuckets, typename BaseT::ExactBucketCount) {
+ this->initWithExactBucketCount(NumBuckets);
}
public:
@@ -1097,8 +1096,7 @@ class SmallDenseMap
void init(unsigned InitNumEntries) {
auto InitBuckets = BaseT::getMinBucketToReserveForEntries(InitNumEntries);
- allocateBuckets(InitBuckets);
- this->BaseT::initEmpty();
+ this->initWithExactBucketCount(InitBuckets);
}
// Put the zombie instance in a known good state after a move.
@@ -1112,7 +1110,7 @@ class SmallDenseMap
if (AtLeast > InlineBuckets)
AtLeast = std::max<unsigned>(64, NextPowerOf2(AtLeast - 1));
- SmallDenseMap Tmp(AtLeast, ExactBucketCount{});
+ SmallDenseMap Tmp(AtLeast, typename BaseT::ExactBucketCount{});
Tmp.moveFrom(*this);
if (Tmp.Small) {
|
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/27/builds/19022 Here is the relevant piece of the build log for the reference |
This patch moves initWithExactBucketCount and ExactBucketCount to
DenseMapBase to share more code.
Since SmallDenseMap::allocateBuckets always returns true,
initWithExactBucketCount is equivalent to:
void initWithExactBucketCount(unsigned NewNumBuckets) {
allocateBuckets(NewNumBuckets);
initEmpty();
}
for SmallDenseMap.
Note that ExactBucketCount is not used within DenseMapBase yet.
This moves us closer to the storage policy idea outlined in #168255.