Change the IR printing pass instrumentation to ignore the verifier passes on non...
authorRiver Riddle <riverriddle@google.com>
Fri, 12 Jul 2019 18:20:09 +0000 (11:20 -0700)
committerMehdi Amini <joker.eph@gmail.com>
Sat, 13 Jul 2019 00:42:46 +0000 (17:42 -0700)
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
mlir/lib/Pass/Pass.cpp
mlir/lib/Pass/PassDetail.h

index 4d07d911ab13fb0a6dd30156007342c0b0d510fa..2de4b05a36c831f98df0ae76aa1a2af55793451b 100644 (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";
 }
 
 //===----------------------------------------------------------------------===//
index 125fcd37cbb706758f9af8b1edf4e1b5963fa731..3ed7b248042b696b831566671cd23aad6d188564 100644 (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
index 62fd9afc1f919160042c861f9e0a7d8b8f354ae8..0b41c44ef146ddc94e2a4ca0f63abebdfde65f00 100644 (file)
 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_