[llvm] bae33a7 - IR printing for single function with the new pass manager.
Wenlei He via llvm-commits
llvm-commits at lists.llvm.org
Sun Feb 23 15:29:17 PST 2020
Author: Hongtao Yu
Date: 2020-02-23T15:28:57-08:00
New Revision: bae33a7c5a1f220671e6d99cda21749afe2501a6
URL: https://github.com/llvm/llvm-project/commit/bae33a7c5a1f220671e6d99cda21749afe2501a6
DIFF: https://github.com/llvm/llvm-project/commit/bae33a7c5a1f220671e6d99cda21749afe2501a6.diff
LOG: IR printing for single function with the new pass manager.
Summary:
The IR printing always prints out all functions in a module with the new pass manager, even with -filter-print-funcs specified. This is being fixed in this change. However, there are two exceptions, i.e, with user-specified wildcast switch -filter-print-funcs=* or -print-module-scope, under which IR of all functions should be printed.
Test Plan:
make check-clang
make check-llvm
Reviewers: wenlei
Reviewed By: wenlei
Subscribers: wenlei, hiraditya, cfe-commits, llvm-commits
Tags: #clang, #llvm
Differential Revision: https://reviews.llvm.org/D74814
Added:
Modified:
llvm/lib/Passes/StandardInstrumentations.cpp
llvm/test/Other/module-pass-printer.ll
Removed:
################################################################################
diff --git a/llvm/lib/Passes/StandardInstrumentations.cpp b/llvm/lib/Passes/StandardInstrumentations.cpp
index 2d3440c1e87d..1e1a6b98a65a 100644
--- a/llvm/lib/Passes/StandardInstrumentations.cpp
+++ b/llvm/lib/Passes/StandardInstrumentations.cpp
@@ -70,16 +70,24 @@ Optional<std::pair<const Module *, std::string>> unwrapModule(Any IR) {
llvm_unreachable("Unknown IR unit");
}
-void printIR(const Module *M, StringRef Banner, StringRef Extra = StringRef()) {
- dbgs() << Banner << Extra << "\n";
- M->print(dbgs(), nullptr, false);
-}
void printIR(const Function *F, StringRef Banner,
StringRef Extra = StringRef()) {
if (!llvm::isFunctionInPrintList(F->getName()))
return;
dbgs() << Banner << Extra << "\n" << static_cast<const Value &>(*F);
}
+
+void printIR(const Module *M, StringRef Banner, StringRef Extra = StringRef()) {
+ if (llvm::isFunctionInPrintList("*") || llvm::forcePrintModuleIR()) {
+ dbgs() << Banner << Extra << "\n";
+ M->print(dbgs(), nullptr, false);
+ } else {
+ for (const auto &F : M->functions()) {
+ printIR(&F, Banner, Extra);
+ }
+ }
+}
+
void printIR(const LazyCallGraph::SCC *C, StringRef Banner,
StringRef Extra = StringRef()) {
bool BannerPrinted = false;
diff --git a/llvm/test/Other/module-pass-printer.ll b/llvm/test/Other/module-pass-printer.ll
index 9c16cf10a2ef..931d6465424f 100644
--- a/llvm/test/Other/module-pass-printer.ll
+++ b/llvm/test/Other/module-pass-printer.ll
@@ -1,13 +1,43 @@
; 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 only one function is printed
+; RUN: opt < %s 2>&1 -forceattrs -disable-output -print-after-all -filter-print-funcs=foo | FileCheck %s -check-prefix=FOO
+; RUN: opt < %s 2>&1 -passes=forceattrs -disable-output -print-after-all -filter-print-funcs=foo | FileCheck %s -check-prefix=FOO
+
+; Check pass name is only printed once.
+; Check both functions are printed
+; RUN: opt < %s 2>&1 -forceattrs -disable-output -print-after-all -filter-print-funcs=foo,bar | FileCheck %s -check-prefix=BOTH
+; RUN: opt < %s 2>&1 -passes=forceattrs -disable-output -print-after-all -filter-print-funcs=foo,bar | FileCheck %s -check-prefix=BOTH
; 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
+; RUN: opt < %s 2>&1 -passes=forceattrs -disable-output -print-after-all -filter-print-funcs=baz | FileCheck %s -allow-empty -check-prefix=EMPTY
+
+; Check whole module is printed with user-specified wildcast switch -filter-print-funcs=* or -print-module-scope
+; RUN: opt < %s 2>&1 -forceattrs -disable-output -print-after-all | FileCheck %s -check-prefix=ALL
+; RUN: opt < %s 2>&1 -forceattrs -disable-output -print-after-all -filter-print-funcs=* | FileCheck %s -check-prefix=ALL
+; RUN: opt < %s 2>&1 -forceattrs -disable-output -print-after-all -filter-print-funcs=foo -print-module-scope | FileCheck %s -check-prefix=ALL
+; RUN: opt < %s 2>&1 -passes=forceattrs -disable-output -print-after-all | FileCheck %s -check-prefix=ALL
+; RUN: opt < %s 2>&1 -passes=forceattrs -disable-output -print-after-all -filter-print-funcs=* | FileCheck %s -check-prefix=ALL
+; RUN: opt < %s 2>&1 -passes=forceattrs -disable-output -print-after-all -filter-print-funcs=foo -print-module-scope | FileCheck %s -check-prefix=ALL
+
+; FOO: IR Dump After {{Force set function attributes|ForceFunctionAttrsPass}}
+; FOO: define void @foo
+; FOO-NOT: define void @bar
+; FOO-NOT: IR Dump After {{Force set function attributes|ForceFunctionAttrsPass}}
+
+; BOTH: IR Dump After {{Force set function attributes|ForceFunctionAttrsPass}}
+; BOTH: define void @foo
+; BOTH: define void @bar
+; BOTH-NOT: IR Dump After {{Force set function attributes|ForceFunctionAttrsPass}}
+; BOTH-NOT: ModuleID =
+
+; EMPTY-NOT: IR Dump After {{Force set function attributes|ForceFunctionAttrsPass}}
-; 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 ***
+; ALL: IR Dump After {{Force set function attributes|ForceFunctionAttrsPass}}
+; ALL: ModuleID =
+; ALL: define void @foo
+; ALL: define void @bar
+; ALL-NOT: IR Dump After {{Force set function attributes|ForceFunctionAttrsPass}}
define void @foo() {
ret void
More information about the llvm-commits
mailing list