[mlir][StandardToSPIRV] Add support for lowering memref<?xi1> to SPIR-V
authorHanhan Wang <hanchung@google.com>
Wed, 14 Apr 2021 14:22:41 +0000 (07:22 -0700)
committerHanhan Wang <hanchung@google.com>
Wed, 14 Apr 2021 14:22:49 +0000 (07:22 -0700)
Reviewed By: antiagainst

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

mlir/lib/Dialect/SPIRV/Transforms/SPIRVConversion.cpp
mlir/test/Conversion/StandardToSPIRV/std-types-to-spirv.mlir

index 9de45e7..5a59021 100644 (file)
@@ -375,12 +375,6 @@ static Type convertTensorType(const spirv::TargetEnv &targetEnv,
 static Type convertBoolMemrefType(const spirv::TargetEnv &targetEnv,
                                   const SPIRVTypeConverter::Options &options,
                                   MemRefType type) {
-  if (!type.hasStaticShape()) {
-    LLVM_DEBUG(llvm::dbgs()
-               << type << " dynamic shape on i1 is not supported yet\n");
-    return nullptr;
-  }
-
   Optional<spirv::StorageClass> storageClass =
       SPIRVTypeConverter::getStorageClassForMemorySpace(
           type.getMemorySpaceAsInt());
@@ -411,6 +405,12 @@ static Type convertBoolMemrefType(const spirv::TargetEnv &targetEnv,
     return nullptr;
   }
 
+  if (!type.hasStaticShape()) {
+    auto arrayType =
+        spirv::RuntimeArrayType::get(arrayElemType, *arrayElemSize);
+    return wrapInStructAndGetPointer(arrayType, *storageClass);
+  }
+
   int64_t memrefSize = (type.getNumElements() * numBoolBits + 7) / 8;
   auto arrayElemCount = (memrefSize + *arrayElemSize - 1) / *arrayElemSize;
   auto arrayType =
index aa4999d..bb253a1 100644 (file)
@@ -511,9 +511,10 @@ module attributes {
 // CHECK-SAME: memref<*xi32>
 func @unranked_memref(%arg0: memref<*xi32>) { return }
 
-// Check that dynamic dims on i1 are not supported.
 // CHECK-LABEL: func @memref_1bit_type
-// CHECK-SAME: memref<?xi1>
+// CHECK-SAME: !spv.ptr<!spv.struct<(!spv.rtarray<i32, stride=4> [0])>, StorageBuffer>
+// NOEMU-LABEL: func @memref_1bit_type
+// NOEMU-SAME: memref<?xi1>
 func @memref_1bit_type(%arg0: memref<?xi1>) { return }
 
 // CHECK-LABEL: func @dynamic_dim_memref