summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--llvm/lib/IR/IRPrintingPasses.cpp18
-rw-r--r--llvm/test/Other/module-pass-printer.ll18
2 files changed, 31 insertions, 5 deletions
diff --git a/llvm/lib/IR/IRPrintingPasses.cpp b/llvm/lib/IR/IRPrintingPasses.cpp
index 35b06135a82..953cf941016 100644
--- a/llvm/lib/IR/IRPrintingPasses.cpp
+++ b/llvm/lib/IR/IRPrintingPasses.cpp
@@ -26,14 +26,22 @@ PrintModulePass::PrintModulePass(raw_ostream &OS, const std::string &Banner,
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();
}
diff --git a/llvm/test/Other/module-pass-printer.ll b/llvm/test/Other/module-pass-printer.ll
new file mode 100644
index 00000000000..9c16cf10a2e
--- /dev/null
+++ b/llvm/test/Other/module-pass-printer.ll
@@ -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
+}
OpenPOWER on IntegriCloud