Skip to content

[ADT] Make DenseMap::init() private (NFC) #134229

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

Merged
merged 1 commit into from
Apr 3, 2025
Merged

Conversation

nikic
Copy link
Contributor

@nikic nikic commented Apr 3, 2025

I believe this method was not supposed to be public, as it has additional preconditions (it will misbehave when called on a non-empty DenseMap).

The public API for this is reserve().

I believe this method was not supposed to be public, as it has
additional preconditions (it will misbehave when called on a
non-empty DenseMap).

The public API for this is reserve().
@nikic nikic requested review from kuhar and dwblaikie April 3, 2025 10:45
@llvmbot
Copy link
Member

llvmbot commented Apr 3, 2025

@llvm/pr-subscribers-llvm-adt

Author: Nikita Popov (nikic)

Changes

I believe this method was not supposed to be public, as it has additional preconditions (it will misbehave when called on a non-empty DenseMap).

The public API for this is reserve().


Full diff: https://github.com/llvm/llvm-project/pull/134229.diff

2 Files Affected:

  • (modified) llvm/include/llvm/ADT/DenseMap.h (+10-10)
  • (modified) llvm/lib/CodeGen/AssignmentTrackingAnalysis.cpp (+4-4)
diff --git a/llvm/include/llvm/ADT/DenseMap.h b/llvm/include/llvm/ADT/DenseMap.h
index ea9ba6f47ac1a..bb99a41646b08 100644
--- a/llvm/include/llvm/ADT/DenseMap.h
+++ b/llvm/include/llvm/ADT/DenseMap.h
@@ -806,16 +806,6 @@ class DenseMap : public DenseMapBase<DenseMap<KeyT, ValueT, KeyInfoT, BucketT>,
     }
   }
 
-  void init(unsigned InitNumEntries) {
-    auto InitBuckets = BaseT::getMinBucketToReserveForEntries(InitNumEntries);
-    if (allocateBuckets(InitBuckets)) {
-      this->BaseT::initEmpty();
-    } else {
-      NumEntries = 0;
-      NumTombstones = 0;
-    }
-  }
-
   void grow(unsigned AtLeast) {
     unsigned OldNumBuckets = NumBuckets;
     BucketT *OldBuckets = Buckets;
@@ -878,6 +868,16 @@ class DenseMap : public DenseMapBase<DenseMap<KeyT, ValueT, KeyInfoT, BucketT>,
         allocate_buffer(sizeof(BucketT) * NumBuckets, alignof(BucketT)));
     return true;
   }
+
+  void init(unsigned InitNumEntries) {
+    auto InitBuckets = BaseT::getMinBucketToReserveForEntries(InitNumEntries);
+    if (allocateBuckets(InitBuckets)) {
+      this->BaseT::initEmpty();
+    } else {
+      NumEntries = 0;
+      NumTombstones = 0;
+    }
+  }
 };
 
 template <typename KeyT, typename ValueT, unsigned InlineBuckets = 4,
diff --git a/llvm/lib/CodeGen/AssignmentTrackingAnalysis.cpp b/llvm/lib/CodeGen/AssignmentTrackingAnalysis.cpp
index 272749f5574c6..8eb523e7d24c6 100644
--- a/llvm/lib/CodeGen/AssignmentTrackingAnalysis.cpp
+++ b/llvm/lib/CodeGen/AssignmentTrackingAnalysis.cpp
@@ -897,8 +897,8 @@ class MemLocFragmentFill {
         Worklist.push(RPONumber);
         ++RPONumber;
       }
-      LiveIn.init(RPONumber);
-      LiveOut.init(RPONumber);
+      LiveIn.reserve(RPONumber);
+      LiveOut.reserve(RPONumber);
     }
 
     // Perform the traversal.
@@ -2318,8 +2318,8 @@ bool AssignmentTrackingLowering::run(FunctionVarLocsBuilder *FnVarLocsBuilder) {
       Worklist.push(RPONumber);
       ++RPONumber;
     }
-    LiveIn.init(RPONumber);
-    LiveOut.init(RPONumber);
+    LiveIn.reserve(RPONumber);
+    LiveOut.reserve(RPONumber);
   }
 
   // Perform the traversal.

@nikic nikic merged commit efbbdd6 into llvm:main Apr 3, 2025
11 of 13 checks passed
@nikic nikic deleted the densemap-init branch April 3, 2025 13:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants