[mlir] Add getters for DenseArrayAttr.

This change adds convenience getters to builders.

Differential Revision: https://reviews.llvm.org/D130696
This commit is contained in:
Adrian Kuegel 2022-07-28 12:50:40 +02:00
parent 28ad5dc3f7
commit ba110cf97a
2 changed files with 32 additions and 0 deletions

View File

@ -130,6 +130,14 @@ public:
DenseIntElementsAttr getI64VectorAttr(ArrayRef<int64_t> values);
DenseIntElementsAttr getIndexVectorAttr(ArrayRef<int64_t> values);
/// Vector-typed DenseArrayAttr getters.
DenseI8ArrayAttr getDenseI8ArrayAttr(ArrayRef<int8_t> values);
DenseI16ArrayAttr getDenseI16ArrayAttr(ArrayRef<int16_t> values);
DenseI32ArrayAttr getDenseI32ArrayAttr(ArrayRef<int32_t> values);
DenseI64ArrayAttr getDenseI64ArrayAttr(ArrayRef<int64_t> values);
DenseF32ArrayAttr getDenseF32ArrayAttr(ArrayRef<float> values);
DenseF64ArrayAttr getDenseF64ArrayAttr(ArrayRef<double> values);
/// Tensor-typed DenseIntElementsAttr getters. `values` can be empty.
/// These are generally preferable for representing general lists of integers
/// as attributes.

View File

@ -124,6 +124,30 @@ DenseIntElementsAttr Builder::getIndexVectorAttr(ArrayRef<int64_t> values) {
values);
}
DenseI8ArrayAttr Builder::getDenseI8ArrayAttr(ArrayRef<int8_t> values) {
return DenseI8ArrayAttr::get(context, values);
}
DenseI16ArrayAttr Builder::getDenseI16ArrayAttr(ArrayRef<int16_t> values) {
return DenseI16ArrayAttr::get(context, values);
}
DenseI32ArrayAttr Builder::getDenseI32ArrayAttr(ArrayRef<int32_t> values) {
return DenseI32ArrayAttr::get(context, values);
}
DenseI64ArrayAttr Builder::getDenseI64ArrayAttr(ArrayRef<int64_t> values) {
return DenseI64ArrayAttr::get(context, values);
}
DenseF32ArrayAttr Builder::getDenseF32ArrayAttr(ArrayRef<float> values) {
return DenseF32ArrayAttr::get(context, values);
}
DenseF64ArrayAttr Builder::getDenseF64ArrayAttr(ArrayRef<double> values) {
return DenseF64ArrayAttr::get(context, values);
}
DenseIntElementsAttr Builder::getI32TensorAttr(ArrayRef<int32_t> values) {
return DenseIntElementsAttr::get(
RankedTensorType::get(static_cast<int64_t>(values.size()),