forked from OSchip/llvm-project
Add Builder::get{I32,I64}TensorAttr.
Builder::get{I32,I64}VectorAttr are actually of limited applicability since vector types can't have zero elements, whereas many uses of this kind of attribute (such as dimension lists for "transpose"-like and other tensor ops) often can result in empty lists. Differential Revision: https://reviews.llvm.org/D76403
This commit is contained in:
parent
a11e5b32df
commit
c31ee83abb
|
@ -116,9 +116,16 @@ public:
|
|||
IntegerAttr getSI32IntegerAttr(int32_t value);
|
||||
IntegerAttr getUI32IntegerAttr(uint32_t value);
|
||||
|
||||
/// Vector-typed DenseIntElementsAttr getters. `values` must not be empty.
|
||||
DenseIntElementsAttr getI32VectorAttr(ArrayRef<int32_t> values);
|
||||
DenseIntElementsAttr getI64VectorAttr(ArrayRef<int64_t> values);
|
||||
|
||||
/// Tensor-typed DenseIntElementsAttr getters. `values` can be empty.
|
||||
/// These are generally preferable for representing general lists of integers
|
||||
/// as attributes.
|
||||
DenseIntElementsAttr getI32TensorAttr(ArrayRef<int32_t> values);
|
||||
DenseIntElementsAttr getI64TensorAttr(ArrayRef<int64_t> values);
|
||||
|
||||
ArrayAttr getAffineMapArrayAttr(ArrayRef<AffineMap> values);
|
||||
ArrayAttr getI32ArrayAttr(ArrayRef<int32_t> values);
|
||||
ArrayAttr getI64ArrayAttr(ArrayRef<int64_t> values);
|
||||
|
|
|
@ -109,6 +109,20 @@ DenseIntElementsAttr Builder::getI64VectorAttr(ArrayRef<int64_t> values) {
|
|||
values);
|
||||
}
|
||||
|
||||
DenseIntElementsAttr Builder::getI32TensorAttr(ArrayRef<int32_t> values) {
|
||||
return DenseIntElementsAttr::get(
|
||||
RankedTensorType::get(static_cast<int64_t>(values.size()),
|
||||
getIntegerType(32)),
|
||||
values);
|
||||
}
|
||||
|
||||
DenseIntElementsAttr Builder::getI64TensorAttr(ArrayRef<int64_t> values) {
|
||||
return DenseIntElementsAttr::get(
|
||||
RankedTensorType::get(static_cast<int64_t>(values.size()),
|
||||
getIntegerType(64)),
|
||||
values);
|
||||
}
|
||||
|
||||
IntegerAttr Builder::getI32IntegerAttr(int32_t value) {
|
||||
return IntegerAttr::get(getIntegerType(32), APInt(32, value));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue