Skip to content

Commit

Permalink
[mlir][EmitC] Fix call ops with zero arguments in func to emitc conve…
Browse files Browse the repository at this point in the history
…rsion (#94936)
  • Loading branch information
simon-camp authored Jun 10, 2024
1 parent bddd8ea commit 346bd91
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
9 changes: 4 additions & 5 deletions mlir/lib/Conversion/FuncToEmitC/FuncToEmitC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,14 @@ 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");

rewriter.replaceOpWithNewOp<emitc::CallOp>(
callOp,
callOp.getNumResults() ? callOp.getResult(0).getType() : nullptr,
adaptor.getOperands(), callOp->getAttrs());
rewriter.replaceOpWithNewOp<emitc::CallOp>(callOp, callOp.getResultTypes(),
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 @@ -58,3 +58,19 @@ func.func @call(%arg0: i32) -> i32 {

// CHECK-LABEL: emitc.func private @return_i32(i32) -> i32 attributes {specifiers = ["extern"]}
func.func private @return_i32(%arg0: i32) -> i32

// -----

// 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
}

0 comments on commit 346bd91

Please sign in to comment.