[Mlir-commits] [mlir] [mlir][EmitC] Fix call ops with zero arguments in func to emitc conversion (PR #94936)
Simon Camphausen
llvmlistbot at llvm.org
Mon Jun 10 02:29:31 PDT 2024
https://github.com/simon-camp updated https://github.com/llvm/llvm-project/pull/94936
>From 14dacb0dc8eaf8cdefef198ba3ea03bc73126fde Mon Sep 17 00:00:00 2001
From: Simon Camphausen <simon.camphausen at iml.fraunhofer.de>
Date: Mon, 10 Jun 2024 07:48:44 +0000
Subject: [PATCH 1/2] [mlir][EmitC] func-to-emitc: Fix conversion for call ops
with zero arguments
---
mlir/lib/Conversion/FuncToEmitC/FuncToEmitC.cpp | 2 +-
.../Conversion/FuncToEmitC/func-to-emitc.mlir | 16 ++++++++++++++++
2 files changed, 17 insertions(+), 1 deletion(-)
diff --git a/mlir/lib/Conversion/FuncToEmitC/FuncToEmitC.cpp b/mlir/lib/Conversion/FuncToEmitC/FuncToEmitC.cpp
index 6a8ecb7b00473..f0bb2093af277 100644
--- a/mlir/lib/Conversion/FuncToEmitC/FuncToEmitC.cpp
+++ b/mlir/lib/Conversion/FuncToEmitC/FuncToEmitC.cpp
@@ -38,7 +38,7 @@ class CallOpConversion final : public OpConversionPattern<func::CallOp> {
rewriter.replaceOpWithNewOp<emitc::CallOp>(
callOp,
- callOp.getNumResults() ? callOp.getResult(0).getType() : nullptr,
+ callOp.getNumResults() ? callOp.getResult(0).getType() : TypeRange{},
adaptor.getOperands(), callOp->getAttrs());
return success();
diff --git a/mlir/test/Conversion/FuncToEmitC/func-to-emitc.mlir b/mlir/test/Conversion/FuncToEmitC/func-to-emitc.mlir
index 5c96cf1ce0d34..5730f7a4814fa 100644
--- a/mlir/test/Conversion/FuncToEmitC/func-to-emitc.mlir
+++ b/mlir/test/Conversion/FuncToEmitC/func-to-emitc.mlir
@@ -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
+}
>From a6a4e5be14433b3bc35f7a60e75c22c80a43c131 Mon Sep 17 00:00:00 2001
From: Simon Camphausen <simon.camphausen at iml.fraunhofer.de>
Date: Mon, 10 Jun 2024 09:29:04 +0000
Subject: [PATCH 2/2] Review comments
---
mlir/lib/Conversion/FuncToEmitC/FuncToEmitC.cpp | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/mlir/lib/Conversion/FuncToEmitC/FuncToEmitC.cpp b/mlir/lib/Conversion/FuncToEmitC/FuncToEmitC.cpp
index f0bb2093af277..53b79839da04c 100644
--- a/mlir/lib/Conversion/FuncToEmitC/FuncToEmitC.cpp
+++ b/mlir/lib/Conversion/FuncToEmitC/FuncToEmitC.cpp
@@ -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() : TypeRange{},
- adaptor.getOperands(), callOp->getAttrs());
+ rewriter.replaceOpWithNewOp<emitc::CallOp>(callOp, callOp.getResultTypes(),
+ adaptor.getOperands(),
+ callOp->getAttrs());
return success();
}
More information about the Mlir-commits
mailing list