diff --git a/mlir/include/mlir/IR/Builders.h b/mlir/include/mlir/IR/Builders.h --- a/mlir/include/mlir/IR/Builders.h +++ b/mlir/include/mlir/IR/Builders.h @@ -116,9 +116,16 @@ IntegerAttr getSI32IntegerAttr(int32_t value); IntegerAttr getUI32IntegerAttr(uint32_t value); + /// Vector-typed DenseIntElementsAttr getters. `values` cannot be empty. DenseIntElementsAttr getI32VectorAttr(ArrayRef values); DenseIntElementsAttr getI64VectorAttr(ArrayRef values); + /// Tensor-typed DenseInteElementsAttr getters. `values` can be empty. + /// These are generally preferable for representing general lists of integers + /// as attributes. + DenseIntElementsAttr getI32TensorAttr(ArrayRef values); + DenseIntElementsAttr getI64TensorAttr(ArrayRef values); + ArrayAttr getAffineMapArrayAttr(ArrayRef values); ArrayAttr getI32ArrayAttr(ArrayRef values); ArrayAttr getI64ArrayAttr(ArrayRef values); diff --git a/mlir/lib/IR/Builders.cpp b/mlir/lib/IR/Builders.cpp --- a/mlir/lib/IR/Builders.cpp +++ b/mlir/lib/IR/Builders.cpp @@ -109,6 +109,20 @@ values); } +DenseIntElementsAttr Builder::getI32TensorAttr(ArrayRef values) { + return DenseIntElementsAttr::get( + RankedTensorType::get(static_cast(values.size()), + getIntegerType(32)), + values); +} + +DenseIntElementsAttr Builder::getI64TensorAttr(ArrayRef values) { + return DenseIntElementsAttr::get( + RankedTensorType::get(static_cast(values.size()), + getIntegerType(64)), + values); +} + IntegerAttr Builder::getI32IntegerAttr(int32_t value) { return IntegerAttr::get(getIntegerType(32), APInt(32, value)); }