[Mlir-commits] [mlir] 7a0dd35 - [mlir][func] Guard for unranked memref with the bare ptr memref call

Kai Sasaki llvmlistbot at llvm.org
Wed Apr 12 19:01:26 PDT 2023


Author: Kai Sasaki
Date: 2023-04-13T10:42:09+09:00
New Revision: 7a0dd35493d4a87b3152e26e1f6449a3f07f1190

URL: https://github.com/llvm/llvm-project/commit/7a0dd35493d4a87b3152e26e1f6449a3f07f1190
DIFF: https://github.com/llvm/llvm-project/commit/7a0dd35493d4a87b3152e26e1f6449a3f07f1190.diff

LOG: [mlir][func] Guard for unranked memref with the bare ptr memref call

Lowering the call op with use-bare-ptr-memref-call crashes due to the unsupported unranked memref type. We can prevent the crash by checking the type of operand in the pass instead of the assertion in the type converter.

Issue: https://github.com/llvm/llvm-project/issues/61872

Reviewed By: ftynse

Differential Revision: https://reviews.llvm.org/D148078

Added: 
    

Modified: 
    mlir/lib/Conversion/FuncToLLVM/FuncToLLVM.cpp
    mlir/test/Conversion/FuncToLLVM/func-memref-return.mlir

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Conversion/FuncToLLVM/FuncToLLVM.cpp b/mlir/lib/Conversion/FuncToLLVM/FuncToLLVM.cpp
index 86394aa969bb3..4fd5b9c43a547 100644
--- a/mlir/lib/Conversion/FuncToLLVM/FuncToLLVM.cpp
+++ b/mlir/lib/Conversion/FuncToLLVM/FuncToLLVM.cpp
@@ -542,6 +542,16 @@ struct CallOpInterfaceLowering : public ConvertOpToLLVMPattern<CallOpType> {
         return failure();
     }
 
+    if (useBarePtrCallConv) {
+      for (auto it : callOp->getOperands()) {
+        Type operandType = it.getType();
+        if (operandType.isa<UnrankedMemRefType>()) {
+          // Unranked memref is not supported in the bare pointer calling
+          // convention.
+          return failure();
+        }
+      }
+    }
     auto promoted = this->getTypeConverter()->promoteOperands(
         callOp.getLoc(), /*opOperands=*/callOp->getOperands(),
         adaptor.getOperands(), rewriter, useBarePtrCallConv);

diff  --git a/mlir/test/Conversion/FuncToLLVM/func-memref-return.mlir b/mlir/test/Conversion/FuncToLLVM/func-memref-return.mlir
index 956c298123db2..c1f41d270e7ea 100644
--- a/mlir/test/Conversion/FuncToLLVM/func-memref-return.mlir
+++ b/mlir/test/Conversion/FuncToLLVM/func-memref-return.mlir
@@ -103,3 +103,14 @@ func.func @check_return(%in : memref<?xi8>) -> memref<?xi8> {
 func.func @unconvertible_multiresult(%arg0: memref<?xf32> , %arg1: memref<?xf32>) -> (memref<?xf32>, memref<?xf32>) {
   return %arg0, %arg1 : memref<?xf32>, memref<?xf32>
 }
+
+// -----
+// BAREPTR-LABEL: func @unranked_memref(
+// BAREPTR-SAME: %{{.*}}: memref<*xi32>)
+func.func @unranked_memref(%arg0:memref<*xi32>) {
+  // BAREPTR:      call @printMemrefI32(%arg{{.*}}) : (memref<*xi32>) -> ()
+  // BAREPTR-NEXT: llvm.return
+  call @printMemrefI32(%arg0) : (memref<*xi32>) -> ()
+  return
+}
+func.func private @printMemrefI32(memref<*xi32>)


        


More information about the Mlir-commits mailing list