Skip to content

Commit 77c9b37

Browse files
[mlir] Fix FunctionOpInterface impl for external func
1 parent fc4210f commit 77c9b37

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

mlir/lib/Interfaces/FunctionInterfaces.cpp

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,7 @@ void function_interface_impl::insertFunctionArguments(
199199
// There are 3 things that need to be updated:
200200
// - Function type.
201201
// - Arg attrs.
202-
// - Block arguments of entry block.
203-
Block &entry = op->getRegion(0).front();
202+
// - Block arguments of entry block, if not empty.
204203

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

229-
// Update the function type and any entry block arguments.
228+
// Update the function type.
230229
op.setFunctionTypeAttr(TypeAttr::get(newType));
231-
for (unsigned i = 0, e = argIndices.size(); i < e; ++i)
232-
entry.insertArgument(argIndices[i] + i, argTypes[i], argLocs[i]);
230+
231+
// Update entry block arguments, if not empty.
232+
if (!op.isExternal()) {
233+
Block &entry = op->getRegion(0).front();
234+
for (unsigned i = 0, e = argIndices.size(); i < e; ++i)
235+
entry.insertArgument(argIndices[i] + i, argTypes[i], argLocs[i]);
236+
}
233237
}
234238

235239
void function_interface_impl::insertFunctionResults(
@@ -279,8 +283,7 @@ void function_interface_impl::eraseFunctionArguments(
279283
// There are 3 things that need to be updated:
280284
// - Function type.
281285
// - Arg attrs.
282-
// - Block arguments of entry block.
283-
Block &entry = op->getRegion(0).front();
286+
// - Block arguments of entry block, if not empty.
284287

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

295-
// Update the function type and any entry block arguments.
298+
// Update the function type.
296299
op.setFunctionTypeAttr(TypeAttr::get(newType));
297-
entry.eraseArguments(argIndices);
300+
301+
// Update entry block arguments, if not empty.
302+
if (!op.isExternal()) {
303+
Block &entry = op->getRegion(0).front();
304+
entry.eraseArguments(argIndices);
305+
}
298306
}
299307

300308
void function_interface_impl::eraseFunctionResults(

0 commit comments

Comments
 (0)