[llvm] [StandardInstrumentations] Support -print-after-pass-number option (PR #87458)
Vincent Lee via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 11 01:43:21 PDT 2024
https://github.com/thevinster updated https://github.com/llvm/llvm-project/pull/87458
>From f07891552a22647ec6ba9840bbae5004db81a7be Mon Sep 17 00:00:00 2001
From: Vincent Lee <leevince at fb.com>
Date: Wed, 3 Apr 2024 00:45:13 -0700
Subject: [PATCH 1/5] [StandardInstrumentations] Support
-print-after-pass-number option
---
.../llvm/Passes/StandardInstrumentations.h | 1 +
llvm/lib/Passes/StandardInstrumentations.cpp | 30 ++++++++++++++-----
llvm/test/Other/print-at-pass-number.ll | 3 ++
3 files changed, 27 insertions(+), 7 deletions(-)
diff --git a/llvm/include/llvm/Passes/StandardInstrumentations.h b/llvm/include/llvm/Passes/StandardInstrumentations.h
index 8c6a44876d5459..f60ff17578b6e9 100644
--- a/llvm/include/llvm/Passes/StandardInstrumentations.h
+++ b/llvm/include/llvm/Passes/StandardInstrumentations.h
@@ -66,6 +66,7 @@ class PrintIRInstrumentation {
bool shouldPrintAfterPass(StringRef PassID);
bool shouldPrintPassNumbers();
bool shouldPrintBeforePassNumber();
+ bool shouldPrintAfterPassNumber();
void pushPassRunDescriptor(StringRef PassID, Any IR,
std::string &DumpIRFilename);
diff --git a/llvm/lib/Passes/StandardInstrumentations.cpp b/llvm/lib/Passes/StandardInstrumentations.cpp
index 697988b3fc7c0b..ae3fac39e5b67a 100644
--- a/llvm/lib/Passes/StandardInstrumentations.cpp
+++ b/llvm/lib/Passes/StandardInstrumentations.cpp
@@ -123,6 +123,11 @@ static cl::opt<unsigned> PrintBeforePassNumber(
cl::desc("Print IR before the pass with this number as "
"reported by print-pass-numbers"));
+static cl::opt<unsigned> PrintAfterPassNumber(
+ "print-after-pass-number", cl::init(0), cl::Hidden,
+ cl::desc("Print IR after the pass with this number as "
+ "reported by print-pass-numbers"));
+
static cl::opt<std::string> IRDumpDirectory(
"ir-dump-directory",
cl::desc("If specified, IR printed using the "
@@ -802,6 +807,8 @@ void PrintIRInstrumentation::printBeforePass(StringRef PassID, Any IR) {
(shouldPrintBeforePass(PassID) || shouldPrintAfterPass(PassID)))
DumpIRFilename = fetchDumpFilename(PassID, IR);
+ ++CurrentPassNumber;
+
// Saving Module for AfterPassInvalidated operations.
// Note: here we rely on a fact that we do not change modules while
// traversing the pipeline, so the latest captured module is good
@@ -812,8 +819,6 @@ void PrintIRInstrumentation::printBeforePass(StringRef PassID, Any IR) {
if (!shouldPrintIR(IR))
return;
- ++CurrentPassNumber;
-
if (shouldPrintPassNumbers())
dbgs() << " Running pass " << CurrentPassNumber << " " << PassID
<< " on " << getIRName(IR) << "\n";
@@ -853,8 +858,10 @@ void PrintIRInstrumentation::printAfterPass(StringRef PassID, Any IR) {
return;
auto WriteIRToStream = [&](raw_ostream &Stream, const StringRef IRName) {
- Stream << "; *** IR Dump " << StringRef(formatv("After {0}", PassID))
- << " on " << IRName << " ***\n";
+ Stream << "; *** IR Dump After ";
+ if (shouldPrintAfterPassNumber())
+ Stream << CurrentPassNumber << "-";
+ Stream << StringRef(formatv("{0}", PassID)) << " on " << IRName << " ***\n";
unwrapAndPrint(Stream, IR);
};
@@ -925,6 +932,10 @@ bool PrintIRInstrumentation::shouldPrintAfterPass(StringRef PassID) {
if (shouldPrintAfterAll())
return true;
+ if (shouldPrintAfterPassNumber() &&
+ CurrentPassNumber == PrintAfterPassNumber)
+ return true;
+
StringRef PassName = PIC->getPassNameForClassName(PassID);
return is_contained(printAfterPasses(), PassName);
}
@@ -937,18 +948,23 @@ bool PrintIRInstrumentation::shouldPrintBeforePassNumber() {
return PrintBeforePassNumber > 0;
}
+bool PrintIRInstrumentation::shouldPrintAfterPassNumber() {
+ return PrintAfterPassNumber > 0;
+}
+
void PrintIRInstrumentation::registerCallbacks(
PassInstrumentationCallbacks &PIC) {
this->PIC = &PIC;
// BeforePass callback is not just for printing, it also saves a Module
- // for later use in AfterPassInvalidated.
+ // for later use in AfterPassInvalidated and keeps tracks of the CurrentPassNumber.
if (shouldPrintPassNumbers() || shouldPrintBeforePassNumber() ||
- shouldPrintBeforeSomePass() || shouldPrintAfterSomePass())
+ shouldPrintAfterPassNumber() || shouldPrintBeforeSomePass() ||
+ shouldPrintAfterSomePass())
PIC.registerBeforeNonSkippedPassCallback(
[this](StringRef P, Any IR) { this->printBeforePass(P, IR); });
- if (shouldPrintAfterSomePass()) {
+ if (shouldPrintAfterSomePass() || shouldPrintAfterPassNumber()) {
PIC.registerAfterPassCallback(
[this](StringRef P, Any IR, const PreservedAnalyses &) {
this->printAfterPass(P, IR);
diff --git a/llvm/test/Other/print-at-pass-number.ll b/llvm/test/Other/print-at-pass-number.ll
index b9c09a36ca1fa4..61f083a20233e3 100644
--- a/llvm/test/Other/print-at-pass-number.ll
+++ b/llvm/test/Other/print-at-pass-number.ll
@@ -1,9 +1,12 @@
; RUN: opt -passes="loop(indvars,loop-deletion,loop-unroll-full)" -print-pass-numbers -S -o /dev/null %s 2>&1 | FileCheck %s --check-prefix=NUMBER
; RUN: opt -passes="loop(indvars,loop-deletion,loop-unroll-full)" -print-module-scope -print-before-pass-number=3 -S -o /dev/null %s 2>&1 | FileCheck %s --check-prefix=BEFORE
+; RUN: opt -passes="loop(indvars,loop-deletion,loop-unroll-full)" -print-module-scope -print-after-pass-number=2 -S -o /dev/null %s 2>&1 | FileCheck %s --check-prefix=AFTER
define i32 @bar(i32 %arg) {
; BEFORE: *** IR Dump Before 3-IndVarSimplifyPass on bb1 ***
; BEFORE: define i32 @bar(i32 %arg) {
+; AFTER: *** IR Dump After 2-LCSSAPass on bar ***
+; AFTER: define i32 @bar(i32 %arg) {
bb:
br label %bb1
>From 7de2435cba391ceb7af4e46ae0377b6bde2b6880 Mon Sep 17 00:00:00 2001
From: Vincent Lee <leevince at fb.com>
Date: Wed, 3 Apr 2024 00:54:50 -0700
Subject: [PATCH 2/5] format
---
llvm/lib/Passes/StandardInstrumentations.cpp | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/llvm/lib/Passes/StandardInstrumentations.cpp b/llvm/lib/Passes/StandardInstrumentations.cpp
index ae3fac39e5b67a..aac9a1ecb8e437 100644
--- a/llvm/lib/Passes/StandardInstrumentations.cpp
+++ b/llvm/lib/Passes/StandardInstrumentations.cpp
@@ -123,10 +123,10 @@ static cl::opt<unsigned> PrintBeforePassNumber(
cl::desc("Print IR before the pass with this number as "
"reported by print-pass-numbers"));
-static cl::opt<unsigned> PrintAfterPassNumber(
- "print-after-pass-number", cl::init(0), cl::Hidden,
- cl::desc("Print IR after the pass with this number as "
- "reported by print-pass-numbers"));
+static cl::opt<unsigned>
+ PrintAfterPassNumber("print-after-pass-number", cl::init(0), cl::Hidden,
+ cl::desc("Print IR after the pass with this number as "
+ "reported by print-pass-numbers"));
static cl::opt<std::string> IRDumpDirectory(
"ir-dump-directory",
@@ -932,8 +932,7 @@ bool PrintIRInstrumentation::shouldPrintAfterPass(StringRef PassID) {
if (shouldPrintAfterAll())
return true;
- if (shouldPrintAfterPassNumber() &&
- CurrentPassNumber == PrintAfterPassNumber)
+ if (shouldPrintAfterPassNumber() && CurrentPassNumber == PrintAfterPassNumber)
return true;
StringRef PassName = PIC->getPassNameForClassName(PassID);
@@ -957,7 +956,8 @@ void PrintIRInstrumentation::registerCallbacks(
this->PIC = &PIC;
// BeforePass callback is not just for printing, it also saves a Module
- // for later use in AfterPassInvalidated and keeps tracks of the CurrentPassNumber.
+ // for later use in AfterPassInvalidated and keeps tracks of the
+ // CurrentPassNumber.
if (shouldPrintPassNumbers() || shouldPrintBeforePassNumber() ||
shouldPrintAfterPassNumber() || shouldPrintBeforeSomePass() ||
shouldPrintAfterSomePass())
>From 01fbd9fb900615d63235b1c957f665cd07431cd8 Mon Sep 17 00:00:00 2001
From: Vincent Lee <leevince at fb.com>
Date: Fri, 5 Apr 2024 20:03:14 -0700
Subject: [PATCH 3/5] Allow filtered printIRs to be consecutive
---
llvm/lib/Passes/StandardInstrumentations.cpp | 7 +++++--
llvm/test/Other/print-at-pass-number.ll | 11 +++++++++++
2 files changed, 16 insertions(+), 2 deletions(-)
diff --git a/llvm/lib/Passes/StandardInstrumentations.cpp b/llvm/lib/Passes/StandardInstrumentations.cpp
index aac9a1ecb8e437..d8be8a643b9e08 100644
--- a/llvm/lib/Passes/StandardInstrumentations.cpp
+++ b/llvm/lib/Passes/StandardInstrumentations.cpp
@@ -807,8 +807,6 @@ void PrintIRInstrumentation::printBeforePass(StringRef PassID, Any IR) {
(shouldPrintBeforePass(PassID) || shouldPrintAfterPass(PassID)))
DumpIRFilename = fetchDumpFilename(PassID, IR);
- ++CurrentPassNumber;
-
// Saving Module for AfterPassInvalidated operations.
// Note: here we rely on a fact that we do not change modules while
// traversing the pipeline, so the latest captured module is good
@@ -819,10 +817,15 @@ void PrintIRInstrumentation::printBeforePass(StringRef PassID, Any IR) {
if (!shouldPrintIR(IR))
return;
+ ++CurrentPassNumber;
+
if (shouldPrintPassNumbers())
dbgs() << " Running pass " << CurrentPassNumber << " " << PassID
<< " on " << getIRName(IR) << "\n";
+ if (shouldPrintAfterPass(PassID))
+ pushPassRunDescriptor(PassID, IR, DumpIRFilename);
+
if (!shouldPrintBeforePass(PassID))
return;
diff --git a/llvm/test/Other/print-at-pass-number.ll b/llvm/test/Other/print-at-pass-number.ll
index 61f083a20233e3..770b3d703c0984 100644
--- a/llvm/test/Other/print-at-pass-number.ll
+++ b/llvm/test/Other/print-at-pass-number.ll
@@ -1,4 +1,5 @@
; RUN: opt -passes="loop(indvars,loop-deletion,loop-unroll-full)" -print-pass-numbers -S -o /dev/null %s 2>&1 | FileCheck %s --check-prefix=NUMBER
+; RUN: opt -passes="loop(indvars,loop-deletion,loop-unroll-full)" -print-pass-numbers -filter-print-funcs=baz -S -o /dev/null %s 2>&1 | FileCheck %s --check-prefix=NUMBER-FILTERED
; RUN: opt -passes="loop(indvars,loop-deletion,loop-unroll-full)" -print-module-scope -print-before-pass-number=3 -S -o /dev/null %s 2>&1 | FileCheck %s --check-prefix=BEFORE
; RUN: opt -passes="loop(indvars,loop-deletion,loop-unroll-full)" -print-module-scope -print-after-pass-number=2 -S -o /dev/null %s 2>&1 | FileCheck %s --check-prefix=AFTER
@@ -23,8 +24,18 @@ bb4: ; preds = %bb1
ret i32 %add3
}
+define i32 @baz(i32 %arg) {
+ ret i32 0;
+}
+
; NUMBER: Running pass 1 LoopSimplifyPass on bar
; NUMBER-NEXT: Running pass 2 LCSSAPass on bar
; NUMBER-NEXT: Running pass 3 IndVarSimplifyPass on bb1
; NUMBER-NEXT: Running pass 4 LoopDeletionPass on bb1
+; NUMBER-NEXT: Running pass 5 LoopSimplifyPass on baz
+; NUMBER-NEXT: Running pass 6 LCSSAPass on baz
; NUMBER-NOT: Running pass
+
+; NUMBER-FILTERED: Running pass 1 LoopSimplifyPass on baz
+; NUMBER-FILTERED-NEXT: Running pass 2 LCSSAPass on baz
+
>From 6a8ef16d970ec3eb172b38bf083a7b08d4113905 Mon Sep 17 00:00:00 2001
From: Vincent Lee <leevince at fb.com>
Date: Fri, 5 Apr 2024 20:57:25 -0700
Subject: [PATCH 4/5] Only push PassRunDescriptor if print after pass number
---
.../llvm/Passes/StandardInstrumentations.h | 1 +
llvm/lib/Passes/StandardInstrumentations.cpp | 23 +++++++++++--------
2 files changed, 15 insertions(+), 9 deletions(-)
diff --git a/llvm/include/llvm/Passes/StandardInstrumentations.h b/llvm/include/llvm/Passes/StandardInstrumentations.h
index f60ff17578b6e9..774028a4a4e68a 100644
--- a/llvm/include/llvm/Passes/StandardInstrumentations.h
+++ b/llvm/include/llvm/Passes/StandardInstrumentations.h
@@ -64,6 +64,7 @@ class PrintIRInstrumentation {
bool shouldPrintBeforePass(StringRef PassID);
bool shouldPrintAfterPass(StringRef PassID);
+ bool shouldPrintAfterPassNumberCheck();
bool shouldPrintPassNumbers();
bool shouldPrintBeforePassNumber();
bool shouldPrintAfterPassNumber();
diff --git a/llvm/lib/Passes/StandardInstrumentations.cpp b/llvm/lib/Passes/StandardInstrumentations.cpp
index d8be8a643b9e08..6be0b74c511c8d 100644
--- a/llvm/lib/Passes/StandardInstrumentations.cpp
+++ b/llvm/lib/Passes/StandardInstrumentations.cpp
@@ -804,7 +804,8 @@ void PrintIRInstrumentation::printBeforePass(StringRef PassID, Any IR) {
std::string DumpIRFilename;
if (!IRDumpDirectory.empty() &&
- (shouldPrintBeforePass(PassID) || shouldPrintAfterPass(PassID)))
+ (shouldPrintBeforePass(PassID) || shouldPrintAfterPass(PassID) ||
+ shouldPrintAfterPassNumberCheck()))
DumpIRFilename = fetchDumpFilename(PassID, IR);
// Saving Module for AfterPassInvalidated operations.
@@ -823,7 +824,7 @@ void PrintIRInstrumentation::printBeforePass(StringRef PassID, Any IR) {
dbgs() << " Running pass " << CurrentPassNumber << " " << PassID
<< " on " << getIRName(IR) << "\n";
- if (shouldPrintAfterPass(PassID))
+ if (shouldPrintAfterPassNumberCheck())
pushPassRunDescriptor(PassID, IR, DumpIRFilename);
if (!shouldPrintBeforePass(PassID))
@@ -851,13 +852,14 @@ void PrintIRInstrumentation::printAfterPass(StringRef PassID, Any IR) {
if (isIgnored(PassID))
return;
- if (!shouldPrintAfterPass(PassID))
+ if (!shouldPrintAfterPass(PassID) && !shouldPrintAfterPassNumberCheck())
return;
auto [M, DumpIRFilename, IRName, StoredPassID] = popPassRunDescriptor(PassID);
assert(StoredPassID == PassID && "mismatched PassID");
- if (!shouldPrintIR(IR) || !shouldPrintAfterPass(PassID))
+ if (!shouldPrintIR(IR) ||
+ (!shouldPrintAfterPass(PassID) && !shouldPrintAfterPassNumberCheck()))
return;
auto WriteIRToStream = [&](raw_ostream &Stream, const StringRef IRName) {
@@ -886,14 +888,15 @@ void PrintIRInstrumentation::printAfterPassInvalidated(StringRef PassID) {
if (isIgnored(PassID))
return;
- if (!shouldPrintAfterPass(PassID))
+ if (!shouldPrintAfterPass(PassID) && !shouldPrintAfterPassNumberCheck())
return;
auto [M, DumpIRFilename, IRName, StoredPassID] = popPassRunDescriptor(PassID);
assert(StoredPassID == PassID && "mismatched PassID");
// Additional filtering (e.g. -filter-print-func) can lead to module
// printing being skipped.
- if (!M || !shouldPrintAfterPass(PassID))
+ if (!M ||
+ (!shouldPrintAfterPass(PassID) && !shouldPrintAfterPassNumberCheck()))
return;
auto WriteIRToStream = [&](raw_ostream &Stream, const Module *M,
@@ -935,13 +938,15 @@ bool PrintIRInstrumentation::shouldPrintAfterPass(StringRef PassID) {
if (shouldPrintAfterAll())
return true;
- if (shouldPrintAfterPassNumber() && CurrentPassNumber == PrintAfterPassNumber)
- return true;
-
StringRef PassName = PIC->getPassNameForClassName(PassID);
return is_contained(printAfterPasses(), PassName);
}
+bool PrintIRInstrumentation::shouldPrintAfterPassNumberCheck() {
+ return shouldPrintAfterPassNumber() &&
+ (CurrentPassNumber == PrintAfterPassNumber);
+}
+
bool PrintIRInstrumentation::shouldPrintPassNumbers() {
return PrintPassNumbers;
}
>From 746340135f67017e6398cb90f36ad766d648d9de Mon Sep 17 00:00:00 2001
From: Vincent Lee <leevince at fb.com>
Date: Thu, 11 Apr 2024 01:42:55 -0700
Subject: [PATCH 5/5]
shouldPrintAfter/BeforePassNumber->shouldPrintAfter/BeforeSomePassNumber and
shouldPrintAfter/BeforePassNumberCheck->shouldPrintAfter/BeforeCurrentPassNumber
---
.../llvm/Passes/StandardInstrumentations.h | 7 ++--
llvm/lib/Passes/StandardInstrumentations.cpp | 41 ++++++++++---------
2 files changed, 25 insertions(+), 23 deletions(-)
diff --git a/llvm/include/llvm/Passes/StandardInstrumentations.h b/llvm/include/llvm/Passes/StandardInstrumentations.h
index 774028a4a4e68a..15b73ec702a4fa 100644
--- a/llvm/include/llvm/Passes/StandardInstrumentations.h
+++ b/llvm/include/llvm/Passes/StandardInstrumentations.h
@@ -64,10 +64,11 @@ class PrintIRInstrumentation {
bool shouldPrintBeforePass(StringRef PassID);
bool shouldPrintAfterPass(StringRef PassID);
- bool shouldPrintAfterPassNumberCheck();
+ bool shouldPrintBeforeCurrentPassNumber();
+ bool shouldPrintAfterCurrentPassNumber();
bool shouldPrintPassNumbers();
- bool shouldPrintBeforePassNumber();
- bool shouldPrintAfterPassNumber();
+ bool shouldPrintBeforeSomePassNumber();
+ bool shouldPrintAfterSomePassNumber();
void pushPassRunDescriptor(StringRef PassID, Any IR,
std::string &DumpIRFilename);
diff --git a/llvm/lib/Passes/StandardInstrumentations.cpp b/llvm/lib/Passes/StandardInstrumentations.cpp
index 6be0b74c511c8d..d4ef236c517431 100644
--- a/llvm/lib/Passes/StandardInstrumentations.cpp
+++ b/llvm/lib/Passes/StandardInstrumentations.cpp
@@ -805,7 +805,7 @@ void PrintIRInstrumentation::printBeforePass(StringRef PassID, Any IR) {
std::string DumpIRFilename;
if (!IRDumpDirectory.empty() &&
(shouldPrintBeforePass(PassID) || shouldPrintAfterPass(PassID) ||
- shouldPrintAfterPassNumberCheck()))
+ shouldPrintBeforeCurrentPassNumber() || shouldPrintAfterCurrentPassNumber()))
DumpIRFilename = fetchDumpFilename(PassID, IR);
// Saving Module for AfterPassInvalidated operations.
@@ -824,15 +824,15 @@ void PrintIRInstrumentation::printBeforePass(StringRef PassID, Any IR) {
dbgs() << " Running pass " << CurrentPassNumber << " " << PassID
<< " on " << getIRName(IR) << "\n";
- if (shouldPrintAfterPassNumberCheck())
+ if (shouldPrintAfterCurrentPassNumber())
pushPassRunDescriptor(PassID, IR, DumpIRFilename);
- if (!shouldPrintBeforePass(PassID))
+ if (!shouldPrintBeforePass(PassID) && !shouldPrintBeforeCurrentPassNumber())
return;
auto WriteIRToStream = [&](raw_ostream &Stream) {
Stream << "; *** IR Dump Before ";
- if (shouldPrintBeforePassNumber())
+ if (shouldPrintBeforeSomePassNumber())
Stream << CurrentPassNumber << "-";
Stream << PassID << " on " << getIRName(IR) << " ***\n";
unwrapAndPrint(Stream, IR);
@@ -852,19 +852,19 @@ void PrintIRInstrumentation::printAfterPass(StringRef PassID, Any IR) {
if (isIgnored(PassID))
return;
- if (!shouldPrintAfterPass(PassID) && !shouldPrintAfterPassNumberCheck())
+ if (!shouldPrintAfterPass(PassID) && !shouldPrintAfterCurrentPassNumber())
return;
auto [M, DumpIRFilename, IRName, StoredPassID] = popPassRunDescriptor(PassID);
assert(StoredPassID == PassID && "mismatched PassID");
if (!shouldPrintIR(IR) ||
- (!shouldPrintAfterPass(PassID) && !shouldPrintAfterPassNumberCheck()))
+ (!shouldPrintAfterPass(PassID) && !shouldPrintAfterCurrentPassNumber()))
return;
auto WriteIRToStream = [&](raw_ostream &Stream, const StringRef IRName) {
Stream << "; *** IR Dump After ";
- if (shouldPrintAfterPassNumber())
+ if (shouldPrintAfterSomePassNumber())
Stream << CurrentPassNumber << "-";
Stream << StringRef(formatv("{0}", PassID)) << " on " << IRName << " ***\n";
unwrapAndPrint(Stream, IR);
@@ -888,7 +888,7 @@ void PrintIRInstrumentation::printAfterPassInvalidated(StringRef PassID) {
if (isIgnored(PassID))
return;
- if (!shouldPrintAfterPass(PassID) && !shouldPrintAfterPassNumberCheck())
+ if (!shouldPrintAfterPass(PassID) && !shouldPrintAfterCurrentPassNumber())
return;
auto [M, DumpIRFilename, IRName, StoredPassID] = popPassRunDescriptor(PassID);
@@ -896,7 +896,7 @@ void PrintIRInstrumentation::printAfterPassInvalidated(StringRef PassID) {
// Additional filtering (e.g. -filter-print-func) can lead to module
// printing being skipped.
if (!M ||
- (!shouldPrintAfterPass(PassID) && !shouldPrintAfterPassNumberCheck()))
+ (!shouldPrintAfterPass(PassID) && !shouldPrintAfterCurrentPassNumber()))
return;
auto WriteIRToStream = [&](raw_ostream &Stream, const Module *M,
@@ -926,10 +926,6 @@ bool PrintIRInstrumentation::shouldPrintBeforePass(StringRef PassID) {
if (shouldPrintBeforeAll())
return true;
- if (shouldPrintBeforePassNumber() &&
- CurrentPassNumber == PrintBeforePassNumber)
- return true;
-
StringRef PassName = PIC->getPassNameForClassName(PassID);
return is_contained(printBeforePasses(), PassName);
}
@@ -942,8 +938,13 @@ bool PrintIRInstrumentation::shouldPrintAfterPass(StringRef PassID) {
return is_contained(printAfterPasses(), PassName);
}
-bool PrintIRInstrumentation::shouldPrintAfterPassNumberCheck() {
- return shouldPrintAfterPassNumber() &&
+bool PrintIRInstrumentation::shouldPrintBeforeCurrentPassNumber() {
+ return shouldPrintBeforeSomePassNumber() &&
+ (CurrentPassNumber == PrintBeforePassNumber);
+}
+
+bool PrintIRInstrumentation::shouldPrintAfterCurrentPassNumber() {
+ return shouldPrintAfterSomePassNumber() &&
(CurrentPassNumber == PrintAfterPassNumber);
}
@@ -951,11 +952,11 @@ bool PrintIRInstrumentation::shouldPrintPassNumbers() {
return PrintPassNumbers;
}
-bool PrintIRInstrumentation::shouldPrintBeforePassNumber() {
+bool PrintIRInstrumentation::shouldPrintBeforeSomePassNumber() {
return PrintBeforePassNumber > 0;
}
-bool PrintIRInstrumentation::shouldPrintAfterPassNumber() {
+bool PrintIRInstrumentation::shouldPrintAfterSomePassNumber() {
return PrintAfterPassNumber > 0;
}
@@ -966,13 +967,13 @@ void PrintIRInstrumentation::registerCallbacks(
// BeforePass callback is not just for printing, it also saves a Module
// for later use in AfterPassInvalidated and keeps tracks of the
// CurrentPassNumber.
- if (shouldPrintPassNumbers() || shouldPrintBeforePassNumber() ||
- shouldPrintAfterPassNumber() || shouldPrintBeforeSomePass() ||
+ if (shouldPrintPassNumbers() || shouldPrintBeforeSomePassNumber() ||
+ shouldPrintAfterSomePassNumber() || shouldPrintBeforeSomePass() ||
shouldPrintAfterSomePass())
PIC.registerBeforeNonSkippedPassCallback(
[this](StringRef P, Any IR) { this->printBeforePass(P, IR); });
- if (shouldPrintAfterSomePass() || shouldPrintAfterPassNumber()) {
+ if (shouldPrintAfterSomePass() || shouldPrintAfterSomePassNumber()) {
PIC.registerAfterPassCallback(
[this](StringRef P, Any IR, const PreservedAnalyses &) {
this->printAfterPass(P, IR);
More information about the llvm-commits
mailing list