This is an archive of the discontinued LLVM Phabricator instance.

[mlir][sparse] cleanup small vector constant hints
ClosedPublic

Authored by aartbik on Nov 15 2022, 2:17 PM.

Details

Summary

Following advise from

https://llvm.org/docs/ProgrammersManual.html#llvm-adt-smallvector-h

This revision removes the size hints from SmallVector (unless we are
certain of the resulting number of elements). Also, this replaces
SmallVector references with SmallVectorImpl references.

Diff Detail

Event Timeline

aartbik created this revision.Nov 15 2022, 2:17 PM
Herald added a project: Restricted Project. · View Herald TranscriptNov 15 2022, 2:17 PM
aartbik requested review of this revision.Nov 15 2022, 2:17 PM

Much cleaner!

mlir/lib/Dialect/SparseTensor/Transforms/Sparsification.cpp
673–674

I think there is a implicit constructor for TypeRange(Type)

So probably builder.create<scf::IfOp>(loc, codegen.insChain.getType(), rhs, /*else=*/true); works without the need of the small vector.

mlir/lib/Dialect/SparseTensor/Utils/Merger.cpp
153

Can't it simply be latSets.emplace_back(); to avoid calling the move constructor here?

aartbik marked 2 inline comments as done.Nov 15 2022, 2:46 PM
aartbik added inline comments.
mlir/lib/Dialect/SparseTensor/Transforms/Sparsification.cpp
673–674

Right you are!

mlir/lib/Dialect/SparseTensor/Utils/Merger.cpp
153

I think you are right, good catch!

aartbik updated this revision to Diff 475590.Nov 15 2022, 2:49 PM
aartbik marked 2 inline comments as done.

addressed comments

Peiming accepted this revision.Nov 15 2022, 2:52 PM
This revision is now accepted and ready to land.Nov 15 2022, 2:52 PM
This revision was landed with ongoing or failed builds.Nov 15 2022, 3:09 PM
This revision was automatically updated to reflect the committed changes.
wrengr added inline comments.Nov 15 2022, 3:25 PM
mlir/lib/Dialect/SparseTensor/Transforms/CodegenUtils.h
98

I remember mentioning this before and Peiming had a good response (though I don't recall what it was), but: Why not use MutableArrayRef?

180

ditto

mlir/lib/Dialect/SparseTensor/Transforms/SparseBufferRewriting.cpp
493–495

Do these two ever get resized? I didn't see any appending anywhere, though I might've missed it

mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorCodegen.cpp
546–547

If there's only this one value, then why not use SV inits{genLoad(...)};? Or even better, assuming createFor takes an ArrayRef then why not just Value theInit = genLoad(...); and pass {theInit} to createFor?

mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorConversion.cpp
95

ditto my earlier comment about using MutableArrayRef

103

ditto

116

ditto

mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorRewriting.cpp
116

ditto

mlir/lib/Dialect/SparseTensor/Transforms/Sparsification.cpp
529

ditto

Peiming added inline comments.Nov 15 2022, 3:27 PM
mlir/lib/Dialect/SparseTensor/Transforms/CodegenUtils.h
98

I think here is inapplicable, because it calls push_back, MutableArrayRef need a fixed size