This is an archive of the discontinued LLVM Phabricator instance.

[mlir][vector] Add a custom builder for LowerVectorsOp
ClosedPublic

Authored by qcolombet on Jan 17 2023, 5:20 AM.

Details

Summary

The lower_vectors operation of the transform dialect takes a lot of arguments to build.
In order to make C++ code easier to work with when using this instruction, introduce a new structure, named LowerVectorsOptions, that aggregates all the options that are used to build this instruction.

This allows to use patterns like:

LowerVectorsOptions opts;
opts.setOptZ(...)
  .setOptY(...)...;
builder.create<LowerVectorsOp>(target, opts);

Instead of having to pass all N options directly to the builder and set them in the right order.

NFC.

Note: I'm looking whether we can set this structure in a .td file like LoopOptionsAttr but not sure how good/bad this will look.
Note 2: I've derived LowerVectorsOptions from VectorTransformsOptions because LowerVectorsOp needs to cover a couple more options. We could avoid introducing this new structure and stick to VectorTransformsOptions but we would have to pass the missing two booleans, i.e., it felt half way done.

Diff Detail

Event Timeline

qcolombet created this revision.Jan 17 2023, 5:20 AM
Herald added a project: Restricted Project. · View Herald Transcript
qcolombet requested review of this revision.Jan 17 2023, 5:20 AM
This revision is now accepted and ready to land.Jan 17 2023, 5:23 AM
qcolombet updated this revision to Diff 489782.Jan 17 2023, 5:36 AM
  • Make sure to match the default values of LowerVectorsOp with what is set in the td file (thanks @nicolasvasilache for noticing)
nicolasvasilache accepted this revision.Jan 17 2023, 5:58 AM
qcolombet updated this revision to Diff 490405.Jan 19 2023, 1:17 AM

Overload the set method for the base options of VectorTransformsOptions to return a LowerVectorsOptions type.

This allows to mix VectorTransformsOptions and LowerVectorsOptions on the same statement. Without this, the base setXXXOpt would return a VectorTransformsOptions and we couldn't chain the newer setYYYOpt.

qcolombet added inline comments.Jan 19 2023, 1:18 AM
mlir/include/mlir/Dialect/Vector/TransformOps/VectorTransformOps.h
70

That all block may be overkill but is convenient in practice.

nicolasvasilache accepted this revision.Jan 19 2023, 1:21 AM
This revision was automatically updated to reflect the committed changes.