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
This commit is contained in:
River Riddle
2019-07-12 11:20:09 -07:00
committed by Mehdi Amini
parent 8e349a48b6
commit 0e3260bc73
3 changed files with 46 additions and 23 deletions

View File

@@ -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";
}
//===----------------------------------------------------------------------===//

View File

@@ -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<FunctionVerifier> {
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<ModuleVerifier> {
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

View File

@@ -22,6 +22,20 @@
namespace mlir {
namespace detail {
//===----------------------------------------------------------------------===//
// Verifier Passes
//===----------------------------------------------------------------------===//
/// Pass to verify a function and signal failure if necessary.
class FunctionVerifierPass : public FunctionPass<FunctionVerifierPass> {
void runOnFunction() override;
};
/// Pass to verify a module and signal failure if necessary.
class ModuleVerifierPass : public ModulePass<ModuleVerifierPass> {
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<FunctionVerifierPass>(pass) || isa<ModuleVerifierPass>(pass);
}
} // end namespace detail
} // end namespace mlir
#endif // MLIR_PASS_PASSDETAIL_H_