Skip to content

Commit

Permalink
Merge pull request #213 from Xilinx/matthias.emitc_func
Browse files Browse the repository at this point in the history
[mlir][EmitC] Fix call ops with zero arguments in func to emitc conversion (llvm#94936)
  • Loading branch information
mgehre-amd authored Jul 10, 2024
2 parents 54e2843 + cfb7599 commit f713706
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
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
}

0 comments on commit f713706

Please sign in to comment.