Skip to content

Conversation

@kazutakahirata
Copy link
Contributor

Passing BlockOrder by value results in deep copies of DenseMap. This
patch replaces them with const l-value references.

Passing BlockOrder by value results in deep copies of DenseMap.  This
patch replaces them with const l-value references.
@llvmbot
Copy link
Member

llvmbot commented Nov 14, 2025

@llvm/pr-subscribers-llvm-transforms

Author: Kazu Hirata (kazutakahirata)

Changes

Passing BlockOrder by value results in deep copies of DenseMap. This
patch replaces them with const l-value references.


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

1 Files Affected:

  • (modified) llvm/lib/Transforms/Scalar/GVNSink.cpp (+3-3)
diff --git a/llvm/lib/Transforms/Scalar/GVNSink.cpp b/llvm/lib/Transforms/Scalar/GVNSink.cpp
index d564e32e26526..4dddb017a98ee 100644
--- a/llvm/lib/Transforms/Scalar/GVNSink.cpp
+++ b/llvm/lib/Transforms/Scalar/GVNSink.cpp
@@ -142,7 +142,7 @@ class ModelledPHI {
     for (unsigned I = 0, E = PN->getNumIncomingValues(); I != E; ++I)
       Ops.push_back({PN->getIncomingBlock(I), PN->getIncomingValue(I)});
 
-    auto ComesBefore = [BlockOrder](OpsType O1, OpsType O2) {
+    auto ComesBefore = [&](OpsType O1, OpsType O2) {
       return BlockOrder.lookup(O1.first) < BlockOrder.lookup(O2.first);
     };
     // Sort in a deterministic order.
@@ -167,8 +167,8 @@ class ModelledPHI {
   verifyModelledPHI(const DenseMap<const BasicBlock *, unsigned> &BlockOrder) {
     assert(Values.size() > 1 && Blocks.size() > 1 &&
            "Modelling PHI with less than 2 values");
-    auto ComesBefore = [BlockOrder](const BasicBlock *BB1,
-                                    const BasicBlock *BB2) {
+    [[maybe_unused]] auto ComesBefore = [&](const BasicBlock *BB1,
+                                            const BasicBlock *BB2) {
       return BlockOrder.lookup(BB1) < BlockOrder.lookup(BB2);
     };
     assert(llvm::is_sorted(Blocks, ComesBefore));

@kazutakahirata kazutakahirata merged commit 4d42a0c into llvm:main Nov 14, 2025
11 of 12 checks passed
@kazutakahirata kazutakahirata deleted the cleanup_20251113_ADT_DenseMap_deep_copy branch November 14, 2025 05:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants