From: Rob Suderman Date: Wed, 24 Apr 2019 20:25:49 +0000 (-0700) Subject: GetMemRefType failed on 0-D tensors. Loosened check to allow tensors with shape X-Git-Tag: llvmorg-11-init~1466^2~1887 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=69cdceae73387cafc797ca77530ab4aa20ae4c3a;p=platform%2Fupstream%2Fllvm.git GetMemRefType failed on 0-D tensors. Loosened check to allow tensors with shape {}. -- PiperOrigin-RevId: 245104548 --- diff --git a/mlir/g3doc/LangRef.md b/mlir/g3doc/LangRef.md index eed2bed..3249b19 100644 --- a/mlir/g3doc/LangRef.md +++ b/mlir/g3doc/LangRef.md @@ -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`, `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 diff --git a/mlir/include/mlir/IR/StandardTypes.h b/mlir/include/mlir/IR/StandardTypes.h index 030d109..97062ab 100644 --- a/mlir/include/mlir/IR/StandardTypes.h +++ b/mlir/include/mlir/IR/StandardTypes.h @@ -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 diff --git a/mlir/lib/IR/StandardTypes.cpp b/mlir/lib/IR/StandardTypes.cpp index 7eddce4..1427f1f 100644 --- a/mlir/lib/IR/StandardTypes.cpp +++ b/mlir/lib/IR/StandardTypes.cpp @@ -314,7 +314,7 @@ MemRefType MemRefType::getImpl(ArrayRef 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 {}; diff --git a/mlir/test/IR/invalid.mlir b/mlir/test/IR/invalid.mlir index 8103fc7..a2d6353 100644 --- a/mlir/test/IR/invalid.mlir +++ b/mlir/test/IR/invalid.mlir @@ -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>