[llvm-branch-commits] [llvm] 8d5f28e - Revert "[CodeGen] Use SmallMapVector for SpillPlacement::Node::Links (#194653)"

via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Wed Apr 29 00:42:14 PDT 2026


Author: Nikita Popov
Date: 2026-04-29T09:42:09+02:00
New Revision: 8d5f28ea2a1ab25b61202350b809348071dbdb88

URL: https://github.com/llvm/llvm-project/commit/8d5f28ea2a1ab25b61202350b809348071dbdb88
DIFF: https://github.com/llvm/llvm-project/commit/8d5f28ea2a1ab25b61202350b809348071dbdb88.diff

LOG: Revert "[CodeGen] Use SmallMapVector for SpillPlacement::Node::Links (#194653)"

This reverts commit f217197c8d658390be97d962627a52f2cd97bd4a.

Added: 
    

Modified: 
    llvm/lib/CodeGen/SpillPlacement.cpp

Removed: 
    


################################################################################
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-branch-commits mailing list