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

Arthur Eubanks via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 16 13:32:12 PDT 2022


aeubanks created this revision.
aeubanks added a reviewer: hans.
Herald added a subscriber: hiraditya.
Herald added a reviewer: ctetreau.
Herald added a project: All.
aeubanks requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D128003

Files:
  llvm/lib/Passes/StandardInstrumentations.cpp
  llvm/test/Other/print-function-size.ll
  llvm/test/Other/print-scc-size.ll


Index: llvm/test/Other/print-scc-size.ll
===================================================================
--- /dev/null
+++ 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
+}
Index: llvm/test/Other/print-function-size.ll
===================================================================
--- /dev/null
+++ 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
+}
Index: llvm/lib/Passes/StandardInstrumentations.cpp
===================================================================
--- llvm/lib/Passes/StandardInstrumentations.cpp
+++ llvm/lib/Passes/StandardInstrumentations.cpp
@@ -939,7 +939,22 @@
     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(


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D128003.437684.patch
Type: text/x-patch
Size: 2060 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220616/edcf03a0/attachment.bin>


More information about the llvm-commits mailing list