};
} // 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.
/// 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,
return;
out << formatv("*** IR Dump After {0} Failed ***", pass->getName());
printIR(ir, printModuleScope, out);
+ out << "\n\n";
}
//===----------------------------------------------------------------------===//
}
//===----------------------------------------------------------------------===//
-// 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),
// 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
// 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
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
//===----------------------------------------------------------------------===//
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_