[llvm] e490920 - [ADT] Remove KeyInfoT forwarders in DenseMap.h (NFC) (#165102)
via llvm-commits
llvm-commits at lists.llvm.org
Sat Oct 25 10:05:14 PDT 2025
Author: Kazu Hirata
Date: 2025-10-25T10:05:10-07:00
New Revision: e4909203feb2f6f4eccb42ed148cc39cedd5b524
URL: https://github.com/llvm/llvm-project/commit/e4909203feb2f6f4eccb42ed148cc39cedd5b524
DIFF: https://github.com/llvm/llvm-project/commit/e4909203feb2f6f4eccb42ed148cc39cedd5b524.diff
LOG: [ADT] Remove KeyInfoT forwarders in DenseMap.h (NFC) (#165102)
This patch removes getEmptyKey, getTombstoneKey, and getHashValue from
DenseMapBase. These forwarder methods do not really encapsulate
KeyInfoT. Many of their callers already mention KeyInfoT::isEqual for
example.
An existing static_assert is moved to another method. Note that it
must live in a method for type completeness reasons.
Added:
Modified:
llvm/include/llvm/ADT/DenseMap.h
Removed:
################################################################################
diff --git a/llvm/include/llvm/ADT/DenseMap.h b/llvm/include/llvm/ADT/DenseMap.h
index c784859081221..6d60d89be1c0f 100644
--- a/llvm/include/llvm/ADT/DenseMap.h
+++ b/llvm/include/llvm/ADT/DenseMap.h
@@ -130,13 +130,13 @@ class DenseMapBase : public DebugEpochBase {
return;
}
- const KeyT EmptyKey = getEmptyKey();
+ const KeyT EmptyKey = KeyInfoT::getEmptyKey();
if constexpr (std::is_trivially_destructible_v<ValueT>) {
// Use a simpler loop when values don't need destruction.
for (BucketT &B : buckets())
B.getFirst() = EmptyKey;
} else {
- const KeyT TombstoneKey = getTombstoneKey();
+ const KeyT TombstoneKey = KeyInfoT::getTombstoneKey();
unsigned NumEntries = getNumEntries();
for (BucketT &B : buckets()) {
if (!KeyInfoT::isEqual(B.getFirst(), EmptyKey)) {
@@ -314,7 +314,7 @@ class DenseMapBase : public DebugEpochBase {
return false; // not in map.
TheBucket->getSecond().~ValueT();
- TheBucket->getFirst() = getTombstoneKey();
+ TheBucket->getFirst() = KeyInfoT::getTombstoneKey();
decrementNumEntries();
incrementNumTombstones();
return true;
@@ -322,7 +322,7 @@ class DenseMapBase : public DebugEpochBase {
void erase(iterator I) {
BucketT *TheBucket = &*I;
TheBucket->getSecond().~ValueT();
- TheBucket->getFirst() = getTombstoneKey();
+ TheBucket->getFirst() = KeyInfoT::getTombstoneKey();
decrementNumEntries();
incrementNumTombstones();
}
@@ -362,7 +362,8 @@ class DenseMapBase : public DebugEpochBase {
if (getNumBuckets() == 0) // Nothing to do.
return;
- const KeyT EmptyKey = getEmptyKey(), TombstoneKey = getTombstoneKey();
+ const KeyT EmptyKey = KeyInfoT::getEmptyKey();
+ const KeyT TombstoneKey = KeyInfoT::getTombstoneKey();
for (BucketT &B : buckets()) {
if (!KeyInfoT::isEqual(B.getFirst(), EmptyKey) &&
!KeyInfoT::isEqual(B.getFirst(), TombstoneKey))
@@ -372,12 +373,14 @@ class DenseMapBase : public DebugEpochBase {
}
void initEmpty() {
+ static_assert(std::is_base_of_v<DenseMapBase, DerivedT>,
+ "Must pass the derived type to this template!");
setNumEntries(0);
setNumTombstones(0);
assert((getNumBuckets() & (getNumBuckets() - 1)) == 0 &&
"# initial buckets must be a power of two!");
- const KeyT EmptyKey = getEmptyKey();
+ const KeyT EmptyKey = KeyInfoT::getEmptyKey();
for (BucketT &B : buckets())
::new (&B.getFirst()) KeyT(EmptyKey);
}
@@ -397,8 +400,8 @@ class DenseMapBase : public DebugEpochBase {
initEmpty();
// Insert all the old elements.
- const KeyT EmptyKey = getEmptyKey();
- const KeyT TombstoneKey = getTombstoneKey();
+ const KeyT EmptyKey = KeyInfoT::getEmptyKey();
+ const KeyT TombstoneKey = KeyInfoT::getTombstoneKey();
for (BucketT &B : OldBuckets) {
if (!KeyInfoT::isEqual(B.getFirst(), EmptyKey) &&
!KeyInfoT::isEqual(B.getFirst(), TombstoneKey)) {
@@ -442,8 +445,8 @@ class DenseMapBase : public DebugEpochBase {
memcpy(reinterpret_cast<void *>(Buckets), OtherBuckets,
NumBuckets * sizeof(BucketT));
} else {
- const KeyT EmptyKey = getEmptyKey();
- const KeyT TombstoneKey = getTombstoneKey();
+ const KeyT EmptyKey = KeyInfoT::getEmptyKey();
+ const KeyT TombstoneKey = KeyInfoT::getTombstoneKey();
for (size_t I = 0; I < NumBuckets; ++I) {
::new (&Buckets[I].getFirst()) KeyT(OtherBuckets[I].getFirst());
if (!KeyInfoT::isEqual(Buckets[I].getFirst(), EmptyKey) &&
@@ -453,19 +456,6 @@ class DenseMapBase : public DebugEpochBase {
}
}
- template <typename LookupKeyT>
- static unsigned getHashValue(const LookupKeyT &Val) {
- return KeyInfoT::getHashValue(Val);
- }
-
- static const KeyT getEmptyKey() {
- static_assert(std::is_base_of_v<DenseMapBase, DerivedT>,
- "Must pass the derived type to this template!");
- return KeyInfoT::getEmptyKey();
- }
-
- static const KeyT getTombstoneKey() { return KeyInfoT::getTombstoneKey(); }
-
private:
DerivedT &derived() { return *static_cast<DerivedT *>(this); }
const DerivedT &derived() const {
@@ -573,7 +563,7 @@ class DenseMapBase : public DebugEpochBase {
incrementNumEntries();
// If we are writing over a tombstone, remember this.
- const KeyT EmptyKey = getEmptyKey();
+ const KeyT EmptyKey = KeyInfoT::getEmptyKey();
if (!KeyInfoT::isEqual(TheBucket->getFirst(), EmptyKey))
decrementNumTombstones();
@@ -587,8 +577,8 @@ class DenseMapBase : public DebugEpochBase {
if (NumBuckets == 0)
return nullptr;
- const KeyT EmptyKey = getEmptyKey();
- unsigned BucketNo = getHashValue(Val) & (NumBuckets - 1);
+ const KeyT EmptyKey = KeyInfoT::getEmptyKey();
+ unsigned BucketNo = KeyInfoT::getHashValue(Val) & (NumBuckets - 1);
unsigned ProbeAmt = 1;
while (true) {
const BucketT *Bucket = BucketsPtr + BucketNo;
@@ -625,13 +615,13 @@ class DenseMapBase : public DebugEpochBase {
// FoundTombstone - Keep track of whether we find a tombstone while probing.
BucketT *FoundTombstone = nullptr;
- const KeyT EmptyKey = getEmptyKey();
- const KeyT TombstoneKey = getTombstoneKey();
+ const KeyT EmptyKey = KeyInfoT::getEmptyKey();
+ const KeyT TombstoneKey = KeyInfoT::getTombstoneKey();
assert(!KeyInfoT::isEqual(Val, EmptyKey) &&
!KeyInfoT::isEqual(Val, TombstoneKey) &&
"Empty/Tombstone value shouldn't be inserted into map!");
- unsigned BucketNo = getHashValue(Val) & (NumBuckets - 1);
+ unsigned BucketNo = KeyInfoT::getHashValue(Val) & (NumBuckets - 1);
unsigned ProbeAmt = 1;
while (true) {
BucketT *ThisBucket = BucketsPtr + BucketNo;
@@ -930,8 +920,8 @@ class SmallDenseMap
NumEntries = TmpNumEntries;
std::swap(NumTombstones, RHS.NumTombstones);
- const KeyT EmptyKey = this->getEmptyKey();
- const KeyT TombstoneKey = this->getTombstoneKey();
+ const KeyT EmptyKey = KeyInfoT::getEmptyKey();
+ const KeyT TombstoneKey = KeyInfoT::getTombstoneKey();
if (Small && RHS.Small) {
// If we're swapping inline bucket arrays, we have to cope with some of
// the tricky bits of DenseMap's storage system: the buckets are not
@@ -1125,8 +1115,8 @@ class SmallDenseMap
// Loop over the buckets, moving non-empty, non-tombstones into the
// temporary storage. Have the loop move the TmpEnd forward as it goes.
- const KeyT EmptyKey = this->getEmptyKey();
- const KeyT TombstoneKey = this->getTombstoneKey();
+ const KeyT EmptyKey = KeyInfoT::getEmptyKey();
+ const KeyT TombstoneKey = KeyInfoT::getTombstoneKey();
for (BucketT &B : inlineBuckets()) {
if (!KeyInfoT::isEqual(B.getFirst(), EmptyKey) &&
!KeyInfoT::isEqual(B.getFirst(), TombstoneKey)) {
More information about the llvm-commits
mailing list