Skip to content

Commit da176cb

Browse files
committed
[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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@370849 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 707116e commit da176cb

File tree

2 files changed

+31
-5
lines changed

2 files changed

+31
-5
lines changed

lib/IR/IRPrintingPasses.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,22 @@ PrintModulePass::PrintModulePass(raw_ostream &OS, const std::string &Banner,
2626
ShouldPreserveUseListOrder(ShouldPreserveUseListOrder) {}
2727

2828
PreservedAnalyses PrintModulePass::run(Module &M, ModuleAnalysisManager &) {
29-
if (!Banner.empty())
30-
OS << Banner << "\n";
31-
if (llvm::isFunctionInPrintList("*"))
29+
if (llvm::isFunctionInPrintList("*")) {
30+
if (!Banner.empty())
31+
OS << Banner << "\n";
3232
M.print(OS, nullptr, ShouldPreserveUseListOrder);
33+
}
3334
else {
34-
for(const auto &F : M.functions())
35-
if (llvm::isFunctionInPrintList(F.getName()))
35+
bool BannerPrinted = false;
36+
for(const auto &F : M.functions()) {
37+
if (llvm::isFunctionInPrintList(F.getName())) {
38+
if (!BannerPrinted && !Banner.empty()) {
39+
OS << Banner << "\n";
40+
BannerPrinted = true;
41+
}
3642
F.print(OS);
43+
}
44+
}
3745
}
3846
return PreservedAnalyses::all();
3947
}

test/Other/module-pass-printer.ll

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
; Check pass name is only printed once.
2+
; RUN: opt < %s 2>&1 -forceattrs -disable-output -print-after-all | FileCheck %s
3+
; RUN: opt < %s 2>&1 -forceattrs -disable-output -print-after-all -filter-print-funcs=foo,bar | FileCheck %s
4+
5+
; Check pass name is not printed if a module doesn't include any function specified in -filter-print-funcs.
6+
; RUN: opt < %s 2>&1 -forceattrs -disable-output -print-after-all -filter-print-funcs=baz | FileCheck %s -allow-empty -check-prefix=EMPTY
7+
8+
; CHECK: *** IR Dump After Force set function attributes ***
9+
; CHECK-NOT: *** IR Dump After Force set function attributes ***
10+
; EMPTY-NOT: *** IR Dump After Force set function attributes ***
11+
12+
define void @foo() {
13+
ret void
14+
}
15+
16+
define void @bar() {
17+
ret void
18+
}

0 commit comments

Comments
 (0)