[PATCH] D72999: [mlir][spirv] Simplify scalar type size calculation.

Denis Khalikov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 21 08:29:08 PST 2020


denis13 updated this revision to Diff 239332.
denis13 added a comment.

Addressed review comments.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D72999/new/

https://reviews.llvm.org/D72999

Files:
  mlir/lib/Conversion/StandardToSPIRV/ConvertStandardToSPIRVPass.cpp
  mlir/lib/Dialect/SPIRV/SPIRVLowering.cpp
  mlir/test/Conversion/StandardToSPIRV/std-to-spirv.mlir


Index: mlir/test/Conversion/StandardToSPIRV/std-to-spirv.mlir
===================================================================
--- mlir/test/Conversion/StandardToSPIRV/std-to-spirv.mlir
+++ mlir/test/Conversion/StandardToSPIRV/std-to-spirv.mlir
@@ -289,3 +289,12 @@
   %0 = std.sitofp %arg0 : i32 to f32
   return
 }
+
+//===----------------------------------------------------------------------===//
+// memref type
+//===----------------------------------------------------------------------===//
+
+// CHECK-LABEL: func @memref_type({{%.*}}: memref<3xi1>) {
+func @memref_type(%arg0: memref<3xi1>) {
+  return
+}
Index: mlir/lib/Dialect/SPIRV/SPIRVLowering.cpp
===================================================================
--- mlir/lib/Dialect/SPIRV/SPIRVLowering.cpp
+++ mlir/lib/Dialect/SPIRV/SPIRVLowering.cpp
@@ -41,10 +41,17 @@
 // TODO(ravishankarm): This is a utility function that should probably be
 // exposed by the SPIR-V dialect. Keeping it local till the use case arises.
 static Optional<int64_t> getTypeNumBytes(Type t) {
-  if (auto integerType = t.dyn_cast<IntegerType>()) {
-    return integerType.getWidth() / 8;
-  } else if (auto floatType = t.dyn_cast<FloatType>()) {
-    return floatType.getWidth() / 8;
+  if (spirv::SPIRVDialect::isValidScalarType(t)) {
+    auto bitWidth = t.getIntOrFloatBitWidth();
+    // There is no physical size or bit pattern defined for values with boolean
+    // type. If they are stored (in conjunction with OpVariable), they can only
+    // be used with logical addressing operations, not physical, and only with
+    // non-externally visible shader Storage Classes: Workgroup, CrossWorkgroup,
+    // Private, Function, Input, and Output.
+    if (bitWidth == 1) {
+      return llvm::None;
+    }
+    return bitWidth / 8;
   } else if (auto memRefType = t.dyn_cast<MemRefType>()) {
     // TODO: Layout should also be controlled by the ABI attributes. For now
     // using the layout from MemRef.
Index: mlir/lib/Conversion/StandardToSPIRV/ConvertStandardToSPIRVPass.cpp
===================================================================
--- mlir/lib/Conversion/StandardToSPIRV/ConvertStandardToSPIRVPass.cpp
+++ mlir/lib/Conversion/StandardToSPIRV/ConvertStandardToSPIRVPass.cpp
@@ -51,6 +51,9 @@
   {
     for (auto argType : enumerate(funcOp.getType().getInputs())) {
       auto convertedType = typeConverter.convertType(argType.value());
+      if (!convertedType) {
+        return matchFailure();
+      }
       signatureConverter.addInputs(argType.index(), convertedType);
     }
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D72999.239332.patch
Type: text/x-patch
Size: 2570 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200121/f7fc166a/attachment.bin>


More information about the llvm-commits mailing list