Skip to content

Commit

Permalink
NFC: Print the generic op form after pass failure.
Browse files Browse the repository at this point in the history
On failure, the IR is likely to be in an invalid state, meaning the custom printer for some operations may now crash. Using the generic op form prevents this from happening.

PiperOrigin-RevId: 274104146
  • Loading branch information
River707 authored and tensorflower-gardener committed Oct 11, 2019
1 parent 7a7dcc1 commit 978b209
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions mlir/lib/Pass/IRPrinting.cpp
Expand Up @@ -63,15 +63,16 @@ static bool isHiddenPass(Pass *pass) {
return isAdaptorPass(pass) || isa<VerifierPass>(pass);
}

static void printIR(Operation *op, bool printModuleScope, raw_ostream &out) {
static void printIR(Operation *op, bool printModuleScope, raw_ostream &out,
OpPrintingFlags flags) {
// Check to see if we are printing the top-level module.
auto module = dyn_cast<ModuleOp>(op);
if (module && !op->getBlock())
return module.print(out << "\n");
return module.print(out << "\n", flags);

// Otherwise, check to see if we are not printing at module scope.
if (!printModuleScope)
return op->print(out << "\n");
return op->print(out << "\n", flags);

// Otherwise, we are printing at module scope.
out << " ('" << op->getName() << "' operation";
Expand All @@ -88,9 +89,9 @@ static void printIR(Operation *op, bool printModuleScope, raw_ostream &out) {
// Check to see if the top-level operation is actually a module in the case of
// invalid-ir.
if (auto module = dyn_cast<ModuleOp>(topLevelOp))
module.print(out);
module.print(out, flags);
else
topLevelOp->print(out);
topLevelOp->print(out, flags);
}

/// Instrumentation hooks.
Expand All @@ -100,7 +101,7 @@ void IRPrinterInstrumentation::runBeforePass(Pass *pass, Operation *op) {
!shouldPrintBeforePass(pass))
return;
out << formatv("*** IR Dump Before {0} ***", pass->getName());
printIR(op, printModuleScope, out);
printIR(op, printModuleScope, out, OpPrintingFlags());
out << "\n\n";
}

Expand All @@ -110,7 +111,7 @@ void IRPrinterInstrumentation::runAfterPass(Pass *pass, Operation *op) {
!shouldPrintAfterPass(pass))
return;
out << formatv("*** IR Dump After {0} ***", pass->getName());
printIR(op, printModuleScope, out);
printIR(op, printModuleScope, out, OpPrintingFlags());
out << "\n\n";
}

Expand All @@ -120,7 +121,7 @@ void IRPrinterInstrumentation::runAfterPassFailed(Pass *pass, Operation *op) {
!shouldPrintAfterPass(pass))
return;
out << formatv("*** IR Dump After {0} Failed ***", pass->getName());
printIR(op, printModuleScope, out);
printIR(op, printModuleScope, out, OpPrintingFlags().printGenericOpForm());
out << "\n\n";
}

Expand Down

0 comments on commit 978b209

Please sign in to comment.