[Mlir-commits] [mlir] [mlir][reducer] Add opt-pass-file option to opt-reduction pass (PR #189353)
lonely eagle
llvmlistbot at llvm.org
Sat Apr 4 07:52:06 PDT 2026
https://github.com/linuxlonelyeagle updated https://github.com/llvm/llvm-project/pull/189353
>From ab036e6c206ee3b6c4d813f6bfec74366b1ca9da Mon Sep 17 00:00:00 2001
From: linuxlonelyeagle <2020382038 at qq.com>
Date: Sat, 4 Apr 2026 14:51:42 +0000
Subject: [PATCH] rebase main.
---
mlir/include/mlir/Reducer/Passes.td | 2 ++
mlir/lib/Reducer/OptReductionPass.cpp | 16 +++++++++++++++-
mlir/test/mlir-reduce/opt-reduction/dce-pipeline | 1 +
.../test/mlir-reduce/opt-reduction/dce-test.mlir | 4 ++++
4 files changed, 22 insertions(+), 1 deletion(-)
create mode 100644 mlir/test/mlir-reduce/opt-reduction/dce-pipeline
diff --git a/mlir/include/mlir/Reducer/Passes.td b/mlir/include/mlir/Reducer/Passes.td
index d63cac535ad8f..cce5c7570d4d9 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"> {
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 62d05c37bfab1..69e1a105ef9a5 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
@@ -47,8 +48,21 @@ void OptReductionPass::runOnOperation() {
Tester test(testerName, testerArgs);
Operation *topOp = this->getOperation();
+ std::string pipelineStr = optPass;
+ if (pipelineStr.empty()) {
+ if (!optPassFile.empty()) {
+ auto fileOrErr = llvm::MemoryBuffer::getFile(optPassFile);
+ if (std::error_code ec = fileOrErr.getError()) {
+ topOp->emitError() << "Could not open pass pipeline file: "
+ << optPassFile << " (" << ec.message() << ")";
+ return signalPassFailure();
+ }
+ pipelineStr = fileOrErr.get()->getBuffer().trim().str();
+ }
+ }
+
PassManager passManager(topOp->getName());
- if (failed(parsePassPipeline(optPass, passManager))) {
+ if (failed(parsePassPipeline(pipelineStr, passManager))) {
topOp->emitError() << "\nfailed to parse pass pipeline";
return signalPassFailure();
}
diff --git a/mlir/test/mlir-reduce/opt-reduction/dce-pipeline b/mlir/test/mlir-reduce/opt-reduction/dce-pipeline
new file mode 100644
index 0000000000000..92fc1ea2acc03
--- /dev/null
+++ b/mlir/test/mlir-reduce/opt-reduction/dce-pipeline
@@ -0,0 +1 @@
+symbol-dce
diff --git a/mlir/test/mlir-reduce/opt-reduction/dce-test.mlir b/mlir/test/mlir-reduce/opt-reduction/dce-test.mlir
index f9b016108caa5..c9f81fe8b1f20 100644
--- a/mlir/test/mlir-reduce/opt-reduction/dce-test.mlir
+++ b/mlir/test/mlir-reduce/opt-reduction/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
More information about the Mlir-commits
mailing list