[Mlir-commits] [mlir] [mlir][reducer] make opt-reduction pass clone topOp after check (NFC) (PR #189356)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Mon Mar 30 04:05:25 PDT 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir-core
Author: lonely eagle (linuxlonelyeagle)
<details>
<summary>Changes</summary>
To avoid potential memory leaks, this PR defers the ModuleOp cloning until after the verification check. If the check fails, the moduleVariant might not be properly deallocated(original implementation), leading to a memory leak. Therefore, this PR ensures that the clone operation is only performed after a successful check
---
Full diff: https://github.com/llvm/llvm-project/pull/189356.diff
1 Files Affected:
- (modified) mlir/lib/Reducer/OptReductionPass.cpp (+1-3)
``````````diff
diff --git a/mlir/lib/Reducer/OptReductionPass.cpp b/mlir/lib/Reducer/OptReductionPass.cpp
index 4bdc7b17567d9..feb28e1b9beb8 100644
--- a/mlir/lib/Reducer/OptReductionPass.cpp
+++ b/mlir/lib/Reducer/OptReductionPass.cpp
@@ -47,8 +47,6 @@ void OptReductionPass::runOnOperation() {
Tester test(testerName, testerArgs);
ModuleOp module = this->getOperation();
- ModuleOp moduleVariant = module.clone();
-
OpPassManager passManager("builtin.module");
if (failed(parsePassPipeline(optPass, passManager))) {
module.emitError() << "\nfailed to parse pass pipeline";
@@ -60,7 +58,7 @@ void OptReductionPass::runOnOperation() {
module.emitError() << "\nthe original input is not interested";
return signalPassFailure();
}
-
+ ModuleOp moduleVariant = module.clone();
// Temporarily push the variant under the main module and execute the pipeline
// on it.
module.getBody()->push_back(moduleVariant);
``````````
</details>
https://github.com/llvm/llvm-project/pull/189356
More information about the Mlir-commits
mailing list