This is an archive of the discontinued LLVM Phabricator instance.

[mlir][Linalg] Add a utility method to get reassociations maps for reshape.
ClosedPublic

Authored by mravishankar on Apr 26 2021, 10:44 PM.

Details

Summary

Given the source and destination shapes, if they are static, or if the
expanded/collapsed dimensions are unit-extent, it is possible to
compute the reassociation maps that can be used to reshape one type
into another. Add a utility method to return the reassociation maps
when possible.

This utility function can be used to fuse a sequence of reshape ops,
given the type of the source of the producer and the final result
type. This pattern supercedes a more constrained folding pattern added
to DropUnitDims pass.

Depends On D101258

Diff Detail

Event Timeline

mravishankar created this revision.Apr 26 2021, 10:44 PM
mravishankar requested review of this revision.Apr 26 2021, 10:44 PM

Cleaup comments.

hanchung added inline comments.Apr 27 2021, 6:12 AM
mlir/include/mlir/Dialect/Linalg/IR/LinalgOps.h
59
mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp
1208–1210

I'd prefer this way. It's simpler to me.

reassociationMaps.emplace_back(reassociations);
reassociations.clear();
1236–1247

I think we do not need the assignment here.

hanchung accepted this revision.Apr 27 2021, 6:12 AM
This revision is now accepted and ready to land.Apr 27 2021, 6:12 AM
mravishankar added inline comments.Apr 27 2021, 10:00 AM
mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp
1208–1210

This is what I had, but clang-tidy flagged this as using the value after is has been move-d. So I switched to this one.

1236–1247

It reads better to me to make it explicit.

Nice, this will also prepare for the upcoming changes to reshape op.
Can we rename "map/maps" to "index/indices" where appropriate in variable and function names?

nicolasvasilache accepted this revision.Apr 30 2021, 1:07 AM

Address minor comments

This revision was landed with ongoing or failed builds.May 3 2021, 2:40 PM
This revision was automatically updated to reflect the committed changes.