-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[ADT] Add roundUpNumBuckets to DenseMap (NFC) #168301
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] Add roundUpNumBuckets to DenseMap (NFC) #168301
Conversation
This patch adds computeNumBuckets, a helper function to compute the number of buckets. This is part of the effort outlined in llvm#168255. This makes it easier to move the core logic of grow() to DenseMapBase::grow().
|
@llvm/pr-subscribers-llvm-adt Author: Kazu Hirata (kazutakahirata) ChangesThis patch adds computeNumBuckets, a helper function to compute the This is part of the effort outlined in #168255. This makes it easier Full diff: https://github.com/llvm/llvm-project/pull/168301.diff 1 Files Affected:
diff --git a/llvm/include/llvm/ADT/DenseMap.h b/llvm/include/llvm/ADT/DenseMap.h
index 86592f12ce62c..152b6a237357d 100644
--- a/llvm/include/llvm/ADT/DenseMap.h
+++ b/llvm/include/llvm/ADT/DenseMap.h
@@ -556,7 +556,10 @@ class DenseMapBase : public DebugEpochBase {
return llvm::make_range(getBuckets(), getBucketsEnd());
}
- void grow(unsigned AtLeast) { derived().grow(AtLeast); }
+ void grow(unsigned AtLeast) {
+ AtLeast = derived().computeNumBuckets(AtLeast);
+ derived().grow(AtLeast);
+ }
template <typename LookupKeyT>
BucketT *findBucketForInsertion(const LookupKeyT &Lookup,
@@ -840,8 +843,11 @@ class DenseMap : public DenseMapBase<DenseMap<KeyT, ValueT, KeyInfoT, BucketT>,
NumBuckets = 0;
}
+ static unsigned computeNumBuckets(unsigned NumBuckets) {
+ return std::max(64u, static_cast<unsigned>(NextPowerOf2(NumBuckets - 1)));
+ }
+
void grow(unsigned AtLeast) {
- AtLeast = std::max<unsigned>(64, NextPowerOf2(AtLeast - 1));
DenseMap Tmp(AtLeast, typename BaseT::ExactBucketCount{});
Tmp.moveFrom(*this);
swapImpl(Tmp);
@@ -1106,10 +1112,14 @@ class SmallDenseMap
new (getLargeRep()) LargeRep{nullptr, 0};
}
- void grow(unsigned AtLeast) {
- if (AtLeast > InlineBuckets)
- AtLeast = std::max<unsigned>(64, NextPowerOf2(AtLeast - 1));
+ static unsigned computeNumBuckets(unsigned NumBuckets) {
+ if (NumBuckets > InlineBuckets)
+ NumBuckets =
+ std::max(64u, static_cast<unsigned>(NextPowerOf2(NumBuckets - 1)));
+ return NumBuckets;
+ }
+ void grow(unsigned AtLeast) {
SmallDenseMap Tmp(AtLeast, typename BaseT::ExactBucketCount{});
Tmp.moveFrom(*this);
|
s-barannikov
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Few suggestions
s-barannikov
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
|
+0.35% regression on instructions:u when building with GCC: http://llvm-compile-time-tracker.com/compare.php?from=6152a8b31003d38eefb5dd9023a6c7e4e4e09ac4&to=4206558f715b7a67daa9c39528d04106f88612b4&stat=instructions:u |
This patch adds computeNumBuckets, a helper function to compute the
number of buckets.
This is part of the effort outlined in #168255. This makes it easier
to move the core logic of grow() to DenseMapBase::grow().