[Mlir-commits] [mlir] [RFC][mlir][func] Enforce func.return as sole terminator in func.func regions (PR #184778)
Jakub Kuderski
llvmlistbot at llvm.org
Thu Mar 5 07:17:27 PST 2026
================
@@ -42,6 +42,24 @@ class ReturnOpPattern final : public OpConversionPattern<func::ReturnOp> {
if (returnOp.getNumOperands() > 1)
return failure();
+ // Only convert func.return when the enclosing func.func is being converted
+ // to spirv.func. Check that all argument and result types of the parent
+ // function are convertible; if not, leave this op unconverted so the
+ // func.func stays in the Func dialect with a valid func.return terminator.
+ if (auto funcOp = returnOp->getParentOfType<func::FuncOp>()) {
+ FunctionType fnType = funcOp.getFunctionType();
+ if (fnType.getNumResults() > 1)
+ return failure();
----------------
kuhar wrote:
I think it would be cleared to bail out one more than 2 args here but do a for loop below, so that it's clear we are handling zero or more return values.
RE signature conversion, I'm also unsure if this is required here -- is it because spirv.func won't convert if the type converter fails alter on, and you always want the return op to be in sync with the function op?
https://github.com/llvm/llvm-project/pull/184778
More information about the Mlir-commits
mailing list