-
Notifications
You must be signed in to change notification settings - Fork 13.3k
[mlir] Fix FunctionOpInterface impl for external func #124693
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
[mlir] Fix FunctionOpInterface impl for external func #124693
Conversation
@llvm/pr-subscribers-mlir Author: Hongren Zheng (ZenithalHourlyRate) ChangesFor function declarations (i.e. func op has no entry block), the FunctionOpInterface method An example can be seen in google/heir#1324 The segfault trace
Full diff: https://github.com/llvm/llvm-project/pull/124693.diff 1 Files Affected:
diff --git a/mlir/lib/Interfaces/FunctionInterfaces.cpp b/mlir/lib/Interfaces/FunctionInterfaces.cpp
index 80f47a3f836768..1d565eac2aeb88 100644
--- a/mlir/lib/Interfaces/FunctionInterfaces.cpp
+++ b/mlir/lib/Interfaces/FunctionInterfaces.cpp
@@ -199,7 +199,7 @@ void function_interface_impl::insertFunctionArguments(
// There are 3 things that need to be updated:
// - Function type.
// - Arg attrs.
- // - Block arguments of entry block.
+ // - Block arguments of entry block, if not empty.
Block &entry = op->getRegion(0).front();
// Update the argument attributes of the function.
@@ -228,8 +228,11 @@ void function_interface_impl::insertFunctionArguments(
// Update the function type and any entry block arguments.
op.setFunctionTypeAttr(TypeAttr::get(newType));
- for (unsigned i = 0, e = argIndices.size(); i < e; ++i)
- entry.insertArgument(argIndices[i] + i, argTypes[i], argLocs[i]);
+
+ // Update the block arguments of the entry block when it is not external.
+ if (!op.isExternal())
+ for (unsigned i = 0, e = argIndices.size(); i < e; ++i)
+ entry.insertArgument(argIndices[i] + i, argTypes[i], argLocs[i]);
}
void function_interface_impl::insertFunctionResults(
@@ -279,7 +282,7 @@ void function_interface_impl::eraseFunctionArguments(
// There are 3 things that need to be updated:
// - Function type.
// - Arg attrs.
- // - Block arguments of entry block.
+ // - Block arguments of entry block, if not empty.
Block &entry = op->getRegion(0).front();
// Update the argument attributes of the function.
@@ -294,7 +297,10 @@ void function_interface_impl::eraseFunctionArguments(
// Update the function type and any entry block arguments.
op.setFunctionTypeAttr(TypeAttr::get(newType));
- entry.eraseArguments(argIndices);
+
+ // Update the block arguments of the entry block when it is not external.
+ if (!op.isExternal())
+ entry.eraseArguments(argIndices);
}
void function_interface_impl::eraseFunctionResults(
|
Cc @fabianschuiki, @River707 for review |
Ping for review |
2fa0334
to
77c9b37
Compare
Comments addressed and tested insertArgument for op declaration in downstream project. |
Ping for review |
1 similar comment
Ping for review |
For function declarations (i.e. func op has no entry block), the FunctionOpInterface method
insertArgument
anderaseArgument
will cause segfault. This PR guards against manipulation of empty entry block by checking whether func op is external.An example can be seen in google/heir#1324
The segfault trace