-
Notifications
You must be signed in to change notification settings - Fork 14.4k
[mlir][func] Fix ReturnOp issue #112146 #112385
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
base: main
Are you sure you want to change the base?
Conversation
This patches fixes issue 112146, where an assertion was being triggered by `func::ReturnOp::getSuccessorRegions` and `func::FuncOp` not implementing `RegionBranchOpInterface`.
@llvm/pr-subscribers-mlir Author: Fabian Mora (fabianmcg) ChangesThis patches fixes issue #112146, where an assertion was being triggered by Full diff: https://github.com/llvm/llvm-project/pull/112385.diff 2 Files Affected:
diff --git a/mlir/include/mlir/Dialect/Func/IR/FuncOps.td b/mlir/include/mlir/Dialect/Func/IR/FuncOps.td
index 22efe15aa83a50..8f20ca64602e4c 100644
--- a/mlir/include/mlir/Dialect/Func/IR/FuncOps.td
+++ b/mlir/include/mlir/Dialect/Func/IR/FuncOps.td
@@ -338,8 +338,10 @@ def FuncOp : Func_Op<"func", [
// ReturnOp
//===----------------------------------------------------------------------===//
-def ReturnOp : Func_Op<"return", [Pure, HasParent<"FuncOp">,
- MemRefsNormalizable, ReturnLike, Terminator]> {
+def ReturnOp : Func_Op<"return", [
+ Pure, HasParent<"FuncOp">, MemRefsNormalizable, ReturnLike, Terminator,
+ DeclareOpInterfaceMethods<RegionBranchTerminatorOpInterface, ["getSuccessorRegions"]>]
+ > {
let summary = "Function return operation";
let description = [{
The `func.return` operation represents a return operation within a function.
diff --git a/mlir/lib/Dialect/Func/IR/FuncOps.cpp b/mlir/lib/Dialect/Func/IR/FuncOps.cpp
index a490b4c3c4ab43..06e0172a0fab6a 100644
--- a/mlir/lib/Dialect/Func/IR/FuncOps.cpp
+++ b/mlir/lib/Dialect/Func/IR/FuncOps.cpp
@@ -306,6 +306,12 @@ LogicalResult ReturnOp::verify() {
return success();
}
+void ReturnOp::getSuccessorRegions(ArrayRef<Attribute> operands,
+ SmallVectorImpl<RegionSuccessor> ®ions) {
+ // Return control back to func::FuncOp.
+ regions.push_back(RegionSuccessor());
+}
+
//===----------------------------------------------------------------------===//
// TableGen'd op method definitions
//===----------------------------------------------------------------------===//
|
@llvm/pr-subscribers-mlir-func Author: Fabian Mora (fabianmcg) ChangesThis patches fixes issue #112146, where an assertion was being triggered by Full diff: https://github.com/llvm/llvm-project/pull/112385.diff 2 Files Affected:
diff --git a/mlir/include/mlir/Dialect/Func/IR/FuncOps.td b/mlir/include/mlir/Dialect/Func/IR/FuncOps.td
index 22efe15aa83a50..8f20ca64602e4c 100644
--- a/mlir/include/mlir/Dialect/Func/IR/FuncOps.td
+++ b/mlir/include/mlir/Dialect/Func/IR/FuncOps.td
@@ -338,8 +338,10 @@ def FuncOp : Func_Op<"func", [
// ReturnOp
//===----------------------------------------------------------------------===//
-def ReturnOp : Func_Op<"return", [Pure, HasParent<"FuncOp">,
- MemRefsNormalizable, ReturnLike, Terminator]> {
+def ReturnOp : Func_Op<"return", [
+ Pure, HasParent<"FuncOp">, MemRefsNormalizable, ReturnLike, Terminator,
+ DeclareOpInterfaceMethods<RegionBranchTerminatorOpInterface, ["getSuccessorRegions"]>]
+ > {
let summary = "Function return operation";
let description = [{
The `func.return` operation represents a return operation within a function.
diff --git a/mlir/lib/Dialect/Func/IR/FuncOps.cpp b/mlir/lib/Dialect/Func/IR/FuncOps.cpp
index a490b4c3c4ab43..06e0172a0fab6a 100644
--- a/mlir/lib/Dialect/Func/IR/FuncOps.cpp
+++ b/mlir/lib/Dialect/Func/IR/FuncOps.cpp
@@ -306,6 +306,12 @@ LogicalResult ReturnOp::verify() {
return success();
}
+void ReturnOp::getSuccessorRegions(ArrayRef<Attribute> operands,
+ SmallVectorImpl<RegionSuccessor> ®ions) {
+ // Return control back to func::FuncOp.
+ regions.push_back(RegionSuccessor());
+}
+
//===----------------------------------------------------------------------===//
// TableGen'd op method definitions
//===----------------------------------------------------------------------===//
|
Can this be triggered in a test? |
On a LIT test, no, only by creating an unit test. There are very few places upstream using this interface, dataflow being one of them. I stumbled upon this assert when I was testing the interface for building the CFG, and I didn't check if the parent was valid. |
I'm just concerned about code coverage upstream: in general we aim to have all this kind of behavior tested. |
Yes there are tests: https://github.com/llvm/llvm-project/blob/main/mlir/unittests/Interfaces/ControlFlowInterfacesTest.cpp for the interface. This issue is specific to the implementation of |
This patches fixes issue #112146, where an assertion was being triggered by
func::ReturnOp::getSuccessorRegions
andfunc::FuncOp
not implementingRegionBranchOpInterface
.