[llvm] 8c6305b - [NewPM] Print function/SCC size with -debug-pass-manager

Arthur Eubanks via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 19 09:05:01 PDT 2022


Author: Arthur Eubanks
Date: 2022-07-19T09:00:37-07:00
New Revision: 8c6305b8b485c26d52409790ffdabe0898af81a1

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

LOG: [NewPM] Print function/SCC size with -debug-pass-manager

This is helpful for debugging issues with very large functions or SCC.
Also helpful when function names are very large and it's hard to tell the number of nodes in an SCC.

Reviewed By: hans

Differential Revision: https://reviews.llvm.org/D128003

Added: 
    llvm/test/Other/print-function-size.ll
    llvm/test/Other/print-scc-size.ll

Modified: 
    llvm/lib/Passes/StandardInstrumentations.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Passes/StandardInstrumentations.cpp b/llvm/lib/Passes/StandardInstrumentations.cpp
index bad8184dffcf..56560d2c07ec 100644
--- a/llvm/lib/Passes/StandardInstrumentations.cpp
+++ b/llvm/lib/Passes/StandardInstrumentations.cpp
@@ -940,7 +940,22 @@ void PrintPassInstrumentation::registerCallbacks(
     if (isSpecialPass(PassID, SpecialPasses))
       return;
 
-    print() << "Running pass: " << PassID << " on " << getIRName(IR) << "\n";
+    auto &OS = print();
+    OS << "Running pass: " << PassID << " on " << getIRName(IR);
+    if (any_isa<const Function *>(IR)) {
+      unsigned Count = any_cast<const Function *>(IR)->getInstructionCount();
+      OS << " (" << Count << " instruction";
+      if (Count != 1)
+        OS << 's';
+      OS << ')';
+    } else if (any_isa<const LazyCallGraph::SCC *>(IR)) {
+      int Count = any_cast<const LazyCallGraph::SCC *>(IR)->size();
+      OS << " (" << Count << " node";
+      if (Count != 1)
+        OS << 's';
+      OS << ')';
+    }
+    OS << "\n";
     Indent += 2;
   });
   PIC.registerAfterPassCallback(

diff  --git a/llvm/test/Other/print-function-size.ll b/llvm/test/Other/print-function-size.ll
new file mode 100644
index 000000000000..83af65793df2
--- /dev/null
+++ b/llvm/test/Other/print-function-size.ll
@@ -0,0 +1,14 @@
+; RUN: opt -S -debug-pass-manager -passes=no-op-function < %s 2>&1 | FileCheck %s
+
+; CHECK: Running pass: NoOpFunctionPass on f (3 instructions)
+; CHECK: Running pass: NoOpFunctionPass on g (1 instruction)
+
+define i32 @f(i32 %i) {
+  %a = add i32 %i, 1
+  %b = add i32 %a, 1
+  ret i32 %b
+}
+
+define i32 @g(i32 %i) {
+  ret i32 0
+}

diff  --git a/llvm/test/Other/print-scc-size.ll b/llvm/test/Other/print-scc-size.ll
new file mode 100644
index 000000000000..4833186d9e7f
--- /dev/null
+++ b/llvm/test/Other/print-scc-size.ll
@@ -0,0 +1,18 @@
+; RUN: opt -S -debug-pass-manager -passes=no-op-cgscc < %s 2>&1 | FileCheck %s
+
+; CHECK: Running pass: NoOpCGSCCPass on (f) (1 node)
+; CHECK: Running pass: NoOpCGSCCPass on (g, h) (2 nodes)
+
+define void @f() {
+  ret void
+}
+
+define void @g() {
+  call void @h()
+  ret void
+}
+
+define void @h() {
+  call void @g()
+  ret void
+}


        


More information about the llvm-commits mailing list