[Mlir-commits] [mlir] [mlir][reducer] Add opt-pass-file option to opt-reduction pass (PR #189353)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Mon Mar 30 03:54:22 PDT 2026


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-mlir

Author: lonely eagle (linuxlonelyeagle)

<details>
<summary>Changes</summary>

Currently, the opt-reduction-pass only supports inputting the optimization pipeline via the command line, which becomes cumbersome when the pipeline is long. To address this, this PR introduces the opt-pass-file option. This allows users to save the pipeline in a file and provide the filename to parse the pipeline.

---
Full diff: https://github.com/llvm/llvm-project/pull/189353.diff


4 Files Affected:

- (modified) mlir/include/mlir/Reducer/Passes.td (+2) 
- (modified) mlir/lib/Reducer/OptReductionPass.cpp (+15-4) 
- (added) mlir/test/mlir-reduce/dce-pipeline (+1) 
- (modified) mlir/test/mlir-reduce/dce-test.mlir (+4) 


``````````diff
diff --git a/mlir/include/mlir/Reducer/Passes.td b/mlir/include/mlir/Reducer/Passes.td
index 624e2e1edc329..220303eb39e74 100644
--- a/mlir/include/mlir/Reducer/Passes.td
+++ b/mlir/include/mlir/Reducer/Passes.td
@@ -40,6 +40,8 @@ def OptReductionPass : Pass<"opt-reduction-pass", "ModuleOp"> {
   let options = [
     Option<"optPass", "opt-pass", "std::string", /* default */"",
            "The optimization passes used for reduction, e.g., symbol-dce">,
+    Option<"optPassFile", "opt-pass-file", "std::string", /* default */"",
+           "The file path containing the optimization pipeline definition">,
   ] # CommonReductionPassOptions.options;
 }
 
diff --git a/mlir/lib/Reducer/OptReductionPass.cpp b/mlir/lib/Reducer/OptReductionPass.cpp
index 4bdc7b17567d9..99b0b0ddc3ec6 100644
--- a/mlir/lib/Reducer/OptReductionPass.cpp
+++ b/mlir/lib/Reducer/OptReductionPass.cpp
@@ -18,6 +18,7 @@
 #include "mlir/Reducer/Tester.h"
 
 #include "llvm/Support/DebugLog.h"
+#include "llvm/Support/MemoryBuffer.h"
 
 namespace mlir {
 #define GEN_PASS_DEF_OPTREDUCTIONPASS
@@ -45,16 +46,26 @@ void OptReductionPass::runOnOperation() {
   LDBG() << "\nOptimization Reduction pass: ";
 
   Tester test(testerName, testerArgs);
-
   ModuleOp module = this->getOperation();
-  ModuleOp moduleVariant = module.clone();
-
+  std::string pipelineStr = optPass;
+  if (pipelineStr.empty()) {
+    if (!optPassFile.empty()) {
+      auto fileOrErr = llvm::MemoryBuffer::getFile(optPassFile);
+      if (std::error_code ec = fileOrErr.getError()) {
+        module.emitError() << "Could not open pass pipeline file: "
+                           << optPassFile << " (" << ec.message() << ")";
+        return signalPassFailure();
+      }
+      pipelineStr = fileOrErr.get()->getBuffer().trim().str();
+    }
+  }
   OpPassManager passManager("builtin.module");
-  if (failed(parsePassPipeline(optPass, passManager))) {
+  if (failed(parsePassPipeline(pipelineStr, passManager))) {
     module.emitError() << "\nfailed to parse pass pipeline";
     return signalPassFailure();
   }
 
+  ModuleOp moduleVariant = module.clone();
   std::pair<Tester::Interestingness, int> original = test.isInteresting(module);
   if (original.first != Tester::Interestingness::True) {
     module.emitError() << "\nthe original input is not interested";
diff --git a/mlir/test/mlir-reduce/dce-pipeline b/mlir/test/mlir-reduce/dce-pipeline
new file mode 100644
index 0000000000000..92fc1ea2acc03
--- /dev/null
+++ b/mlir/test/mlir-reduce/dce-pipeline
@@ -0,0 +1 @@
+symbol-dce
diff --git a/mlir/test/mlir-reduce/dce-test.mlir b/mlir/test/mlir-reduce/dce-test.mlir
index 57b5fd9c2ea73..e81cad3ef9f21 100644
--- a/mlir/test/mlir-reduce/dce-test.mlir
+++ b/mlir/test/mlir-reduce/dce-test.mlir
@@ -1,16 +1,20 @@
 // UNSUPPORTED: system-windows
 // RUN: mlir-reduce %s -opt-reduction-pass='opt-pass=symbol-dce test=%S/failure-test.sh' | FileCheck %s
+// RUN: mlir-reduce %s -opt-reduction-pass='opt-pass-file=%S/dce-pipeline test=%S/failure-test.sh' | FileCheck %s  --check-prefix=CHECK-OPT-FILE
 // This input should be reduced by the pass pipeline so that only
 // the @simple1 function remains as the other functions should be
 // removed by the dead code elimination pass.
 
 // CHECK-NOT: func private @dead_private_function
+// CHECK-OPT-FILE-NOT: func private @dead_private_function
 func.func private @dead_private_function()
 
 // CHECK-NOT: func nested @dead_nested_function
+// CHECK-OPT-FILE-NOT: funcnested @dead_nested_function
 func.func nested @dead_nested_function()
 
 // CHECK-LABEL: func @simple1(%arg0: i1, %arg1: memref<2xf32>, %arg2: memref<2xf32>) {
+// CHECK-OPT-FILE-LABEL: func @simple1(%arg0: i1, %arg1: memref<2xf32>, %arg2: memref<2xf32>) {
 func.func @simple1(%arg0: i1, %arg1: memref<2xf32>, %arg2: memref<2xf32>) {
   "test.op_crash" () : () -> ()
   return

``````````

</details>


https://github.com/llvm/llvm-project/pull/189353


More information about the Mlir-commits mailing list