forked from OSchip/llvm-project
[mlir][Vector] First step for 0D vector type
There seems to be a consensus that we should allow 0D vectors: https://llvm.discourse.group/t/should-we-have-0-d-vectors/3097 This commit is only the first step: it changes the verifier and the parser to allow vectors like `vector<f32>` (but does not allow explicit 0 dimensions, i.e., `vector<0xf32>` is not allowed). Reviewed By: nicolasvasilache Differential Revision: https://reviews.llvm.org/D114086
This commit is contained in:
parent
35ff3a0095
commit
ddf2d62c7d
|
@ -895,7 +895,7 @@ def Builtin_Vector : Builtin_Type<"Vector", [
|
|||
vector-type ::= `vector` `<` static-dimension-list vector-element-type `>`
|
||||
vector-element-type ::= float-type | integer-type | index-type
|
||||
|
||||
static-dimension-list ::= (decimal-literal `x`)+
|
||||
static-dimension-list ::= (decimal-literal `x`)*
|
||||
```
|
||||
|
||||
The vector type represents a SIMD style vector, used by target-specific
|
||||
|
@ -903,13 +903,13 @@ def Builtin_Vector : Builtin_Type<"Vector", [
|
|||
vector<16 x f32>) we also support multidimensional registers on targets that
|
||||
support them (like TPUs).
|
||||
|
||||
Vector shapes must be positive decimal integers.
|
||||
Vector shapes must be positive decimal integers. 0D vectors are allowed by
|
||||
omitting the dimension: `vector<f32>`.
|
||||
|
||||
Note: hexadecimal integer literals are not allowed in vector type
|
||||
declarations, `vector<0x42xi32>` is invalid because it is interpreted as a
|
||||
2D vector with shape `(0, 42)` and zero shapes are not allowed.
|
||||
|
||||
|
||||
Examples:
|
||||
|
||||
```mlir
|
||||
|
|
|
@ -441,9 +441,6 @@ bool ShapedType::hasStaticShape(ArrayRef<int64_t> shape) const {
|
|||
|
||||
LogicalResult VectorType::verify(function_ref<InFlightDiagnostic()> emitError,
|
||||
ArrayRef<int64_t> shape, Type elementType) {
|
||||
if (shape.empty())
|
||||
return emitError() << "vector types must have at least one dimension";
|
||||
|
||||
if (!isValidElementType(elementType))
|
||||
return emitError()
|
||||
<< "vector elements must be int/index/float type but got "
|
||||
|
|
|
@ -442,9 +442,7 @@ Type Parser::parseTupleType() {
|
|||
|
||||
/// Parse a vector type.
|
||||
///
|
||||
/// vector-type ::= `vector` `<` non-empty-static-dimension-list type `>`
|
||||
/// non-empty-static-dimension-list ::= decimal-literal `x`
|
||||
/// static-dimension-list
|
||||
/// vector-type ::= `vector` `<` static-dimension-list type `>`
|
||||
/// static-dimension-list ::= (decimal-literal `x`)*
|
||||
///
|
||||
VectorType Parser::parseVectorType() {
|
||||
|
@ -456,8 +454,6 @@ VectorType Parser::parseVectorType() {
|
|||
SmallVector<int64_t, 4> dimensions;
|
||||
if (parseDimensionListRanked(dimensions, /*allowDynamic=*/false))
|
||||
return nullptr;
|
||||
if (dimensions.empty())
|
||||
return (emitError("expected dimension size in vector type"), nullptr);
|
||||
if (any_of(dimensions, [](int64_t i) { return i <= 0; }))
|
||||
return emitError(getToken().getLoc(),
|
||||
"vector types must have positive constant sizes"),
|
||||
|
|
|
@ -949,7 +949,7 @@ func @zero_in_vector_type() -> vector<1x0xi32>
|
|||
|
||||
// -----
|
||||
|
||||
// expected-error @+1 {{expected dimension size in vector type}}
|
||||
// expected-error @+1 {{expected non-function type}}
|
||||
func @negative_vector_size() -> vector<-1xi32>
|
||||
|
||||
// -----
|
||||
|
|
|
@ -67,8 +67,8 @@ func private @uint_types(ui2, ui4) -> (ui7, ui1023)
|
|||
// CHECK: func private @float_types(f80, f128)
|
||||
func private @float_types(f80, f128)
|
||||
|
||||
// CHECK: func private @vectors(vector<1xf32>, vector<2x4xf32>)
|
||||
func private @vectors(vector<1 x f32>, vector<2x4xf32>)
|
||||
// CHECK: func private @vectors(vector<f32>, vector<1xf32>, vector<2x4xf32>)
|
||||
func private @vectors(vector<f32>, vector<1 x f32>, vector<2x4xf32>)
|
||||
|
||||
// CHECK: func private @tensors(tensor<*xf32>, tensor<*xvector<2x4xf32>>, tensor<1x?x4x?x?xi32>, tensor<i8>)
|
||||
func private @tensors(tensor<* x f32>, tensor<* x vector<2x4xf32>>,
|
||||
|
|
Loading…
Reference in New Issue