[Mlir-commits] [mlir] [mlir] Add DenseUI32ArrayAttr (PR #68230)
Maya Amrami
llvmlistbot at llvm.org
Mon Oct 9 01:36:14 PDT 2023
https://github.com/amrami updated https://github.com/llvm/llvm-project/pull/68230
>From 9794b69dce9e38275bbcfc31d35249fd47c07e8b Mon Sep 17 00:00:00 2001
From: Maya Amrami <mayaam88 at gmail.com>
Date: Thu, 21 Sep 2023 18:11:50 +0300
Subject: [PATCH] [mlir] Add DenseUI32ArrayAttr
---
mlir/include/mlir/IR/Builders.h | 1 +
mlir/include/mlir/IR/BuiltinAttributes.h | 2 ++
mlir/include/mlir/IR/CommonAttrConstraints.td | 1 +
mlir/lib/IR/Builders.cpp | 4 ++++
mlir/lib/IR/BuiltinAttributes.cpp | 4 ++++
mlir/test/IR/attribute.mlir | 13 ++++++++++++-
mlir/test/lib/Dialect/Test/TestOps.td | 9 +++++++--
7 files changed, 31 insertions(+), 3 deletions(-)
diff --git a/mlir/include/mlir/IR/Builders.h b/mlir/include/mlir/IR/Builders.h
index 5e54d4ea49e8251..a121c07bdad9229 100644
--- a/mlir/include/mlir/IR/Builders.h
+++ b/mlir/include/mlir/IR/Builders.h
@@ -154,6 +154,7 @@ class Builder {
DenseBoolArrayAttr getDenseBoolArrayAttr(ArrayRef<bool> values);
DenseI8ArrayAttr getDenseI8ArrayAttr(ArrayRef<int8_t> values);
DenseI16ArrayAttr getDenseI16ArrayAttr(ArrayRef<int16_t> values);
+ DenseUI32ArrayAttr getDenseUI32ArrayAttr(ArrayRef<uint32_t> values);
DenseI32ArrayAttr getDenseI32ArrayAttr(ArrayRef<int32_t> values);
DenseI64ArrayAttr getDenseI64ArrayAttr(ArrayRef<int64_t> values);
DenseF32ArrayAttr getDenseF32ArrayAttr(ArrayRef<float> values);
diff --git a/mlir/include/mlir/IR/BuiltinAttributes.h b/mlir/include/mlir/IR/BuiltinAttributes.h
index c8161604aad3503..ee12e9c59986eb0 100644
--- a/mlir/include/mlir/IR/BuiltinAttributes.h
+++ b/mlir/include/mlir/IR/BuiltinAttributes.h
@@ -755,6 +755,7 @@ class DenseArrayAttrImpl : public DenseArrayAttr {
extern template class DenseArrayAttrImpl<bool>;
extern template class DenseArrayAttrImpl<int8_t>;
extern template class DenseArrayAttrImpl<int16_t>;
+extern template class DenseArrayAttrImpl<uint32_t>;
extern template class DenseArrayAttrImpl<int32_t>;
extern template class DenseArrayAttrImpl<int64_t>;
extern template class DenseArrayAttrImpl<float>;
@@ -765,6 +766,7 @@ extern template class DenseArrayAttrImpl<double>;
using DenseBoolArrayAttr = detail::DenseArrayAttrImpl<bool>;
using DenseI8ArrayAttr = detail::DenseArrayAttrImpl<int8_t>;
using DenseI16ArrayAttr = detail::DenseArrayAttrImpl<int16_t>;
+using DenseUI32ArrayAttr = detail::DenseArrayAttrImpl<uint32_t>;
using DenseI32ArrayAttr = detail::DenseArrayAttrImpl<int32_t>;
using DenseI64ArrayAttr = detail::DenseArrayAttrImpl<int64_t>;
using DenseF32ArrayAttr = detail::DenseArrayAttrImpl<float>;
diff --git a/mlir/include/mlir/IR/CommonAttrConstraints.td b/mlir/include/mlir/IR/CommonAttrConstraints.td
index 0312ac7ec1d8df5..6bdf286d0928913 100644
--- a/mlir/include/mlir/IR/CommonAttrConstraints.td
+++ b/mlir/include/mlir/IR/CommonAttrConstraints.td
@@ -433,6 +433,7 @@ class DenseArrayAttrBase<string denseAttrName, string cppType, string summaryNam
def DenseBoolArrayAttr : DenseArrayAttrBase<"DenseBoolArrayAttr", "bool", "i1">;
def DenseI8ArrayAttr : DenseArrayAttrBase<"DenseI8ArrayAttr", "int8_t", "i8">;
def DenseI16ArrayAttr : DenseArrayAttrBase<"DenseI16ArrayAttr", "int16_t", "i16">;
+def DenseUI32ArrayAttr : DenseArrayAttrBase<"DenseUI32ArrayAttr", "uint32_t", "ui32">;
def DenseI32ArrayAttr : DenseArrayAttrBase<"DenseI32ArrayAttr", "int32_t", "i32">;
def DenseI64ArrayAttr : DenseArrayAttrBase<"DenseI64ArrayAttr", "int64_t", "i64">;
def DenseF32ArrayAttr : DenseArrayAttrBase<"DenseF32ArrayAttr", "float", "f32">;
diff --git a/mlir/lib/IR/Builders.cpp b/mlir/lib/IR/Builders.cpp
index ab20f4863e11c23..ba08544eb4059a0 100644
--- a/mlir/lib/IR/Builders.cpp
+++ b/mlir/lib/IR/Builders.cpp
@@ -180,6 +180,10 @@ DenseI32ArrayAttr Builder::getDenseI32ArrayAttr(ArrayRef<int32_t> values) {
return DenseI32ArrayAttr::get(context, values);
}
+DenseUI32ArrayAttr Builder::getDenseUI32ArrayAttr(ArrayRef<uint32_t> values) {
+ return DenseUI32ArrayAttr::get(context, values);
+}
+
DenseI64ArrayAttr Builder::getDenseI64ArrayAttr(ArrayRef<int64_t> values) {
return DenseI64ArrayAttr::get(context, values);
}
diff --git a/mlir/lib/IR/BuiltinAttributes.cpp b/mlir/lib/IR/BuiltinAttributes.cpp
index 64949a17107297a..ec333f59ed441fb 100644
--- a/mlir/lib/IR/BuiltinAttributes.cpp
+++ b/mlir/lib/IR/BuiltinAttributes.cpp
@@ -757,6 +757,9 @@ struct DenseArrayAttrUtil<int8_t> : public DenseArrayAttrIntUtil<8> {
template <>
struct DenseArrayAttrUtil<int16_t> : public DenseArrayAttrIntUtil<16> {};
template <>
+struct DenseArrayAttrUtil<uint32_t>
+ : public DenseArrayAttrIntUtil<32, IntegerType::Unsigned> {};
+template <>
struct DenseArrayAttrUtil<int32_t> : public DenseArrayAttrIntUtil<32> {};
template <>
struct DenseArrayAttrUtil<int64_t> : public DenseArrayAttrIntUtil<64> {};
@@ -872,6 +875,7 @@ namespace detail {
template class DenseArrayAttrImpl<bool>;
template class DenseArrayAttrImpl<int8_t>;
template class DenseArrayAttrImpl<int16_t>;
+template class DenseArrayAttrImpl<uint32_t>;
template class DenseArrayAttrImpl<int32_t>;
template class DenseArrayAttrImpl<int64_t>;
template class DenseArrayAttrImpl<float>;
diff --git a/mlir/test/IR/attribute.mlir b/mlir/test/IR/attribute.mlir
index 291d5832fce79aa..05ddb39b75eb658 100644
--- a/mlir/test/IR/attribute.mlir
+++ b/mlir/test/IR/attribute.mlir
@@ -592,6 +592,8 @@ func.func @dense_array_attr() attributes {
emptyi64attr = array<i64>,
// CHECK-SAME: emptyi8attr = array<i8>,
emptyi8attr = array<i8>,
+// CHECK-SAME: emptyui32attr = array<ui32>,
+ emptyui32attr = array<ui32>,
// CHECK-SAME: f32attr = array<f32: 1.024000e+03, 4.530000e+02, -6.435000e+03>,
f32attr = array<f32: 1024., 453., -6435.>,
// CHECK-SAME: f64attr = array<f64: -1.420000e+02>,
@@ -605,7 +607,9 @@ func.func @dense_array_attr() attributes {
// CHECK-SAME: i64attr = array<i64: -142>,
i64attr = array<i64: -142>,
// CHECK-SAME: i8attr = array<i8: 1, -2, 3>
- i8attr = array<i8: 1, -2, 3>
+ i8attr = array<i8: 1, -2, 3>,
+// CHECK-SAME: ui32attr = array<ui32: 1024, 453, 6435>
+ ui32attr = array<ui32: 1024, 453, 6435>
} {
// CHECK: test.dense_array_attr
test.dense_array_attr
@@ -617,6 +621,8 @@ func.func @dense_array_attr() attributes {
i16attr = [3, 5, -4, 10]
// CHECK-SAME: i32attr = [1024, 453, -6435]
i32attr = [1024, 453, -6435]
+// CHECK-SAME: ui32attr = [1024, 453, 6435]
+ ui32attr = [1024, 453, 6435]
// CHECK-SAME: i64attr = [-142]
i64attr = [-142]
// CHECK-SAME: f32attr = [1.024000e+03, 4.530000e+02, -6.435000e+03]
@@ -655,6 +661,7 @@ func.func @testConfinedDenseArrayAttr() {
"test.confined_dense_array_attr"() {
i64attr = array<i64: 0, 2, 3>,
i32attr = array<i32: 1>,
+ ui32attr = array<ui32: 10>,
emptyattr = array<i16>
} : () -> ()
func.return
@@ -666,6 +673,7 @@ func.func @testConfinedDenseArrayAttrDuplicateValues() {
// expected-error at +1{{'test.confined_dense_array_attr' op attribute 'i64attr' failed to satisfy constraint: i64 dense array attribute should be in increasing order}}
"test.confined_dense_array_attr"() {
emptyattr = array<i16>,
+ ui32attr = array<ui32: 3, 3>,
i32attr = array<i32: 1, 1>,
i64attr = array<i64: 0, 2, 2>
} : () -> ()
@@ -678,6 +686,7 @@ func.func @testConfinedDenseArrayAttrDecreasingOrder() {
// expected-error at +1{{'test.confined_dense_array_attr' op attribute 'i32attr' failed to satisfy constraint: i32 dense array attribute should be in non-decreasing order}}
"test.confined_dense_array_attr"() {
emptyattr = array<i16>,
+ ui32attr = array<ui32: 1, 2>,
i32attr = array<i32: 1, 0>,
i64attr = array<i64: 0, 2, 3>
} : () -> ()
@@ -690,6 +699,7 @@ func.func @testConfinedStrictlyPositiveDenseArrayAttr() {
"test.confined_strictly_positive_attr"() {
i8attr = array<i8: 2, 3>,
i16attr = array<i16: 20, 30>,
+ ui32attr = array<ui32: 1>,
i32attr = array<i32: 1>,
i64attr = array<i64: 1, 2, 3>,
f32attr = array<f32: 1.1, 2.1>,
@@ -706,6 +716,7 @@ func.func @testConfinedStrictlyPositiveDenseArrayAttr() {
"test.confined_strictly_positive_attr"() {
i8attr = array<i8: 2, 3>,
i16attr = array<i16: 20, 30>,
+ ui32attr = array<ui32: 1>,
i32attr = array<i32: 1>,
i64attr = array<i64: 0, 2, 3>,
f32attr = array<f32: 1.1, 2.1>,
diff --git a/mlir/test/lib/Dialect/Test/TestOps.td b/mlir/test/lib/Dialect/Test/TestOps.td
index edb63924b3553f2..cfc9fd1e262f5e6 100644
--- a/mlir/test/lib/Dialect/Test/TestOps.td
+++ b/mlir/test/lib/Dialect/Test/TestOps.td
@@ -300,6 +300,7 @@ def DenseArrayAttrOp : TEST_Op<"dense_array_attr"> {
DenseI8ArrayAttr:$i8attr,
DenseI16ArrayAttr:$i16attr,
DenseI32ArrayAttr:$i32attr,
+ DenseUI32ArrayAttr:$ui32attr,
DenseI64ArrayAttr:$i64attr,
DenseF32ArrayAttr:$f32attr,
DenseF64ArrayAttr:$f64attr,
@@ -307,7 +308,7 @@ def DenseArrayAttrOp : TEST_Op<"dense_array_attr"> {
);
let assemblyFormat = [{
`i1attr` `=` $i1attr `i8attr` `=` $i8attr `i16attr` `=` $i16attr
- `i32attr` `=` $i32attr `i64attr` `=` $i64attr `f32attr` `=` $f32attr
+ `i32attr` `=` $i32attr `ui32attr` `=` $ui32attr `i64attr` `=` $i64attr `f32attr` `=` $f32attr
`f64attr` `=` $f64attr `emptyattr` `=` $emptyattr attr-dict
}];
}
@@ -320,6 +321,8 @@ def ConfinedDenseArrayAttrOp : TEST_Op<"confined_dense_array_attr"> {
let arguments = (ins
ConfinedAttr<DenseI16ArrayAttr,
[DenseArrayStrictlySorted<DenseI16ArrayAttr>]>:$emptyattr,
+ ConfinedAttr<DenseUI32ArrayAttr,
+ [DenseArraySorted<DenseUI32ArrayAttr>]>:$ui32attr,
ConfinedAttr<DenseI32ArrayAttr,
[DenseArraySorted<DenseI32ArrayAttr>]>:$i32attr,
ConfinedAttr<DenseI64ArrayAttr,
@@ -334,6 +337,8 @@ def DenseArrayStrictlyPositiveAttrOp : TEST_Op<"confined_strictly_positive_attr"
[DenseArrayStrictlyPositive<DenseI8ArrayAttr>]>:$i8attr,
ConfinedAttr<DenseI16ArrayAttr,
[DenseArrayStrictlyPositive<DenseI16ArrayAttr>]>:$i16attr,
+ ConfinedAttr<DenseUI32ArrayAttr,
+ [DenseArrayStrictlyPositive<DenseUI32ArrayAttr>]>:$ui32attr,
ConfinedAttr<DenseI32ArrayAttr,
[DenseArrayStrictlyPositive<DenseI32ArrayAttr>]>:$i32attr,
ConfinedAttr<DenseI64ArrayAttr,
@@ -347,7 +352,7 @@ def DenseArrayStrictlyPositiveAttrOp : TEST_Op<"confined_strictly_positive_attr"
);
}
-// It does not make sense to have this constraint on a DenseBoolArrayAttr.
+// It does not make sense to have this constraint on a DenseBoolArrayAttr/DenseUI32ArrayAttr.
// It is always true.
def DenseArrayNonNegativeOp : TEST_Op<"confined_non_negative_attr"> {
let arguments = (ins
More information about the Mlir-commits
mailing list