Skip to content

Commit f713706

Browse files
authored
Merge pull request #213 from Xilinx/matthias.emitc_func
[mlir][EmitC] Fix call ops with zero arguments in func to emitc conversion (llvm#94936)
2 parents 54e2843 + cfb7599 commit f713706

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

mlir/lib/Conversion/FuncToEmitC/FuncToEmitC.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,19 @@ 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

3939
// Convert the original function results.
40-
Type resultTy = nullptr;
41-
if (callOp.getNumResults()) {
42-
resultTy = typeConverter->convertType(callOp.getResult(0).getType());
43-
if (!resultTy)
44-
return rewriter.notifyMatchFailure(
45-
callOp, "function return type conversion failed");
40+
SmallVector<Type> types;
41+
if (failed(typeConverter->convertTypes(callOp.getResultTypes(), types))) {
42+
return rewriter.notifyMatchFailure(
43+
callOp, "function return type conversion failed");
4644
}
47-
4845
rewriter.replaceOpWithNewOp<emitc::CallOp>(
49-
callOp, resultTy, adaptor.getOperands(), callOp->getAttrs());
46+
callOp, types, adaptor.getOperands(), callOp->getAttrs());
5047

5148
return success();
5249
}

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,19 @@ func.func @index_args_only(%i: index) -> f32 {
8888
%0 = arith.constant 0.0 : f32
8989
return %0 : f32
9090
}
91+
92+
// -----
93+
94+
// CHECK-LABEL: emitc.func private @return_void() attributes {specifiers = ["static"]}
95+
// CHECK-NEXT: emitc.return
96+
func.func private @return_void() {
97+
return
98+
}
99+
100+
// CHECK-LABEL: emitc.func @call()
101+
// CHECK-NEXT: emitc.call @return_void() : () -> ()
102+
// CHECK-NEXT: emitc.return
103+
func.func @call() {
104+
call @return_void() : () -> ()
105+
return
106+
}

0 commit comments

Comments
 (0)