From 8e45771e6e37698a90871ac0eb0c9964b483e180 Mon Sep 17 00:00:00 2001 From: Arthur Eubanks Date: Thu, 20 Feb 2025 21:19:17 +0000 Subject: [PATCH 1/2] [CGSCC] Add statistic on largest SCC visited To help debugging long compile times. --- llvm/lib/Analysis/CGSCCPassManager.cpp | 5 +++++ llvm/test/Other/largest-scc-stat.ll | 21 +++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 llvm/test/Other/largest-scc-stat.ll 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 @@ PassManagersize()); + 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 +} From da61b2333a76705ad31ec61579a5efd15814456b Mon Sep 17 00:00:00 2001 From: Arthur Eubanks Date: Thu, 20 Feb 2025 21:27:17 +0000 Subject: [PATCH 2/2] simplify test --- llvm/test/Other/largest-scc-stat.ll | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/llvm/test/Other/largest-scc-stat.ll b/llvm/test/Other/largest-scc-stat.ll index 814f4dbe6b80b..a24e426c31a00 100644 --- a/llvm/test/Other/largest-scc-stat.ll +++ b/llvm/test/Other/largest-scc-stat.ll @@ -5,17 +5,14 @@ ; 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 + %f = bitcast ptr @f2 to ptr call void %f() ret void } define void @f2() { - %f = load ptr, ptr @g1 + %f = bitcast ptr @f1 to ptr call void %f() ret void }