[llvm] Revert "[CodeGen] Use SmallMapVector for SpillPlacement::Node::Links" (PR #194801)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 29 00:42:47 PDT 2026
https://github.com/nikic created https://github.com/llvm/llvm-project/pull/194801
Reverts llvm/llvm-project#194653
This caused a compile-time regression, rather than the expected improvement.
>From 8d5f28ea2a1ab25b61202350b809348071dbdb88 Mon Sep 17 00:00:00 2001
From: Nikita Popov <github at npopov.com>
Date: Wed, 29 Apr 2026 09:42:09 +0200
Subject: [PATCH] Revert "[CodeGen] Use SmallMapVector for
SpillPlacement::Node::Links (#194653)"
This reverts commit f217197c8d658390be97d962627a52f2cd97bd4a.
---
llvm/lib/CodeGen/SpillPlacement.cpp | 34 +++++++++++++++++------------
1 file changed, 20 insertions(+), 14 deletions(-)
diff --git a/llvm/lib/CodeGen/SpillPlacement.cpp b/llvm/lib/CodeGen/SpillPlacement.cpp
index 1b3cd9ccbf08b..55a96a22a00ec 100644
--- a/llvm/lib/CodeGen/SpillPlacement.cpp
+++ b/llvm/lib/CodeGen/SpillPlacement.cpp
@@ -28,7 +28,6 @@
#include "llvm/CodeGen/SpillPlacement.h"
#include "llvm/ADT/BitVector.h"
-#include "llvm/ADT/MapVector.h"
#include "llvm/CodeGen/EdgeBundles.h"
#include "llvm/CodeGen/MachineBasicBlock.h"
#include "llvm/CodeGen/MachineBlockFrequencyInfo.h"
@@ -82,9 +81,11 @@ struct SpillPlacement::Node {
/// variable should go in a register through this bundle.
int Value;
- /// Links - (BundleNo, Weight) for all transparent blocks connecting to other
+ using LinkVector = SmallVector<std::pair<BlockFrequency, unsigned>, 4>;
+
+ /// Links - (Weight, BundleNo) for all transparent blocks connecting to other
/// bundles. The weights are all positive block frequencies.
- SmallMapVector<unsigned, BlockFrequency, 4> Links;
+ LinkVector Links;
/// SumLinkWeights - Cached sum of the weights of all links + ThresHold.
BlockFrequency SumLinkWeights;
@@ -119,9 +120,13 @@ struct SpillPlacement::Node {
SumLinkWeights += w;
// There can be multiple links to the same bundle, add them up.
- auto [It, Inserted] = Links.try_emplace(b, w);
- if (!Inserted)
- It->second += w;
+ for (std::pair<BlockFrequency, unsigned> &L : Links)
+ if (L.second == b) {
+ L.first += w;
+ return;
+ }
+ // This must be the first link to b.
+ Links.push_back(std::make_pair(w, b));
}
/// addBias - Bias this node.
@@ -147,11 +152,11 @@ struct SpillPlacement::Node {
// Compute the weighted sum of inputs.
BlockFrequency SumN = BiasN;
BlockFrequency SumP = BiasP;
- for (auto [BundleNo, Weight] : Links) {
- if (nodes[BundleNo].Value == -1)
- SumN += Weight;
- else if (nodes[BundleNo].Value == 1)
- SumP += Weight;
+ for (std::pair<BlockFrequency, unsigned> &L : Links) {
+ if (nodes[L.second].Value == -1)
+ SumN += L.first;
+ else if (nodes[L.second].Value == 1)
+ SumP += L.first;
}
// Each weighted sum is going to be less than the total frequency of the
@@ -174,11 +179,12 @@ struct SpillPlacement::Node {
void getDissentingNeighbors(SparseSet<unsigned> &List,
const Node nodes[]) const {
- for (auto [BundleNo, _] : Links) {
+ for (const auto &Elt : Links) {
+ unsigned n = Elt.second;
// Neighbors that already have the same value are not going to
// change because of this node changing.
- if (Value != nodes[BundleNo].Value)
- List.insert(BundleNo);
+ if (Value != nodes[n].Value)
+ List.insert(n);
}
}
};
More information about the llvm-commits
mailing list