GetMemRefType failed on 0-D tensors. Loosened check to allow tensors with shape
authorRob Suderman <suderman@google.com>
Wed, 24 Apr 2019 20:25:49 +0000 (13:25 -0700)
committerMehdi Amini <joker.eph@gmail.com>
Mon, 6 May 2019 15:16:23 +0000 (08:16 -0700)
    {}.

--

PiperOrigin-RevId: 245104548

mlir/g3doc/LangRef.md
mlir/include/mlir/IR/StandardTypes.h
mlir/lib/IR/StandardTypes.cpp
mlir/test/IR/invalid.mlir

index eed2bed..3249b19 100644 (file)
@@ -678,8 +678,8 @@ of tensor type.
 Note: hexadecimal integer literals are not allowed in tensor type declarations
 to avoid confusion between `0xf32` and `0 x f32`. Zero sizes are allowed in
 tensors and treated as other sizes, e.g., `tensor<0 x 1 x i32>` and `tensor<1 x
-0 x i32>` are different types. Since zero sizes are not allowed in other types,
-such tensors should be optimized away before lowering tensors to memrefs.
+0 x i32>` are different types. Since zero sizes are not allowed in some other
+types, such tensors should be optimized away before lowering tensors to vectors.
 
 Examples:
 
@@ -722,7 +722,9 @@ A `memref` type is a reference to a region of memory (similar to a buffer
 pointer, but more powerful). The buffer pointed to by a memref can be allocated,
 aliased and deallocated. A memref can be used to read and write data from/to the
 memory region which it references. Memref types use the same shape specifier as
-tensor types, but do not allow unknown rank nor zero sizes.
+tensor types, but do not allow unknown rank. Note that `memref<f32>`, `memref<0
+x f32>`, `memref<1 x 0 x f32>`, and `memref<0 x 1 x f32>` are all different
+types.
 
 The memory space of a memref is specified by a target-specific integer index. If
 no memory space is specified, then the default memory space (0) is used. The
index 030d109..97062ab 100644 (file)
@@ -353,7 +353,7 @@ public:
 };
 
 /// MemRef types represent a region of memory that have a shape with a fixed
-/// number of dimensions. Each shape element can be a positive integer or
+/// number of dimensions. Each shape element can be a non-negative integer or
 /// unknown (represented by any negative integer). MemRef types also have an
 /// affine map composition, represented as an array AffineMap pointers.
 class MemRefType
index 7eddce4..1427f1f 100644 (file)
@@ -314,7 +314,7 @@ MemRefType MemRefType::getImpl(ArrayRef<int64_t> shape, Type elementType,
 
   for (int64_t s : shape) {
     // Negative sizes are not allowed except for `-1` that means dynamic size.
-    if (s <= 0 && s != -1) {
+    if (s < -1) {
       if (location)
         context->emitError(*location, "invalid memref size");
       return {};
index 8103fc7..a2d6353 100644 (file)
@@ -871,16 +871,6 @@ func @zero_in_vector_type() -> vector<1x0xi32>
 
 // -----
 
-// expected-error @+1 {{invalid memref size}}
-func @zero_memref_type() -> memref<0xi32>
-
-// -----
-
-// expected-error @+1 {{invalid memref size}}
-func @zero_in_memref_type() -> memref<1x0xi32>
-
-// -----
-
 // expected-error @+1 {{expected dimension size in vector type}}
 func @negative_vector_size() -> vector<-1xi32>