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

Denis Khalikov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Jan 19 06:58:50 PST 2020


denis13 created this revision.
denis13 added reviewers: antiagainst, mravishankar.
Herald added subscribers: llvm-commits, liufengdb, lucyrfox, mgester, arpith-jacob, shauheen, burmako, jpienaar, rriddle, mehdi_amini.
Herald added a reviewer: nicolasvasilache.
Herald added a project: LLVM.

Simplify scalar type size calculation and handle boolean types.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D72999

Files:
  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({{%.*}}: !spv.ptr<!spv.struct<!spv.array<3 x i1 [1]> [0]>, {{.*}}>
+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,9 @@
 // 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();
+    return bitWidth == 1 ? 1 : (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.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D72999.238985.patch
Type: text/x-patch
Size: 1607 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200119/eec5b532/attachment-0001.bin>


More information about the llvm-commits mailing list