[llvm] [MCA] Do not allocate space for DependenceEdge by default in DependencyGraphNode (NFC) (PR #125080)

Anton Sidorenko via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 31 02:57:47 PST 2025


https://github.com/asi-sc updated https://github.com/llvm/llvm-project/pull/125080

>From 77145440e95ec6e797cf2cfb2c10eb8dc777df69 Mon Sep 17 00:00:00 2001
From: Anton Sidorenko <anton.sidorenko at syntacore.com>
Date: Thu, 16 Jan 2025 15:22:36 +0300
Subject: [PATCH 1/2] [MCA] Do not allocate space for DependenceEdge by default
 in DependencyGraphNode (NFC)

For each instruction from the input assembly sequence, DependencyGraph has a
dedicated node (DGNode). Outgoing edges (data, resource and memory dependencies)
are tracked as SmallVector<..., 8> for each DGNode in the graph. However, it's
rather unlikely that a usual input instruction will have approximately eight
dependent instructions. Below is my statistics for several RISC-V input
sequences:

Number of  | Number of nodes with
edges      | this # of edges
--------------------------------------------
         0 | 8239447
         1 | 464252
         2 | 6164
         3 | 6783
         4 | 939
         5 | 500
         6 | 545
         7 | 116
         8 | 2
         9 | 1
        10 | 1

Approximately the same distribution is produced by llvm-mca lit tests (even
modified ones with extra dependencies added).
On a rather big input asm sequences, the use of SmallVector<..., 8> dramatically
increases memory consumption without any need for it. In my case, replacing it
with SmallVector<...,0> reduces memory usage by ~28% or ~1700% of input file size
(2.2GB in absolute values).

There is no change in execution time, I verified it on mca lit-tests and on my big
test (execution time is ~30s in both cases).
---
 llvm/tools/llvm-mca/Views/BottleneckAnalysis.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/tools/llvm-mca/Views/BottleneckAnalysis.h b/llvm/tools/llvm-mca/Views/BottleneckAnalysis.h
index 529090cf543fc4..2621efb0413ae2 100644
--- a/llvm/tools/llvm-mca/Views/BottleneckAnalysis.h
+++ b/llvm/tools/llvm-mca/Views/BottleneckAnalysis.h
@@ -228,7 +228,7 @@ class DependencyGraph {
     unsigned Depth;
 
     DependencyEdge CriticalPredecessor;
-    SmallVector<DependencyEdge, 8> OutgoingEdges;
+    SmallVector<DependencyEdge, 0> OutgoingEdges;
   };
   SmallVector<DGNode, 16> Nodes;
 

>From 234783809a9e70876fee3a38ebc5146c4f01eed5 Mon Sep 17 00:00:00 2001
From: Anton Sidorenko <anton.sidorenko at syntacore.com>
Date: Fri, 31 Jan 2025 13:56:34 +0300
Subject: [PATCH 2/2] fixup! [MCA] Do not allocate space for DependenceEdge by
 default in DependencyGraphNode (NFC)

---
 llvm/tools/llvm-mca/Views/BottleneckAnalysis.h | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/llvm/tools/llvm-mca/Views/BottleneckAnalysis.h b/llvm/tools/llvm-mca/Views/BottleneckAnalysis.h
index 2621efb0413ae2..d4c07f521e6b1f 100644
--- a/llvm/tools/llvm-mca/Views/BottleneckAnalysis.h
+++ b/llvm/tools/llvm-mca/Views/BottleneckAnalysis.h
@@ -228,6 +228,9 @@ class DependencyGraph {
     unsigned Depth;
 
     DependencyEdge CriticalPredecessor;
+    // Measurements show that more than 90% of nodes have no outgoing edges. To
+    // minimize memory consumption we use SmallVector with zero inline elements
+    // that is preferred version of std::vector.
     SmallVector<DependencyEdge, 0> OutgoingEdges;
   };
   SmallVector<DGNode, 16> Nodes;



More information about the llvm-commits mailing list