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

via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 31 04:45:09 PST 2025


Author: Anton Sidorenko
Date: 2025-01-31T15:45:05+03:00
New Revision: 9cf8ee91451788b08a0bcda924bfbb3754c454da

URL: https://github.com/llvm/llvm-project/commit/9cf8ee91451788b08a0bcda924bfbb3754c454da
DIFF: https://github.com/llvm/llvm-project/commit/9cf8ee91451788b08a0bcda924bfbb3754c454da.diff

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

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 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
for X86, AArch and RISC-V (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).

This change was made with the same intention as #124904 and optimizes I
believe quite an unusual scenario. However, if there is no negative
impact on other known scenarios, I'd like to have the change in
llvm-project.

Added: 
    

Modified: 
    llvm/tools/llvm-mca/Views/BottleneckAnalysis.h

Removed: 
    


################################################################################
diff  --git a/llvm/tools/llvm-mca/Views/BottleneckAnalysis.h b/llvm/tools/llvm-mca/Views/BottleneckAnalysis.h
index 529090cf543fc4..d4c07f521e6b1f 100644
--- a/llvm/tools/llvm-mca/Views/BottleneckAnalysis.h
+++ b/llvm/tools/llvm-mca/Views/BottleneckAnalysis.h
@@ -228,7 +228,10 @@ class DependencyGraph {
     unsigned Depth;
 
     DependencyEdge CriticalPredecessor;
-    SmallVector<DependencyEdge, 8> OutgoingEdges;
+    // 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