Skip to content

Commit 346bd91

Browse files
author
Simon Camphausen
authored
[mlir][EmitC] Fix call ops with zero arguments in func to emitc conversion (#94936)
1 parent bddd8ea commit 346bd91

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

mlir/lib/Conversion/FuncToEmitC/FuncToEmitC.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,14 @@ class CallOpConversion final : public OpConversionPattern<func::CallOp> {
3131
LogicalResult
3232
matchAndRewrite(func::CallOp callOp, OpAdaptor adaptor,
3333
ConversionPatternRewriter &rewriter) const override {
34-
// Multiple results func was not converted to `emitc.func`.
34+
// Multiple results func cannot be converted to `emitc.func`.
3535
if (callOp.getNumResults() > 1)
3636
return rewriter.notifyMatchFailure(
3737
callOp, "only functions with zero or one result can be converted");
3838

39-
rewriter.replaceOpWithNewOp<emitc::CallOp>(
40-
callOp,
41-
callOp.getNumResults() ? callOp.getResult(0).getType() : nullptr,
42-
adaptor.getOperands(), callOp->getAttrs());
39+
rewriter.replaceOpWithNewOp<emitc::CallOp>(callOp, callOp.getResultTypes(),
40+
adaptor.getOperands(),
41+
callOp->getAttrs());
4342

4443
return success();
4544
}

mlir/test/Conversion/FuncToEmitC/func-to-emitc.mlir

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,19 @@ func.func @call(%arg0: i32) -> i32 {
5858

5959
// CHECK-LABEL: emitc.func private @return_i32(i32) -> i32 attributes {specifiers = ["extern"]}
6060
func.func private @return_i32(%arg0: i32) -> i32
61+
62+
// -----
63+
64+
// CHECK-LABEL: emitc.func private @return_void() attributes {specifiers = ["static"]}
65+
// CHECK-NEXT: emitc.return
66+
func.func private @return_void() {
67+
return
68+
}
69+
70+
// CHECK-LABEL: emitc.func @call()
71+
// CHECK-NEXT: emitc.call @return_void() : () -> ()
72+
// CHECK-NEXT: emitc.return
73+
func.func @call() {
74+
call @return_void() : () -> ()
75+
return
76+
}

0 commit comments

Comments
 (0)