diff --git a/mlir/docs/PassManagement.md b/mlir/docs/PassManagement.md --- a/mlir/docs/PassManagement.md +++ b/mlir/docs/PassManagement.md @@ -1333,9 +1333,9 @@ #-} ``` -The configuration dumped can be passed to `mlir-opt`. This will result in -parsing the configuration of the reproducer and adjusting the necessary opt -state, e.g. configuring the pass manager, context, etc. +The configuration dumped can be passed to `mlir-opt` by specifying +`-run-reproducer` flag. This will result in parsing the configuration of the reproducer +and adjusting the necessary opt state, e.g. configuring the pass manager, context, etc. Beyond specifying a filename, one can also register a `ReproducerStreamFactory` function that would be invoked in the case of a crash and the reproducer written diff --git a/mlir/include/mlir/Tools/mlir-opt/MlirOptMain.h b/mlir/include/mlir/Tools/mlir-opt/MlirOptMain.h --- a/mlir/include/mlir/Tools/mlir-opt/MlirOptMain.h +++ b/mlir/include/mlir/Tools/mlir-opt/MlirOptMain.h @@ -116,6 +116,16 @@ return success(); } + /// Enable running the reproducer information stored in resources (if + /// present). + MlirOptMainConfig &runReproducer(bool enableReproducer) { + runReproducerFlag = enableReproducer; + return *this; + }; + + /// Return true if the reproducer should be run. + bool shouldRunReproducer() const { return runReproducerFlag; } + /// Show the registered dialects before trying to load the input file. MlirOptMainConfig &showDialects(bool show) { showDialectsFlag = show; @@ -183,6 +193,9 @@ /// The callback to populate the pass manager. std::function passPipelineCallback; + /// Enable running the reproducer. + bool runReproducerFlag = false; + /// Show the registered dialects before trying to load the input file. bool showDialectsFlag = false; 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 @@ -113,6 +113,10 @@ "parsing"), cl::location(useExplicitModuleFlag), cl::init(false)); + static cl::opt runReproducer( + "run-reproducer", cl::desc("Run the pipeline stored in the reproducer"), + cl::location(runReproducerFlag), cl::init(false)); + static cl::opt showDialects( "show-dialects", cl::desc("Print the list of registered dialects and exit"), @@ -236,7 +240,8 @@ FallbackAsmResourceMap fallbackResourceMap; ParserConfig parseConfig(context, /*verifyAfterParse=*/true, &fallbackResourceMap); - reproOptions.attachResourceParser(parseConfig); + if (config.shouldRunReproducer()) + reproOptions.attachResourceParser(parseConfig); // Parse the input file and reset the context threading state. TimingScope parserTiming = timing.nest("Parser"); @@ -253,7 +258,9 @@ if (failed(applyPassManagerCLOptions(pm))) return failure(); pm.enableTiming(timing); - if (failed(reproOptions.apply(pm)) || failed(config.setupPassPipeline(pm))) + if (config.shouldRunReproducer() && failed(reproOptions.apply(pm))) + return failure(); + if (failed(config.setupPassPipeline(pm))) return failure(); // Run the pipeline. diff --git a/mlir/test/Pass/run-reproducer.mlir b/mlir/test/Pass/run-reproducer.mlir --- a/mlir/test/Pass/run-reproducer.mlir +++ b/mlir/test/Pass/run-reproducer.mlir @@ -1,5 +1,5 @@ -// RUN: mlir-opt %s -dump-pass-pipeline 2>&1 | FileCheck %s -// RUN: mlir-opt %s -mlir-print-ir-before=cse 2>&1 | FileCheck -check-prefix=BEFORE %s +// RUN: mlir-opt %s --run-reproducer -dump-pass-pipeline 2>&1 | FileCheck %s +// RUN: mlir-opt %s --run-reproducer -mlir-print-ir-before=cse 2>&1 | FileCheck -check-prefix=BEFORE %s func.func @foo() { %0 = arith.constant 0 : i32