Skip to content
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
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
}