[Mlir-commits] [mlir] 346bd91 - [mlir][EmitC] Fix call ops with zero arguments in func to emitc conversion (#94936)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Mon Jun 10 04:40:27 PDT 2024


Author: Simon Camphausen
Date: 2024-06-10T13:40:24+02:00
New Revision: 346bd917929fa89dfe00d999effcde7ee3d8d4a7

URL: https://github.com/llvm/llvm-project/commit/346bd917929fa89dfe00d999effcde7ee3d8d4a7
DIFF: https://github.com/llvm/llvm-project/commit/346bd917929fa89dfe00d999effcde7ee3d8d4a7.diff

LOG: [mlir][EmitC] Fix call ops with zero arguments in func to emitc conversion (#94936)

Added: 
    

Modified: 
    mlir/lib/Conversion/FuncToEmitC/FuncToEmitC.cpp
    mlir/test/Conversion/FuncToEmitC/func-to-emitc.mlir

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Conversion/FuncToEmitC/FuncToEmitC.cpp b/mlir/lib/Conversion/FuncToEmitC/FuncToEmitC.cpp
index 6a8ecb7b00473..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() : nullptr,
-        adaptor.getOperands(), callOp->getAttrs());
+    rewriter.replaceOpWithNewOp<emitc::CallOp>(callOp, callOp.getResultTypes(),
+                                               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
+}


        


More information about the Mlir-commits mailing list