@@ -838,6 +838,9 @@ template <typename T>
838
838
Attribute DenseArrayAttr<T>::parse(AsmParser &parser, Type odsType) {
839
839
if (parser.parseLSquare ())
840
840
return {};
841
+ // Handle empty list case.
842
+ if (succeeded (parser.parseOptionalRSquare ()))
843
+ return get (parser.getContext (), {});
841
844
Attribute result = parseWithoutBraces (parser, odsType);
842
845
if (parser.parseRSquare ())
843
846
return {};
@@ -860,42 +863,48 @@ struct denseArrayAttrEltTypeBuilder;
860
863
template <>
861
864
struct denseArrayAttrEltTypeBuilder <int8_t > {
862
865
constexpr static auto eltType = DenseArrayBaseAttr::EltType::I8;
863
- static ShapedType getShapedType (MLIRContext *context, int64_t shape) {
866
+ static ShapedType getShapedType (MLIRContext *context,
867
+ ArrayRef<int64_t > shape) {
864
868
return VectorType::get (shape, IntegerType::get (context, 8 ));
865
869
}
866
870
};
867
871
template <>
868
872
struct denseArrayAttrEltTypeBuilder <int16_t > {
869
873
constexpr static auto eltType = DenseArrayBaseAttr::EltType::I16;
870
- static ShapedType getShapedType (MLIRContext *context, int64_t shape) {
874
+ static ShapedType getShapedType (MLIRContext *context,
875
+ ArrayRef<int64_t > shape) {
871
876
return VectorType::get (shape, IntegerType::get (context, 16 ));
872
877
}
873
878
};
874
879
template <>
875
880
struct denseArrayAttrEltTypeBuilder <int32_t > {
876
881
constexpr static auto eltType = DenseArrayBaseAttr::EltType::I32;
877
- static ShapedType getShapedType (MLIRContext *context, int64_t shape) {
882
+ static ShapedType getShapedType (MLIRContext *context,
883
+ ArrayRef<int64_t > shape) {
878
884
return VectorType::get (shape, IntegerType::get (context, 32 ));
879
885
}
880
886
};
881
887
template <>
882
888
struct denseArrayAttrEltTypeBuilder <int64_t > {
883
889
constexpr static auto eltType = DenseArrayBaseAttr::EltType::I64;
884
- static ShapedType getShapedType (MLIRContext *context, int64_t shape) {
890
+ static ShapedType getShapedType (MLIRContext *context,
891
+ ArrayRef<int64_t > shape) {
885
892
return VectorType::get (shape, IntegerType::get (context, 64 ));
886
893
}
887
894
};
888
895
template <>
889
896
struct denseArrayAttrEltTypeBuilder <float > {
890
897
constexpr static auto eltType = DenseArrayBaseAttr::EltType::F32;
891
- static ShapedType getShapedType (MLIRContext *context, int64_t shape) {
898
+ static ShapedType getShapedType (MLIRContext *context,
899
+ ArrayRef<int64_t > shape) {
892
900
return VectorType::get (shape, Float32Type::get (context));
893
901
}
894
902
};
895
903
template <>
896
904
struct denseArrayAttrEltTypeBuilder <double > {
897
905
constexpr static auto eltType = DenseArrayBaseAttr::EltType::F64;
898
- static ShapedType getShapedType (MLIRContext *context, int64_t shape) {
906
+ static ShapedType getShapedType (MLIRContext *context,
907
+ ArrayRef<int64_t > shape) {
899
908
return VectorType::get (shape, Float64Type::get (context));
900
909
}
901
910
};
@@ -905,8 +914,9 @@ struct denseArrayAttrEltTypeBuilder<double> {
905
914
template <typename T>
906
915
DenseArrayAttr<T> DenseArrayAttr<T>::get(MLIRContext *context,
907
916
ArrayRef<T> content) {
908
- auto shapedType =
909
- denseArrayAttrEltTypeBuilder<T>::getShapedType (context, content.size ());
917
+ auto size = static_cast <int64_t >(content.size ());
918
+ auto shapedType = denseArrayAttrEltTypeBuilder<T>::getShapedType (
919
+ context, size ? ArrayRef<int64_t >{size} : ArrayRef<int64_t >{});
910
920
auto eltType = denseArrayAttrEltTypeBuilder<T>::eltType;
911
921
auto rawArray = ArrayRef<char >(reinterpret_cast <const char *>(content.data ()),
912
922
content.size () * sizeof (T));
0 commit comments