[llvm] r344505 - [NewPM] implement SCC printing for -print-before-all/-print-after-all

Fedor Sergeev via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 15 03:46:35 PDT 2018


Author: fedor.sergeev
Date: Mon Oct 15 03:46:35 2018
New Revision: 344505

URL: http://llvm.org/viewvc/llvm-project?rev=344505&view=rev
Log:
[NewPM] implement SCC printing for -print-before-all/-print-after-all

Removing deficiency of initial implementation of -print-before-all/-after-all
- it was effectively skipping IR printing for all the SCC passes.

Now LazyCallGraph:SCC gets its IR printed.

Reviewed By: skatkov
Differential Revision: https://reviews.llvm.org/D53270

Added:
    llvm/trunk/test/Other/scc-pass-printer.ll
Modified:
    llvm/trunk/lib/Passes/StandardInstrumentations.cpp

Modified: llvm/trunk/lib/Passes/StandardInstrumentations.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Passes/StandardInstrumentations.cpp?rev=344505&r1=344504&r2=344505&view=diff
==============================================================================
--- llvm/trunk/lib/Passes/StandardInstrumentations.cpp (original)
+++ llvm/trunk/lib/Passes/StandardInstrumentations.cpp Mon Oct 15 03:46:35 2018
@@ -37,10 +37,6 @@ namespace PrintIR {
 /// Generic IR-printing helper that unpacks a pointer to IRUnit wrapped into
 /// llvm::Any and does actual print job.
 void unwrapAndPrint(StringRef Banner, Any IR) {
-  if (any_isa<const CallGraphSCC *>(IR) ||
-      any_isa<const LazyCallGraph::SCC *>(IR))
-    return;
-
   SmallString<40> Extra{"\n"};
   const Module *M = nullptr;
   if (any_isa<const Module *>(IR)) {
@@ -55,6 +51,34 @@ void unwrapAndPrint(StringRef Banner, An
     }
     M = F->getParent();
     Extra = formatv(" (function: {0})\n", F->getName());
+  } else if (any_isa<const LazyCallGraph::SCC *>(IR)) {
+    const LazyCallGraph::SCC *C = any_cast<const LazyCallGraph::SCC *>(IR);
+    assert(C);
+    if (!llvm::forcePrintModuleIR()) {
+      Extra = formatv(" (scc: {0})\n", C->getName());
+      bool BannerPrinted = false;
+      for (const LazyCallGraph::Node &N : *C) {
+        const Function &F = N.getFunction();
+        if (!F.isDeclaration() && isFunctionInPrintList(F.getName())) {
+          if (!BannerPrinted) {
+            dbgs() << Banner << Extra;
+            BannerPrinted = true;
+          }
+          F.print(dbgs());
+        }
+      }
+      return;
+    }
+    for (const LazyCallGraph::Node &N : *C) {
+      const Function &F = N.getFunction();
+      if (!F.isDeclaration() && isFunctionInPrintList(F.getName())) {
+        M = F.getParent();
+        break;
+      }
+    }
+    if (!M)
+      return;
+    Extra = formatv(" (for scc: {0})\n", C->getName());
   } else if (any_isa<const Loop *>(IR)) {
     const Loop *L = any_cast<const Loop *>(IR);
     const Function *F = L->getHeader()->getParent();

Added: llvm/trunk/test/Other/scc-pass-printer.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Other/scc-pass-printer.ll?rev=344505&view=auto
==============================================================================
--- llvm/trunk/test/Other/scc-pass-printer.ll (added)
+++ llvm/trunk/test/Other/scc-pass-printer.ll Mon Oct 15 03:46:35 2018
@@ -0,0 +1,49 @@
+; RUN: opt < %s 2>&1 -disable-output \
+; RUN: 	   -inline -print-after-all | FileCheck %s -check-prefix=INL
+; RUN: opt < %s 2>&1 -disable-output \
+; RUN: 	   -passes=inline -print-after-all | FileCheck %s -check-prefix=INL
+; RUN: opt < %s 2>&1 -disable-output \
+; RUN: 	   -inline -print-after-all -print-module-scope | FileCheck %s -check-prefix=INL-MOD
+; RUN: opt < %s 2>&1 -disable-output \
+; RUN: 	   -passes=inline -print-after-all -print-module-scope | FileCheck %s -check-prefix=INL-MOD
+
+; INL: IR Dump After {{Function Integration/Inlining|InlinerPass .*scc: .bar, foo}}
+; INL: define void @bar()
+; INL-NEXT:  call void @foo()
+; INL: define void @foo()
+; INL-NEXT:   call void @bar()
+; INL: IR Dump After {{Function Integration/Inlining|InlinerPass .*scc: .tester}}
+; INL: define void @tester()
+; INL-NEXT:  call void @foo()
+; INL: IR Dump After
+
+; INL-MOD: IR Dump After {{Function Integration/Inlining|InlinerPass .*scc: .bar, foo}}
+; INL-MOD: define void @tester()
+; INL-MOD-NEXT:  call void @foo()
+; INL-MOD: define void @foo()
+; INL-MOD-NEXT:   call void @bar()
+; INL-MOD: define void @bar()
+; INL-MOD-NEXT:  call void @foo()
+; INL-MOD: IR Dump After {{Function Integration/Inlining|InlinerPass .*scc: .tester}}
+; INL-MOD: define void @tester()
+; INL-MOD-NEXT:  call void @foo()
+; INL-MOD: define void @foo()
+; INL-MOD-NEXT:   call void @bar()
+; INL-MOD: define void @bar()
+; INL-MOD-NEXT:  call void @foo()
+; INL-MOD: IR Dump After
+
+define void @tester() noinline {
+  call void @foo()
+  ret void
+}
+
+define void @foo() noinline {
+  call void @bar()
+  ret void
+}
+
+define void @bar() noinline {
+  call void @foo()
+  ret void
+}




More information about the llvm-commits mailing list