Skip to content

Commit 5e101de

Browse files
authored
[mlir][nfc] Replace some std::vectors with SmallVector (llvm#136703)
`SmallVector` is preferable to `std::vector` https://llvm.org/docs/ProgrammersManual.html#llvm-adt-smallvector-h
1 parent c05da6e commit 5e101de

File tree

3 files changed

+11
-10
lines changed

3 files changed

+11
-10
lines changed

mlir/include/mlir/IR/BuiltinAttributes.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -994,7 +994,7 @@ auto SparseElementsAttr::try_value_begin_impl(OverloadToken<T>) const
994994
auto valueIt = getValues().try_value_begin<T>();
995995
if (failed(valueIt))
996996
return failure();
997-
const std::vector<ptrdiff_t> flatSparseIndices(getFlattenedSparseIndices());
997+
const SmallVector<ptrdiff_t> flatSparseIndices(getFlattenedSparseIndices());
998998
std::function<T(ptrdiff_t)> mapFn =
999999
[flatSparseIndices{flatSparseIndices}, valueIt{std::move(*valueIt)},
10001000
zeroValue{std::move(zeroValue)}](ptrdiff_t index) {

mlir/include/mlir/IR/BuiltinAttributes.td

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ def Builtin_DenseArrayRawDataParameter : ArrayRefParameter<
164164
}];
165165
}
166166

167-
def Builtin_DenseArray : Builtin_Attr<"DenseArray", "dense_array",
167+
def Builtin_DenseArray : Builtin_Attr<"DenseArray", "dense_array",
168168
[BlobAttrInterface]> {
169169
let summary = "A dense array of integer or floating point elements.";
170170
let description = [{
@@ -494,7 +494,7 @@ def Builtin_DenseResourceElementsAttr : Builtin_Attr<"DenseResourceElements",
494494
/// when building the attribute. The provided `blobName` is used as a hint
495495
/// for the key of the new handle for the `blob` resource, but may be
496496
/// changed if necessary to ensure uniqueness during insertion.
497-
/// This base class builder does no element type specific size or alignment
497+
/// This base class builder does no element type specific size or alignment
498498
/// checking. Use the typed subclasses for more safety unless if performing
499499
/// generic operations.
500500
AttrBuilderWithInferredContext<(ins
@@ -989,7 +989,7 @@ def Builtin_SparseElementsAttr : Builtin_Attr<
989989

990990
/// Flatten, and return, all of the sparse indices in this attribute in
991991
/// row-major order.
992-
std::vector<ptrdiff_t> getFlattenedSparseIndices() const;
992+
SmallVector<ptrdiff_t> getFlattenedSparseIndices() const;
993993

994994
public:
995995
}];

mlir/lib/IR/BuiltinAttributes.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -988,7 +988,7 @@ DenseElementsAttr DenseElementsAttr::get(ShapedType type,
988988
assert(hasSameNumElementsOrSplat(type, values));
989989
assert(type.getElementType().isInteger(1));
990990

991-
std::vector<char> buff(llvm::divideCeil(values.size(), CHAR_BIT));
991+
SmallVector<char> buff(llvm::divideCeil(values.size(), CHAR_BIT));
992992

993993
if (!values.empty()) {
994994
bool isSplat = true;
@@ -1306,7 +1306,8 @@ int64_t DenseElementsAttr::getNumElements() const {
13061306

13071307
/// Utility method to write a range of APInt values to a buffer.
13081308
template <typename APRangeT>
1309-
static void writeAPIntsToBuffer(size_t storageWidth, std::vector<char> &data,
1309+
static void writeAPIntsToBuffer(size_t storageWidth,
1310+
SmallVectorImpl<char> &data,
13101311
APRangeT &&values) {
13111312
size_t numValues = llvm::size(values);
13121313
data.resize(llvm::divideCeil(storageWidth * numValues, CHAR_BIT));
@@ -1328,7 +1329,7 @@ static void writeAPIntsToBuffer(size_t storageWidth, std::vector<char> &data,
13281329
DenseElementsAttr DenseIntOrFPElementsAttr::getRaw(ShapedType type,
13291330
size_t storageWidth,
13301331
ArrayRef<APFloat> values) {
1331-
std::vector<char> data;
1332+
SmallVector<char> data;
13321333
auto unwrapFloat = [](const APFloat &val) { return val.bitcastToAPInt(); };
13331334
writeAPIntsToBuffer(storageWidth, data, llvm::map_range(values, unwrapFloat));
13341335
return DenseIntOrFPElementsAttr::getRaw(type, data);
@@ -1340,7 +1341,7 @@ DenseElementsAttr DenseIntOrFPElementsAttr::getRaw(ShapedType type,
13401341
DenseElementsAttr DenseIntOrFPElementsAttr::getRaw(ShapedType type,
13411342
size_t storageWidth,
13421343
ArrayRef<APInt> values) {
1343-
std::vector<char> data;
1344+
SmallVector<char> data;
13441345
writeAPIntsToBuffer(storageWidth, data, values);
13451346
return DenseIntOrFPElementsAttr::getRaw(type, data);
13461347
}
@@ -1705,8 +1706,8 @@ Attribute SparseElementsAttr::getZeroAttr() const {
17051706

17061707
/// Flatten, and return, all of the sparse indices in this attribute in
17071708
/// row-major order.
1708-
std::vector<ptrdiff_t> SparseElementsAttr::getFlattenedSparseIndices() const {
1709-
std::vector<ptrdiff_t> flatSparseIndices;
1709+
SmallVector<ptrdiff_t> SparseElementsAttr::getFlattenedSparseIndices() const {
1710+
SmallVector<ptrdiff_t> flatSparseIndices;
17101711

17111712
// The sparse indices are 64-bit integers, so we can reinterpret the raw data
17121713
// as a 1-D index array.

0 commit comments

Comments
 (0)