Skip to content

[mlir][EmitC] Fix call ops with zero arguments in func to emitc conversion (llvm#94936) #213

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

Merged
merged 2 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
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
15 changes: 6 additions & 9 deletions mlir/lib/Conversion/FuncToEmitC/FuncToEmitC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,19 @@ class CallOpConversion final : public OpConversionPattern<func::CallOp> {
LogicalResult
matchAndRewrite(func::CallOp callOp, OpAdaptor adaptor,
ConversionPatternRewriter &rewriter) const override {
// Multiple results func was not converted to `emitc.func`.
// Multiple results func cannot be converted to `emitc.func`.
if (callOp.getNumResults() > 1)
return rewriter.notifyMatchFailure(
callOp, "only functions with zero or one result can be converted");

// Convert the original function results.
Type resultTy = nullptr;
if (callOp.getNumResults()) {
resultTy = typeConverter->convertType(callOp.getResult(0).getType());
if (!resultTy)
return rewriter.notifyMatchFailure(
callOp, "function return type conversion failed");
SmallVector<Type> types;
if (failed(typeConverter->convertTypes(callOp.getResultTypes(), types))) {
return rewriter.notifyMatchFailure(
callOp, "function return type conversion failed");
}

rewriter.replaceOpWithNewOp<emitc::CallOp>(
callOp, resultTy, adaptor.getOperands(), callOp->getAttrs());
callOp, types, adaptor.getOperands(), callOp->getAttrs());

return success();
}
Expand Down
16 changes: 16 additions & 0 deletions mlir/test/Conversion/FuncToEmitC/func-to-emitc.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,19 @@ func.func @index_args_only(%i: index) -> f32 {
%0 = arith.constant 0.0 : f32
return %0 : f32
}

// -----

// CHECK-LABEL: emitc.func private @return_void() attributes {specifiers = ["static"]}
// CHECK-NEXT: emitc.return
func.func private @return_void() {
return
}

// CHECK-LABEL: emitc.func @call()
// CHECK-NEXT: emitc.call @return_void() : () -> ()
// CHECK-NEXT: emitc.return
func.func @call() {
call @return_void() : () -> ()
return
}