[llvm] r370849 - [IRPrinting] Improve module pass printer to work better with -filter-print-funcs

Taewook Oh via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 4 01:08:58 PDT 2019


Author: twoh
Date: Wed Sep  4 01:08:58 2019
New Revision: 370849

URL: http://llvm.org/viewvc/llvm-project?rev=370849&view=rev
Log:
[IRPrinting] Improve module pass printer to work better with -filter-print-funcs

Summary: Previously module pass printer pass prints the banner even when the module doesn't include any function provided with `-filter-print-funcs` option. This introduced a lot of noise, especailly with ThinLTO. This diff addresses the issue and makes the banner printed only when the module includes functions in `-filter-print-funcs` list.

Reviewers: fedor.sergeev

Subscribers: mehdi_amini, hiraditya, dexonsmith, llvm-commits

Tags: #llvm

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

Added:
    llvm/trunk/test/Other/module-pass-printer.ll
Modified:
    llvm/trunk/lib/IR/IRPrintingPasses.cpp

Modified: llvm/trunk/lib/IR/IRPrintingPasses.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/IRPrintingPasses.cpp?rev=370849&r1=370848&r2=370849&view=diff
==============================================================================
--- llvm/trunk/lib/IR/IRPrintingPasses.cpp (original)
+++ llvm/trunk/lib/IR/IRPrintingPasses.cpp Wed Sep  4 01:08:58 2019
@@ -26,14 +26,22 @@ PrintModulePass::PrintModulePass(raw_ost
       ShouldPreserveUseListOrder(ShouldPreserveUseListOrder) {}
 
 PreservedAnalyses PrintModulePass::run(Module &M, ModuleAnalysisManager &) {
-  if (!Banner.empty())
-    OS << Banner << "\n";
-  if (llvm::isFunctionInPrintList("*"))
+  if (llvm::isFunctionInPrintList("*")) {
+    if (!Banner.empty())
+      OS << Banner << "\n";
     M.print(OS, nullptr, ShouldPreserveUseListOrder);
+  }
   else {
-    for(const auto &F : M.functions())
-      if (llvm::isFunctionInPrintList(F.getName()))
+    bool BannerPrinted = false;
+    for(const auto &F : M.functions()) {
+      if (llvm::isFunctionInPrintList(F.getName())) {
+        if (!BannerPrinted && !Banner.empty()) {
+          OS << Banner << "\n";
+          BannerPrinted = true;
+        }
         F.print(OS);
+      }
+    }
   }
   return PreservedAnalyses::all();
 }

Added: llvm/trunk/test/Other/module-pass-printer.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Other/module-pass-printer.ll?rev=370849&view=auto
==============================================================================
--- llvm/trunk/test/Other/module-pass-printer.ll (added)
+++ llvm/trunk/test/Other/module-pass-printer.ll Wed Sep  4 01:08:58 2019
@@ -0,0 +1,18 @@
+; Check pass name is only printed once.
+; RUN: opt < %s 2>&1 -forceattrs -disable-output -print-after-all | FileCheck %s
+; RUN: opt < %s 2>&1 -forceattrs -disable-output -print-after-all -filter-print-funcs=foo,bar | FileCheck %s
+
+; Check pass name is not printed if a module doesn't include any function specified in -filter-print-funcs.
+; RUN: opt < %s 2>&1 -forceattrs -disable-output -print-after-all -filter-print-funcs=baz | FileCheck %s -allow-empty -check-prefix=EMPTY
+
+; CHECK: *** IR Dump After Force set function attributes ***
+; CHECK-NOT: *** IR Dump After Force set function attributes ***
+; EMPTY-NOT: *** IR Dump After Force set function attributes ***
+
+define void @foo() {
+  ret void
+}
+
+define void @bar() {
+  ret void
+}




More information about the llvm-commits mailing list