[mlir][reducer] make opt-reduction pass clone topOp after check (NFC)#189356
Conversation
|
@llvm/pr-subscribers-mlir Author: lonely eagle (linuxlonelyeagle) ChangesTo 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:
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);
|
|
@llvm/pr-subscribers-mlir-core Author: lonely eagle (linuxlonelyeagle) ChangesTo 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:
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);
|
2c026a0 to
41bf2a9
Compare
|
hmm, good catch, something related to this, our internal MLIR projects did an ASAN build for all of our testcases and found bunch of these kinds of memory leak. Func cloning and module cloning leaks are the most common. If you have time probably can try doing an ASAN debug and do some regression test. |
|
lgtm |
41bf2a9 to
8475c05
Compare
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/157/builds/45695 Here is the relevant piece of the build log for the reference |
…llvm#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 llvm#189353.
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 #189353.