From 0e3260bc7310f2b8fd8bc2919e9d5965ac3bf22e Mon Sep 17 00:00:00 2001 From: River Riddle Date: Fri, 12 Jul 2019 11:20:09 -0700 Subject: [PATCH] Change the IR printing pass instrumentation to ignore the verifier passes on non-failure. The verifier passes are NO-OP and are only useful to print after in the case of failure. This removes a lot of unnecessary clutter when printing after/before all passes. PiperOrigin-RevId: 257836310 --- mlir/lib/Pass/IRPrinting.cpp | 12 ++++++++++-- mlir/lib/Pass/Pass.cpp | 38 ++++++++++++++++-------------------- mlir/lib/Pass/PassDetail.h | 19 ++++++++++++++++++ 3 files changed, 46 insertions(+), 23 deletions(-) diff --git a/mlir/lib/Pass/IRPrinting.cpp b/mlir/lib/Pass/IRPrinting.cpp index 4d07d911ab13..2de4b05a36c8 100644 --- a/mlir/lib/Pass/IRPrinting.cpp +++ b/mlir/lib/Pass/IRPrinting.cpp @@ -58,6 +58,11 @@ private: }; } // end anonymous namespace +/// Returns true if the given pass is hidden from IR printing. +static bool isHiddenPass(Pass *pass) { + return isAdaptorPass(pass) || isVerifierPass(pass); +} + static void printIR(const llvm::Any &ir, bool printModuleScope, raw_ostream &out) { // Check for printing at module scope. @@ -87,20 +92,22 @@ static void printIR(const llvm::Any &ir, bool printModuleScope, /// Instrumentation hooks. void IRPrinterInstrumentation::runBeforePass(Pass *pass, const llvm::Any &ir) { // Skip adaptor passes and passes that the user filtered out. - if (!shouldPrintBeforePass || isAdaptorPass(pass) || + if (!shouldPrintBeforePass || isHiddenPass(pass) || !shouldPrintBeforePass(pass)) return; out << formatv("*** IR Dump Before {0} ***", pass->getName()); printIR(ir, printModuleScope, out); + out << "\n\n"; } void IRPrinterInstrumentation::runAfterPass(Pass *pass, const llvm::Any &ir) { // Skip adaptor passes and passes that the user filtered out. - if (!shouldPrintAfterPass || isAdaptorPass(pass) || + if (!shouldPrintAfterPass || isHiddenPass(pass) || !shouldPrintAfterPass(pass)) return; out << formatv("*** IR Dump After {0} ***", pass->getName()); printIR(ir, printModuleScope, out); + out << "\n\n"; } void IRPrinterInstrumentation::runAfterPassFailed(Pass *pass, @@ -111,6 +118,7 @@ void IRPrinterInstrumentation::runAfterPassFailed(Pass *pass, return; out << formatv("*** IR Dump After {0} Failed ***", pass->getName()); printIR(ir, printModuleScope, out); + out << "\n\n"; } //===----------------------------------------------------------------------===// diff --git a/mlir/lib/Pass/Pass.cpp b/mlir/lib/Pass/Pass.cpp index 125fcd37cbb7..3ed7b248042b 100644 --- a/mlir/lib/Pass/Pass.cpp +++ b/mlir/lib/Pass/Pass.cpp @@ -226,28 +226,24 @@ void ModuleToFunctionPassAdaptorParallel::runOnModule() { } //===----------------------------------------------------------------------===// -// PassManager +// Verifier Passes //===----------------------------------------------------------------------===// -namespace { -/// Pass to verify a function and signal failure if necessary. -class FunctionVerifier : public FunctionPass { - void runOnFunction() { - if (failed(verify(getFunction()))) - signalPassFailure(); - markAllAnalysesPreserved(); - } -}; +void FunctionVerifierPass::runOnFunction() { + if (failed(verify(getFunction()))) + signalPassFailure(); + markAllAnalysesPreserved(); +} -/// Pass to verify a module and signal failure if necessary. -class ModuleVerifier : public ModulePass { - void runOnModule() { - if (failed(verify(getModule()))) - signalPassFailure(); - markAllAnalysesPreserved(); - } -}; -} // end anonymous namespace +void ModuleVerifierPass::runOnModule() { + if (failed(verify(getModule()))) + signalPassFailure(); + markAllAnalysesPreserved(); +} + +//===----------------------------------------------------------------------===// +// PassManager +//===----------------------------------------------------------------------===// PassManager::PassManager(bool verifyPasses) : mpe(new ModulePassExecutor()), verifyPasses(verifyPasses), @@ -287,7 +283,7 @@ void PassManager::addPass(ModulePassBase *pass) { // Add a verifier run if requested. if (verifyPasses) - mpe->addPass(new ModuleVerifier()); + mpe->addPass(new ModuleVerifierPass()); } /// Add a function pass to the current manager. This takes ownership over the @@ -317,7 +313,7 @@ void PassManager::addPass(FunctionPassBase *pass) { // Add a verifier run if requested. if (verifyPasses) - fpe->addPass(new FunctionVerifier()); + fpe->addPass(new FunctionVerifierPass()); } /// Add the provided instrumentation to the pass manager. This takes ownership diff --git a/mlir/lib/Pass/PassDetail.h b/mlir/lib/Pass/PassDetail.h index 62fd9afc1f91..0b41c44ef146 100644 --- a/mlir/lib/Pass/PassDetail.h +++ b/mlir/lib/Pass/PassDetail.h @@ -22,6 +22,20 @@ namespace mlir { namespace detail { +//===----------------------------------------------------------------------===// +// Verifier Passes +//===----------------------------------------------------------------------===// + +/// Pass to verify a function and signal failure if necessary. +class FunctionVerifierPass : public FunctionPass { + void runOnFunction() override; +}; + +/// Pass to verify a module and signal failure if necessary. +class ModuleVerifierPass : public ModulePass { + void runOnModule() override; +}; + //===----------------------------------------------------------------------===// // PassExecutor //===----------------------------------------------------------------------===// @@ -146,6 +160,11 @@ inline bool isAdaptorPass(Pass *pass) { return isModuleToFunctionAdaptorPass(pass); } +/// Utility function to return if a pass refers to a verifier pass. +inline bool isVerifierPass(Pass *pass) { + return isa(pass) || isa(pass); +} + } // end namespace detail } // end namespace mlir #endif // MLIR_PASS_PASSDETAIL_H_