Skip to content
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

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 17 additions & 9 deletions mlir/lib/Interfaces/FunctionInterfaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +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 &entry = op->getRegion(0).front();
// - Block arguments of entry block, if not empty.

// Update the argument attributes of the function.
ArrayAttr oldArgAttrs = op.getArgAttrsAttr();
Expand All @@ -226,10 +225,15 @@ void function_interface_impl::insertFunctionArguments(
setAllArgAttrDicts(op, newArgAttrs);
}

// Update the function type and any entry block arguments.
// Update the function type.
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 entry block arguments, if not empty.
if (!op.isExternal()) {
Block &entry = op->getRegion(0).front();
for (unsigned i = 0, e = argIndices.size(); i < e; ++i)
entry.insertArgument(argIndices[i] + i, argTypes[i], argLocs[i]);
}
}

void function_interface_impl::insertFunctionResults(
Expand Down Expand Up @@ -279,8 +283,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 &entry = op->getRegion(0).front();
// - Block arguments of entry block, if not empty.

// Update the argument attributes of the function.
if (ArrayAttr argAttrs = op.getArgAttrsAttr()) {
Expand All @@ -292,9 +295,14 @@ void function_interface_impl::eraseFunctionArguments(
setAllArgAttrDicts(op, newArgAttrs);
}

// Update the function type and any entry block arguments.
// Update the function type.
op.setFunctionTypeAttr(TypeAttr::get(newType));
entry.eraseArguments(argIndices);

// Update entry block arguments, if not empty.
if (!op.isExternal()) {
Block &entry = op->getRegion(0).front();
entry.eraseArguments(argIndices);
}
}

void function_interface_impl::eraseFunctionResults(
Expand Down