From 6144fc2da1b87dc64ff887d73b60f7708f5cb0a4 Mon Sep 17 00:00:00 2001 From: Arthur Eubanks Date: Mon, 19 Jul 2021 10:32:12 -0700 Subject: [PATCH] [NewPM] Print pre-transformation IR name in --print-after-all Sometimes a transformation can change the name of some IR (e.g. an SCC with functions added/removed). This can be confusing when debug logging doesn't match the post-transformation name. The specific example I came across was that --print-after-all said the inliner was working on an SCC that only contained one function, but calls in multiple functions were getting inlined. After all inlining, the current SCC only contained one function. Piggyback off of the existing logic to handle invalidated IR + --print-module-scope. Simply always store the IR description and use that. Reviewed By: jamieschmeiser Differential Revision: https://reviews.llvm.org/D106290 --- .../include/llvm/Passes/StandardInstrumentations.h | 1 - llvm/lib/Passes/StandardInstrumentations.cpp | 23 +++++++++------------- llvm/test/Other/loop-deletion-printer.ll | 6 ++---- llvm/test/Other/scc-deleted-printer.ll | 17 ++++++---------- 4 files changed, 17 insertions(+), 30 deletions(-) diff --git a/llvm/include/llvm/Passes/StandardInstrumentations.h b/llvm/include/llvm/Passes/StandardInstrumentations.h index 9011c52..2f57358 100644 --- a/llvm/include/llvm/Passes/StandardInstrumentations.h +++ b/llvm/include/llvm/Passes/StandardInstrumentations.h @@ -61,7 +61,6 @@ private: /// Stack of Module description, enough to print the module after a given /// pass. SmallVector ModuleDescStack; - bool StoreModuleDesc = false; }; class OptNoneInstrumentation { diff --git a/llvm/lib/Passes/StandardInstrumentations.cpp b/llvm/lib/Passes/StandardInstrumentations.cpp index a03e0d4..5a48923 100644 --- a/llvm/lib/Passes/StandardInstrumentations.cpp +++ b/llvm/lib/Passes/StandardInstrumentations.cpp @@ -709,7 +709,6 @@ PrintIRInstrumentation::~PrintIRInstrumentation() { } void PrintIRInstrumentation::pushModuleDesc(StringRef PassID, Any IR) { - assert(StoreModuleDesc); const Module *M = unwrapModule(IR); ModuleDescStack.emplace_back(M, getIRName(IR), PassID); } @@ -730,7 +729,7 @@ void PrintIRInstrumentation::printBeforePass(StringRef PassID, Any IR) { // Note: here we rely on a fact that we do not change modules while // traversing the pipeline, so the latest captured module is good // for all print operations that has not happen yet. - if (StoreModuleDesc && shouldPrintAfterPass(PassID)) + if (shouldPrintAfterPass(PassID)) pushModuleDesc(PassID, IR); if (!shouldPrintBeforePass(PassID)) @@ -751,25 +750,22 @@ void PrintIRInstrumentation::printAfterPass(StringRef PassID, Any IR) { if (!shouldPrintAfterPass(PassID)) return; - if (StoreModuleDesc) { - const Module *M; - std::string IRName; - StringRef StoredPassID; - std::tie(M, IRName, StoredPassID) = popModuleDesc(PassID); - assert(StoredPassID == PassID && "mismatched PassID"); - } + const Module *M; + std::string IRName; + StringRef StoredPassID; + std::tie(M, IRName, StoredPassID) = popModuleDesc(PassID); + assert(StoredPassID == PassID && "mismatched PassID"); if (!shouldPrintIR(IR)) return; - dbgs() << "*** IR Dump After " << PassID << " on " << getIRName(IR) - << " ***\n"; + dbgs() << "*** IR Dump After " << PassID << " on " << IRName << " ***\n"; unwrapAndPrint(dbgs(), IR); } void PrintIRInstrumentation::printAfterPassInvalidated(StringRef PassID) { StringRef PassName = PIC->getPassNameForClassName(PassID); - if (!StoreModuleDesc || !shouldPrintAfterPass(PassName)) + if (!shouldPrintAfterPass(PassName)) return; if (isIgnored(PassID)) @@ -813,8 +809,7 @@ void PrintIRInstrumentation::registerCallbacks( // BeforePass callback is not just for printing, it also saves a Module // for later use in AfterPassInvalidated. - StoreModuleDesc = forcePrintModuleIR() && shouldPrintAfterSomePass(); - if (shouldPrintBeforeSomePass() || StoreModuleDesc) + if (shouldPrintBeforeSomePass() || shouldPrintAfterSomePass()) PIC.registerBeforeNonSkippedPassCallback( [this](StringRef P, Any IR) { this->printBeforePass(P, IR); }); diff --git a/llvm/test/Other/loop-deletion-printer.ll b/llvm/test/Other/loop-deletion-printer.ll index 53971b8..bce32db 100644 --- a/llvm/test/Other/loop-deletion-printer.ll +++ b/llvm/test/Other/loop-deletion-printer.ll @@ -6,13 +6,11 @@ ; RUN: opt < %s -disable-output \ ; RUN: -passes=loop-deletion,loop-instsimplify -print-after-all 2>&1 | FileCheck %s -check-prefix=DELETED ; RUN: opt < %s -disable-output \ -; RUN: -passes=loop-deletion,loop-instsimplify -print-after-all -print-module-scope 2>&1 | FileCheck %s -check-prefix=DELETED-BUT-PRINTED +; RUN: -passes=loop-deletion,loop-instsimplify -print-after-all -print-module-scope 2>&1 | FileCheck %s -check-prefix=DELETED ; ; SIMPLIFY: IR Dump {{.*}} LoopInstSimplifyPass +; DELETED: IR Dump {{.*}}LoopDeletionPass {{.*}}(invalidated) ; DELETED-NOT: IR Dump {{.*}}LoopInstSimplifyPass -; DELETED-NOT: IR Dump {{.*}}LoopDeletionPass -; DELETED-BUT-PRINTED: IR Dump {{.*}}LoopDeletionPass {{.*}}(invalidated) -; DELETED-BUT-PRINTED-NOT: IR Dump {{.*}}LoopInstSimplifyPass define void @deleteme() { entry: diff --git a/llvm/test/Other/scc-deleted-printer.ll b/llvm/test/Other/scc-deleted-printer.ll index 05b2f45..86171d9 100644 --- a/llvm/test/Other/scc-deleted-printer.ll +++ b/llvm/test/Other/scc-deleted-printer.ll @@ -1,17 +1,12 @@ ; RUN: opt < %s 2>&1 -disable-output \ -; RUN: -passes=inline -print-before-all -print-after-all | FileCheck %s -check-prefix=INL +; RUN: -passes=inline -print-before-all -print-after-all | FileCheck %s ; RUN: opt < %s 2>&1 -disable-output \ -; RUN: -passes=inline -print-before-all -print-after-all -print-module-scope | FileCheck %s -check-prefix=INL-MOD +; RUN: -passes=inline -print-before-all -print-after-all -print-module-scope | FileCheck %s -; INL: IR Dump Before InlinerPass on (tester, foo) -; INL-NOT: IR Dump After {{InlinerPass}} -; INL: IR Dump Before InlinerPass on (tester) -; INL: IR Dump After InlinerPass on (tester) - -; INL-MOD: IR Dump Before InlinerPass on (tester, foo) -; INL-MOD: IR Dump After InlinerPass on (tester, foo) (invalidated) -; INL-MOD: IR Dump Before InlinerPass on (tester) -; INL-MOD: IR Dump After InlinerPass on (tester) +; CHECK: IR Dump Before InlinerPass on (tester, foo) +; CHECK: IR Dump After InlinerPass on (tester, foo) (invalidated) +; CHECK: IR Dump Before InlinerPass on (tester) +; CHECK: IR Dump After InlinerPass on (tester) define void @tester() noinline { -- 2.7.4