Skip to content

Conversation

@aeubanks
Copy link
Contributor

To help debugging long compile times.

To help debugging long compile times.
@aeubanks aeubanks requested a review from zmodem February 20, 2025 21:22
@llvmbot llvmbot added the llvm:analysis Includes value tracking, cost tables and constant folding label Feb 20, 2025
@llvmbot
Copy link
Member

llvmbot commented Feb 20, 2025

@llvm/pr-subscribers-llvm-analysis

Author: Arthur Eubanks (aeubanks)

Changes

To help debugging long compile times.


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

2 Files Affected:

  • (modified) llvm/lib/Analysis/CGSCCPassManager.cpp (+5)
  • (added) llvm/test/Other/largest-scc-stat.ll (+21)
diff --git a/llvm/lib/Analysis/CGSCCPassManager.cpp b/llvm/lib/Analysis/CGSCCPassManager.cpp
index 948bc2435ab27..ab3a721d874a5 100644
--- a/llvm/lib/Analysis/CGSCCPassManager.cpp
+++ b/llvm/lib/Analysis/CGSCCPassManager.cpp
@@ -13,6 +13,7 @@
 #include "llvm/ADT/SetVector.h"
 #include "llvm/ADT/SmallPtrSet.h"
 #include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/Statistic.h"
 #include "llvm/ADT/iterator_range.h"
 #include "llvm/Analysis/LazyCallGraph.h"
 #include "llvm/IR/Constant.h"
@@ -33,6 +34,8 @@
 
 using namespace llvm;
 
+STATISTIC(LargestCGSCC, "Number of functions in the largest SCC");
+
 // Explicit template instantiations and specialization definitions for core
 // template typedefs.
 namespace llvm {
@@ -82,6 +85,8 @@ PassManager<LazyCallGraph::SCC, CGSCCAnalysisManager, LazyCallGraph &,
     if (!PI.runBeforePass(*Pass, *C))
       continue;
 
+    LargestCGSCC.updateMax(C->size());
+
     PreservedAnalyses PassPA = Pass->run(*C, AM, G, UR);
 
     // Update the SCC if necessary.
diff --git a/llvm/test/Other/largest-scc-stat.ll b/llvm/test/Other/largest-scc-stat.ll
new file mode 100644
index 0000000000000..814f4dbe6b80b
--- /dev/null
+++ b/llvm/test/Other/largest-scc-stat.ll
@@ -0,0 +1,21 @@
+; REQUIRES: asserts
+; RUN: opt -passes='no-op-cgscc' -disable-output -stats < %s 2>&1 | FileCheck %s --check-prefix=ONE
+; RUN: opt -passes='cgscc(instcombine)' -disable-output -stats < %s 2>&1 | FileCheck %s --check-prefix=TWO
+
+; ONE: 1 cgscc - Number of functions in the largest SCC
+; TWO: 2 cgscc - Number of functions in the largest SCC
+
+@g1 = constant ptr @f1
+@g2 = constant ptr @f2
+
+define void @f1() {
+  %f = load ptr, ptr @g2
+  call void %f()
+  ret void
+}
+
+define void @f2() {
+  %f = load ptr, ptr @g1
+  call void %f()
+  ret void
+}

Copy link
Collaborator

@zmodem zmodem left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@aeubanks aeubanks merged commit ab098a7 into llvm:main Feb 21, 2025
11 checks passed
@aeubanks aeubanks deleted the largest-scc branch February 21, 2025 17:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

llvm:analysis Includes value tracking, cost tables and constant folding

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants