Skip to content

[mlir][transforms] Add signalPassFailure in RemoveDeadValues #112199

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 18, 2024

Conversation

CoTinker
Copy link
Contributor

This PR adds signalPassFailure in RemoveDeadValues to ensure that a pipeline would stop here.
Fixes #111757.

This PR adds `signalPassFailure` in RemoveDeadValues to ensure that a
pipeline would stop here.
@CoTinker CoTinker requested a review from srishti-pm October 14, 2024 13:40
@llvmbot llvmbot added mlir:core MLIR Core Infrastructure mlir labels Oct 14, 2024
@CoTinker CoTinker requested a review from joker-eph October 14, 2024 13:40
@llvmbot
Copy link
Member

llvmbot commented Oct 14, 2024

@llvm/pr-subscribers-mlir

Author: Longsheng Mou (CoTinker)

Changes

This PR adds signalPassFailure in RemoveDeadValues to ensure that a pipeline would stop here.
Fixes #111757.


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

1 Files Affected:

  • (modified) mlir/lib/Transforms/RemoveDeadValues.cpp (+1-1)
diff --git a/mlir/lib/Transforms/RemoveDeadValues.cpp b/mlir/lib/Transforms/RemoveDeadValues.cpp
index 3de4fb75ed831c..7e45f18b660ba7 100644
--- a/mlir/lib/Transforms/RemoveDeadValues.cpp
+++ b/mlir/lib/Transforms/RemoveDeadValues.cpp
@@ -589,7 +589,7 @@ void RemoveDeadValues::runOnOperation() {
   });
 
   if (acceptableIR.wasInterrupted())
-    return;
+    return signalPassFailure();
 
   module->walk([&](Operation *op) {
     if (auto funcOp = dyn_cast<FunctionOpInterface>(op)) {

@llvmbot
Copy link
Member

llvmbot commented Oct 14, 2024

@llvm/pr-subscribers-mlir-core

Author: Longsheng Mou (CoTinker)

Changes

This PR adds signalPassFailure in RemoveDeadValues to ensure that a pipeline would stop here.
Fixes #111757.


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

1 Files Affected:

  • (modified) mlir/lib/Transforms/RemoveDeadValues.cpp (+1-1)
diff --git a/mlir/lib/Transforms/RemoveDeadValues.cpp b/mlir/lib/Transforms/RemoveDeadValues.cpp
index 3de4fb75ed831c..7e45f18b660ba7 100644
--- a/mlir/lib/Transforms/RemoveDeadValues.cpp
+++ b/mlir/lib/Transforms/RemoveDeadValues.cpp
@@ -589,7 +589,7 @@ void RemoveDeadValues::runOnOperation() {
   });
 
   if (acceptableIR.wasInterrupted())
-    return;
+    return signalPassFailure();
 
   module->walk([&](Operation *op) {
     if (auto funcOp = dyn_cast<FunctionOpInterface>(op)) {

Copy link
Contributor

@MaheshRavishankar MaheshRavishankar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a test here please?

@CoTinker
Copy link
Contributor Author

Could you add a test here please?

I don't know how to add test for signalPassFailure, could you please give me some advice.

Copy link
Contributor

@MaheshRavishankar MaheshRavishankar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can add a test with // expected-error and use --verify-diagnostics (I think).

@joker-eph
Copy link
Collaborator

LG with a test

@joker-eph
Copy link
Collaborator

Mmmmm there is already a test for the diagnostic, somehow the test does not check the return of mlir-opt though!

@CoTinker
Copy link
Contributor Author

Sorry, I'm still having trouble understanding how to check for signalPassFailure in mlir-opt. I know expected-error and verify-diagnostics can check for emitError, but I'm not sure how to handle signalPassFailure.

@MaheshRavishankar
Copy link
Contributor

Sorry, I'm still having trouble understanding how to check for signalPassFailure in mlir-opt. I know expected-error and verify-diagnostics can check for emitError, but I'm not sure how to handle signalPassFailure.

Emit an error message before the return signalPassFailure and check for the error message?

@CoTinker
Copy link
Contributor Author

Sorry, I'm still having trouble understanding how to check for signalPassFailure in mlir-opt. I know expected-error and verify-diagnostics can check for emitError, but I'm not sure how to handle signalPassFailure.

Emit an error message before the return signalPassFailure and check for the error message?

// The IR remains untouched because of the presence of a non-function-like
// symbol op inside the module (const @__dont_touch_unacceptable_ir).
//
module {
// expected-error @+1 {{cannot optimize an IR with non-function symbol ops, non-call symbol user ops or branch ops}}
memref.global "private" constant @__dont_touch_unacceptable_ir : memref<i32> = dense<0>
func.func @main(%arg0: i32) -> i32 {
return %arg0 : i32
}
}

It has already been checked.

@CoTinker
Copy link
Contributor Author

Error message is here.

WalkResult acceptableIR = module->walk([&](Operation *op) {
if (op == module)
return WalkResult::advance();
if (isa<BranchOpInterface>(op) ||
(isa<SymbolOpInterface>(op) && !isa<FunctionOpInterface>(op)) ||
(isa<SymbolUserOpInterface>(op) && !isa<CallOpInterface>(op))) {
op->emitError() << "cannot optimize an IR with non-function symbol ops, "
"non-call symbol user ops or branch ops\n";
return WalkResult::interrupt();
}
return WalkResult::advance();
});
if (acceptableIR.wasInterrupted())
return;

@CoTinker
Copy link
Contributor Author

Thanks for your review.

@CoTinker CoTinker merged commit 70865c4 into llvm:main Oct 18, 2024
11 checks passed
@CoTinker CoTinker deleted the eliminate branch October 18, 2024 01:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mlir:core MLIR Core Infrastructure mlir
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[mlir] remove-dead-values zero exit code on failure
4 participants