[mlir][reducer] make opt-reduction pass clone topOp after check (NFC) (#189356)

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. It
is part of https://github.com/llvm/llvm-project/pull/189353.
This commit is contained in:
lonely eagle 2026-04-04 22:08:34 +08:00 committed by GitHub
parent fb3fada084
commit 230d757a13
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -45,9 +45,7 @@ void OptReductionPass::runOnOperation() {
LDBG() << "\nOptimization Reduction pass: ";
Tester test(testerName, testerArgs);
Operation *topOp = this->getOperation();
Operation *topOpVariant = topOp->clone();
PassManager passManager(topOp->getName());
if (failed(parsePassPipeline(optPass, passManager))) {
@ -60,6 +58,7 @@ void OptReductionPass::runOnOperation() {
topOp->emitError() << "\nthe original input is not interested";
return signalPassFailure();
}
Operation *topOpVariant = topOp->clone();
LogicalResult pipelineResult = passManager.run(topOpVariant);
if (failed(pipelineResult)) {