diff --git a/mlir/include/mlir/Pass/PassRegistry.h b/mlir/include/mlir/Pass/PassRegistry.h --- a/mlir/include/mlir/Pass/PassRegistry.h +++ b/mlir/include/mlir/Pass/PassRegistry.h @@ -281,11 +281,12 @@ //===----------------------------------------------------------------------===// /// Attach an assembly resource parser that handles MLIR reproducer -/// configurations. Any found reproducer information will be attached to the -/// given pass manager, e.g. the reproducer pipeline, verification flags, etc. +/// configurations. // FIXME: Remove the `enableThreading` flag when possible. Some tools, e.g. // mlir-opt, force disable threading during parsing. -void attachPassReproducerAsmResource(ParserConfig &config, PassManager &pm, +void attachPassReproducerAsmResource(ParserConfig &config, + std::string &pipelineStr, + bool &enableVerifier, bool &enableThreading); } // namespace mlir diff --git a/mlir/lib/Pass/PassCrashRecovery.cpp b/mlir/lib/Pass/PassCrashRecovery.cpp --- a/mlir/lib/Pass/PassCrashRecovery.cpp +++ b/mlir/lib/Pass/PassCrashRecovery.cpp @@ -444,14 +444,15 @@ //===----------------------------------------------------------------------===// void mlir::attachPassReproducerAsmResource(ParserConfig &config, - PassManager &pm, + std::string &pipelineStr, + bool &enableVerifier, bool &enableThreading) { auto parseFn = [&](AsmParsedResourceEntry &entry) -> LogicalResult { if (entry.getKey() == "pipeline") { - FailureOr pipeline = entry.parseAsString(); - if (failed(pipeline)) - return failure(); - return parsePassPipeline(*pipeline, pm); + FailureOr value = entry.parseAsString(); + if (succeeded(value)) + pipelineStr = std::move(*value); + return value; } if (entry.getKey() == "disable_threading") { FailureOr value = entry.parseAsBool(); @@ -465,7 +466,7 @@ if (entry.getKey() == "verify_each") { FailureOr value = entry.parseAsBool(); if (succeeded(value)) - pm.enableVerifier(*value); + enableVerifier = *value; return value; } return entry.emitError() << "unknown 'mlir_reproducer' resource key '" diff --git a/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp b/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp --- a/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp +++ b/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp @@ -59,16 +59,12 @@ bool wasThreadingEnabled = context->isMultithreadingEnabled(); context->disableMultithreading(); - // Prepare the pass manager and apply any command line options. - PassManager pm(context, OpPassManager::Nesting::Implicit); - pm.enableVerifier(verifyPasses); - applyPassManagerCLOptions(pm); - pm.enableTiming(timing); - // Prepare the parser config, and attach any useful/necessary resource // handlers. ParserConfig config(context); - attachPassReproducerAsmResource(config, pm, wasThreadingEnabled); + std::string reproPipeline; + attachPassReproducerAsmResource(config, reproPipeline, verifyPasses, + wasThreadingEnabled); // Parse the input file and reset the context threading state. TimingScope parserTiming = timing.nest("Parser"); @@ -78,7 +74,14 @@ return failure(); parserTiming.stop(); - // Callback to build the pipeline. + // Prepare the pass manager, applying command-line and reproducer options. + PassManager pm(context, OpPassManager::Nesting::Implicit, + module->getOperationName()); + pm.enableVerifier(verifyPasses); + applyPassManagerCLOptions(pm); + pm.enableTiming(timing); + if (failed(parsePassPipeline(reproPipeline, pm))) + return failure(); if (failed(passManagerSetupFn(pm))) return failure();