[Mlir-commits] [mlir] c31ee83 - Add Builder::get{I32, I64}TensorAttr.
Sean Silva
llvmlistbot at llvm.org
Thu Mar 19 11:38:17 PDT 2020
Author: Sean Silva
Date: 2020-03-19T11:37:59-07:00
New Revision: c31ee83abb0cae95b1a9216826076e442c3582f9
URL: https://github.com/llvm/llvm-project/commit/c31ee83abb0cae95b1a9216826076e442c3582f9
DIFF: https://github.com/llvm/llvm-project/commit/c31ee83abb0cae95b1a9216826076e442c3582f9.diff
LOG: 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
Added:
Modified:
mlir/include/mlir/IR/Builders.h
mlir/lib/IR/Builders.cpp
Removed:
################################################################################
diff --git a/mlir/include/mlir/IR/Builders.h b/mlir/include/mlir/IR/Builders.h
index 3817b35ea7cf..5b42132d463a 100644
--- a/mlir/include/mlir/IR/Builders.h
+++ b/mlir/include/mlir/IR/Builders.h
@@ -116,9 +116,16 @@ class Builder {
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);
diff --git a/mlir/lib/IR/Builders.cpp b/mlir/lib/IR/Builders.cpp
index 82d2efb5255c..23536651f974 100644
--- a/mlir/lib/IR/Builders.cpp
+++ b/mlir/lib/IR/Builders.cpp
@@ -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));
}
More information about the Mlir-commits
mailing list