[PATCH] D141923: [mlir][vector] Add a custom builder for LowerVectorsOp

Quentin Colombet via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 17 05:20:55 PST 2023


qcolombet created this revision.
qcolombet added reviewers: nicolasvasilache, ftynse, springerm.
qcolombet added a project: MLIR.
Herald added subscribers: Moerafaat, zero9178, bzcheeseman, ThomasRaoux, sdasgup3, wenzhicui, wrengr, jsetoain, cota, teijeong, rdzhabarov, tatianashp, msifontes, jurahul, Kayjukh, grosul1, Joonsoo, liufengdb, aartbik, mgester, arpith-jacob, antiagainst, shauheen, rriddle, mehdi_amini.
Herald added a reviewer: aartbik.
Herald added a project: All.
qcolombet requested review of this revision.
Herald added a subscriber: stephenneuendorffer.
Herald added a reviewer: dcaballe.

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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D141923

Files:
  mlir/include/mlir/Dialect/Vector/TransformOps/VectorTransformOps.h
  mlir/include/mlir/Dialect/Vector/TransformOps/VectorTransformOps.td


Index: mlir/include/mlir/Dialect/Vector/TransformOps/VectorTransformOps.td
===================================================================
--- mlir/include/mlir/Dialect/Vector/TransformOps/VectorTransformOps.td
+++ mlir/include/mlir/Dialect/Vector/TransformOps/VectorTransformOps.td
@@ -46,6 +46,18 @@
   );
   let results = (outs PDL_Operation:$results);
 
+  let builders = [
+    OpBuilder<(ins "Type":$resultType, "Value":$target,
+      "const vector::LowerVectorsOptions &":$options), [{
+        return build($_builder, $_state, resultType, target,
+          options.vectorContractLowering,
+          options.vectorMultiReductionLowering, options.vectorTransferSplit,
+          options.vectorTransposeLowering, options.transposeAVX2Lowering,
+          options.unrollVectorTransfers);
+      }]
+    >
+  ];
+
   let assemblyFormat = [{
     $target
     oilist (
Index: mlir/include/mlir/Dialect/Vector/TransformOps/VectorTransformOps.h
===================================================================
--- mlir/include/mlir/Dialect/Vector/TransformOps/VectorTransformOps.h
+++ mlir/include/mlir/Dialect/Vector/TransformOps/VectorTransformOps.h
@@ -17,6 +17,7 @@
 namespace mlir {
 namespace vector {
 class VectorOp;
+struct LowerVectorsOptions;
 } // namespace vector
 } // namespace mlir
 
@@ -32,6 +33,20 @@
 
 namespace vector {
 void registerTransformDialectExtension(DialectRegistry &registry);
+
+/// Helper structure used to hold the different options of LowerVectorsOp.
+struct LowerVectorsOptions : public VectorTransformsOptions {
+  bool transposeAVX2Lowering = false;
+  LowerVectorsOptions &setTransposeAVX2Lowering(bool opt) {
+    transposeAVX2Lowering = opt;
+    return *this;
+  }
+  bool unrollVectorTransfers = true;
+  LowerVectorsOptions &setUnrollVectorTransfers(bool opt) {
+    unrollVectorTransfers = opt;
+    return *this;
+  }
+};
 } // namespace vector
 } // namespace mlir
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D141923.489762.patch
Type: text/x-patch
Size: 1925 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230117/b54e31df/attachment.bin>


More information about the llvm-commits mailing list