xref: /llvm-project/mlir/include/mlir/Dialect/Vector/TransformOps/VectorTransformOps.td (revision 1f5e8263b920f591c517a5dc562cccad39dd6ec7)
1//===- VectorTransformOps.td - Vector transform ops --------*- tablegen -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef VECTOR_TRANSFORM_OPS
10#define VECTOR_TRANSFORM_OPS
11
12include "mlir/Dialect/Transform/IR/TransformDialect.td"
13include "mlir/Dialect/Transform/Interfaces/TransformInterfaces.td"
14include "mlir/Dialect/Vector/Transforms/VectorTransformsBase.td"
15include "mlir/Interfaces/SideEffectInterfaces.td"
16include "mlir/IR/OpBase.td"
17
18def ApplyVectorToLLVMConversionPatternsOp : Op<Transform_Dialect,
19    "apply_conversion_patterns.vector.vector_to_llvm",
20    [DeclareOpInterfaceMethods<ConversionPatternDescriptorOpInterface,
21                               ["verifyTypeConverter"]>]> {
22  let description = [{
23    Collects patterns that convert vector dialect ops to LLVM dialect ops. These
24    patterns require an "LLVMTypeConverter".
25
26    The patterns can be customized as follows:
27    - `reassociate_fp_reductions`: Allows LLVM to reassociate floating-point
28      reductions for speed.
29    - `force_32bit_vector_indices`: Allows the compiler to assume that vector
30      indices fit in 32-bit if that yields faster code.
31  }];
32
33  let arguments = (ins
34      DefaultValuedAttr<BoolAttr, "false">:$reassociate_fp_reductions,
35      DefaultValuedAttr<BoolAttr, "true">:$force_32bit_vector_indices);
36  let assemblyFormat = "attr-dict";
37}
38
39
40def ApplyCastAwayVectorLeadingOneDimPatternsOp : Op<Transform_Dialect,
41    "apply_patterns.vector.cast_away_vector_leading_one_dim",
42    [DeclareOpInterfaceMethods<PatternDescriptorOpInterface>]> {
43  let description = [{
44    Collect a set of leading one dimension removal patterns.
45
46    These patterns insert vector.shape_cast to remove leading one dimensions
47    to expose more canonical forms of read/write/insert/extract operations.
48    With them, there are more chances that we can cancel out extract-insert
49    pairs or forward write-read pairs.
50  }];
51
52  let assemblyFormat = "attr-dict";
53}
54
55def ApplyRankReducingSubviewPatternsOp : Op<Transform_Dialect,
56    "apply_patterns.vector.rank_reducing_subview_patterns",
57    [DeclareOpInterfaceMethods<PatternDescriptorOpInterface>]> {
58  let description = [{
59    Apply opt-in vector transfer permutation patterns that include:
60      - TransferReadDropUnitDimsPattern
61      - TransferWriteDropUnitDimsPattern
62
63    These patterns have the effect of rewriting a vector.transfer with unit
64    dimensions into a rank-reduced version thanks to subview operations.
65    This is complemented by shape_cast folding patterns.
66  }];
67
68  let assemblyFormat = "attr-dict";
69}
70
71def ApplyDropUnitDimWithShapeCastPatternsOp : Op<Transform_Dialect,
72    "apply_patterns.vector.drop_unit_dims_with_shape_cast",
73    [DeclareOpInterfaceMethods<PatternDescriptorOpInterface>]> {
74  let description = [{
75     Apply vector patterns to fold unit dims with vector.shape_cast Ops:
76      - DropUnitDimFromElementwiseOps
77      - DropUnitDimsFromScfForOp
78      - DropUnitDimsFromTransposeOp
79
80    Excludes patterns for vector.transfer Ops. This is complemented by
81    shape_cast folding patterns.
82  }];
83
84  let assemblyFormat = "attr-dict";
85}
86
87def ApplyTransferPermutationPatternsOp : Op<Transform_Dialect,
88    "apply_patterns.vector.transfer_permutation_patterns",
89    [DeclareOpInterfaceMethods<PatternDescriptorOpInterface>]> {
90  let description = [{
91    Apply opt-in vector transfer permutation patterns that include:
92      - TransferReadPermutationLowering
93      - TransferWritePermutationLowering
94      - TransferOpReduceRank
95      - TransferWriteNonPermutationLowering
96
97    These patterns have the effect of rewriting a vector.transfer with an
98    arbitrary permutation_map to a vector.transfer with a permutation_map that
99    is a minor identity followed by a vector.transpose.
100
101    In other words, this makes the vector.transfer contiguous on the most minor
102    dimensions and materializes the permutation_map as a vector.transpose.
103  }];
104
105  let assemblyFormat = "attr-dict";
106}
107
108def ApplyLowerBitCastPatternsOp : Op<Transform_Dialect,
109    "apply_patterns.vector.lower_bitcast",
110    [DeclareOpInterfaceMethods<PatternDescriptorOpInterface>]> {
111  let description = [{
112    Indicates that vector bitcast operations should be lowered to
113    finer-grained vector primitives.
114
115    This is usally a late step that is run after bufferization as part of the
116    process of lowering to e.g. LLVM or NVVM.
117  }];
118
119  let assemblyFormat = "attr-dict";
120}
121
122def ApplyLowerBroadcastPatternsOp : Op<Transform_Dialect,
123    "apply_patterns.vector.lower_broadcast",
124    [DeclareOpInterfaceMethods<PatternDescriptorOpInterface>]> {
125  let description = [{
126    Indicates that vector broadcast operations should be lowered to
127    finer-grained vector primitives.
128
129    This is usally a late step that is run after bufferization as part of the
130    process of lowering to e.g. LLVM or NVVM.
131  }];
132
133  let assemblyFormat = "attr-dict";
134}
135
136def ApplyLowerContractionPatternsOp : Op<Transform_Dialect,
137    "apply_patterns.vector.lower_contraction",
138    [DeclareOpInterfaceMethods<PatternDescriptorOpInterface>]> {
139  let description = [{
140    Indicates that vector contraction-like operations should be lowered to
141    finer-grained vector primitives.
142
143    This is usually a late step that is run after bufferization as part of the
144    process of lowering to e.g. LLVM or NVVM.
145  }];
146
147  let arguments = (ins DefaultValuedAttr<VectorContractLoweringAttr,
148      "vector::VectorContractLowering::OuterProduct">:$lowering_strategy
149  );
150  let assemblyFormat = [{
151    (`lowering_strategy` `=` $lowering_strategy^)? attr-dict
152  }];
153}
154
155def ApplyLowerCreateMaskPatternsOp : Op<Transform_Dialect,
156    "apply_patterns.vector.lower_create_mask",
157    [DeclareOpInterfaceMethods<PatternDescriptorOpInterface>]> {
158  let description = [{
159    Indicates that vector create_mask-like operations should be lowered to
160    finer-grained vector primitives.
161  }];
162
163  let assemblyFormat = "attr-dict";
164}
165
166def ApplyLowerMasksPatternsOp : Op<Transform_Dialect,
167    "apply_patterns.vector.lower_masks",
168    [DeclareOpInterfaceMethods<PatternDescriptorOpInterface>]> {
169  let description = [{
170    Indicates that vector.create_mask and vector.constant_mask operations
171    should be lowered to finer-grained vector primitives.
172
173    This is usually a late step that is run after bufferization as part of the
174    process of lowering to e.g. LLVM or NVVM.
175  }];
176
177  let assemblyFormat = "attr-dict";
178}
179
180def ApplyLowerMaskedTransfersPatternsOp : Op<Transform_Dialect,
181    "apply_patterns.vector.lower_masked_transfers",
182    [DeclareOpInterfaceMethods<PatternDescriptorOpInterface>]> {
183  let description = [{
184    Apply opt-in patterns that lower vector.mask operations surrounding
185    side-effecting ops:
186      - MaskedTransferReadOpPattern
187      - MaskedTransferWriteOpPattern
188      - MaskedGatherOpPattern
189
190    This is usually a late step that is run after bufferization as part of the
191    process of lowering to e.g. LLVM or NVVM.
192  }];
193
194  let assemblyFormat = "attr-dict";
195}
196
197def ApplyMaterializeMasksPatternsOp : Op<Transform_Dialect,
198    "apply_patterns.vector.materialize_masks",
199    [DeclareOpInterfaceMethods<PatternDescriptorOpInterface>]> {
200  let description = [{
201    Indicates that mask operations should be lowered to fine-grained arithemtic
202    operations.
203
204    This is usually the last step that is run after bufferization as part of the
205    process of lowering to e.g. LLVM or NVVM.
206  }];
207
208  let assemblyFormat = "attr-dict";
209}
210
211def ApplyLowerMultiReductionPatternsOp : Op<Transform_Dialect,
212    "apply_patterns.vector.lower_multi_reduction",
213    [DeclareOpInterfaceMethods<PatternDescriptorOpInterface>]> {
214  let description = [{
215    Indicates that vector multi_reduction-like operations should be lowered to
216    finer-grained vector primitives.
217
218    This is usually a late step that is run after bufferization as part of the
219    process of lowering to e.g. LLVM or NVVM.
220  }];
221
222  let arguments = (ins DefaultValuedAttr<VectorMultiReductionLoweringAttr,
223      "vector::VectorMultiReductionLowering::InnerParallel">:$lowering_strategy
224  );
225
226  let assemblyFormat = [{
227    (`lowering_strategy` `=` $lowering_strategy^)? attr-dict
228  }];
229}
230
231def ApplyLowerOuterProductPatternsOp : Op<Transform_Dialect,
232    "apply_patterns.vector.lower_outerproduct",
233    [DeclareOpInterfaceMethods<PatternDescriptorOpInterface>]> {
234  let description = [{
235    Indicates that the vector outerproduct operations should be lowered to
236    finer-grained vector primitives.
237
238    This is usually a late step that is run after bufferization as part of the
239    process of lowering to e.g. LLVM or NVVM.
240  }];
241
242  let assemblyFormat = "attr-dict";
243}
244
245def ApplyLowerGatherPatternsOp : Op<Transform_Dialect,
246    "apply_patterns.vector.lower_gather",
247    [DeclareOpInterfaceMethods<PatternDescriptorOpInterface>]> {
248  let description = [{
249    Indicates that vector.gather operations should be lowered to
250    finer-grained vector primitives.
251  }];
252
253  let assemblyFormat = "attr-dict";
254}
255
256def ApplyLowerScanPatternsOp : Op<Transform_Dialect,
257    "apply_patterns.vector.lower_scan",
258    [DeclareOpInterfaceMethods<PatternDescriptorOpInterface>]> {
259  let description = [{
260    Indicates that vector.scan operations should be lowered to
261    finer-grained vector primitives.
262  }];
263
264  let assemblyFormat = "attr-dict";
265}
266
267def ApplyLowerShapeCastPatternsOp : Op<Transform_Dialect,
268    "apply_patterns.vector.lower_shape_cast",
269    [DeclareOpInterfaceMethods<PatternDescriptorOpInterface>]> {
270  let description = [{
271    Indicates that vector shape_cast operations should be lowered to
272    finer-grained vector primitives.
273
274    This is usually a late step that is run after bufferization as part of the
275    process of lowering to e.g. LLVM or NVVM.
276  }];
277
278  let assemblyFormat = "attr-dict";
279}
280
281def ApplyLowerTransferPatternsOp : Op<Transform_Dialect,
282    "apply_patterns.vector.lower_transfer",
283    [DeclareOpInterfaceMethods<PatternDescriptorOpInterface>]> {
284  let description = [{
285    Indicates that vector transfer operations should be lowered to finer-grained
286    vector primitives.
287
288    This is usually a late step that is run after bufferization as part of the
289    process of lowering to e.g. LLVM or NVVM.
290  }];
291
292  let arguments = (ins DefaultValuedAttr<I64Attr, "1">:$max_transfer_rank);
293
294  let assemblyFormat = [{
295    (`max_transfer_rank` `=` $max_transfer_rank^)? attr-dict
296  }];
297}
298
299def ApplyLowerTransposePatternsOp : Op<Transform_Dialect,
300    "apply_patterns.vector.lower_transpose",
301    [DeclareOpInterfaceMethods<PatternDescriptorOpInterface>]> {
302  let description = [{
303    Indicates that vector transpose-like operations should be lowered to
304    finer-grained vector primitives.
305
306    This is usually a late step that is run after bufferization as part of the
307    process of lowering to e.g. LLVM or NVVM.
308  }];
309
310  let arguments = (ins
311     DefaultValuedAttr<VectorTransposeLoweringAttr,
312       "vector::VectorTransposeLowering::EltWise">:$lowering_strategy,
313     DefaultValuedAttr<BoolAttr, "false">:$avx2_lowering_strategy
314  );
315
316  let assemblyFormat = [{
317    oilist (
318      `lowering_strategy` `=` $lowering_strategy
319      | `avx2_lowering_strategy` `=` $avx2_lowering_strategy
320    )
321    attr-dict
322  }];
323}
324
325def ApplyLowerInterleavePatternsOp : Op<Transform_Dialect,
326    "apply_patterns.vector.lower_interleave",
327    [DeclareOpInterfaceMethods<PatternDescriptorOpInterface>]> {
328  let description = [{
329    Indicates that vector interleave operations should be lowered to
330    finer-grained vector primitives.
331
332    This is usally a late step that is run after bufferization as part of the
333    process of lowering to e.g. LLVM or NVVM.
334  }];
335
336  let assemblyFormat = "attr-dict";
337}
338
339def ApplyInterleaveToShufflePatternsOp : Op<Transform_Dialect,
340    "apply_patterns.vector.interleave_to_shuffle",
341    [DeclareOpInterfaceMethods<PatternDescriptorOpInterface>]> {
342  let description = [{
343    Indicates that 1D vector interleave operations should be rewritten as
344    vector shuffle operations.
345
346    This is motivated by some current codegen backends not handling vector
347    interleave operations.
348  }];
349
350  let assemblyFormat = "attr-dict";
351}
352
353def ApplyRewriteNarrowTypePatternsOp : Op<Transform_Dialect,
354    "apply_patterns.vector.rewrite_narrow_types",
355    [DeclareOpInterfaceMethods<PatternDescriptorOpInterface>]> {
356  let description = [{
357    Indicates that vector narrow rewrite operations should be applied.
358
359    This is usually a late step that is run after bufferization as part of the
360    process of lowering to e.g. LLVM or NVVM.
361
362    Warning: these patterns currently only work for little endian targets.
363  }];
364
365  let assemblyFormat = "attr-dict";
366}
367
368def ApplySplitTransferFullPartialPatternsOp : Op<Transform_Dialect,
369    "apply_patterns.vector.split_transfer_full_partial",
370    [DeclareOpInterfaceMethods<PatternDescriptorOpInterface>]> {
371  let description = [{
372    Indicates that vector transfer operations should be split to full and
373    partial parts.
374
375    This is usually a late step that is run after bufferization as part of the
376    process of lowering to e.g. LLVM or NVVM.
377  }];
378
379  let arguments = (ins
380     DefaultValuedAttr<VectorTransferSplitAttr,
381       "vector::VectorTransferSplit::LinalgCopy">:$split_transfer_strategy
382  );
383
384  let assemblyFormat = [{
385    (`split_transfer_strategy` `=` $split_transfer_strategy^)? attr-dict
386  }];
387}
388
389def ApplyTransferToScfPatternsOp : Op<Transform_Dialect,
390    "apply_patterns.vector.transfer_to_scf",
391    [DeclareOpInterfaceMethods<PatternDescriptorOpInterface>]> {
392  let description = [{
393    Indicates that vector transfer operations should be rewritten with scf.for
394    loops over finer-grained vector primitives.
395
396    This is usually a late step that is run after bufferization as part of the
397    process of lowering to e.g. LLVM or NVVM.
398  }];
399
400  let arguments = (ins
401     DefaultValuedAttr<I64Attr, "1">:$max_transfer_rank,
402     DefaultValuedAttr<BoolAttr, "false">:$full_unroll
403  );
404
405  let assemblyFormat = [{
406    oilist (
407        `max_transfer_rank` `=` $max_transfer_rank
408      | `full_unroll` `=` $full_unroll
409    )
410    attr-dict
411  }];
412}
413
414def ApplyFoldArithExtensionPatternsOp : Op<Transform_Dialect,
415    "apply_patterns.vector.fold_arith_extension",
416    [DeclareOpInterfaceMethods<PatternDescriptorOpInterface>]> {
417  let description = [{
418    Collect a set of patterns that fold arithmetic extension on floating point
419    into vector contract for the backends with native support.
420  }];
421
422  let assemblyFormat = "attr-dict";
423}
424
425def ApplyFoldElementwiseToVectorPatternsOp : Op<Transform_Dialect,
426    "apply_patterns.vector.elementwise_to_vector",
427    [DeclareOpInterfaceMethods<PatternDescriptorOpInterface>]> {
428  let description = [{
429    Collect a set of patterns that fold elementwise op on vectors to the vector
430    dialect.
431  }];
432
433  let assemblyFormat = "attr-dict";
434}
435
436def ApplyVectorReductionToContractPatternsOp : Op<Transform_Dialect,
437    "apply_patterns.vector.reduction_to_contract",
438    [DeclareOpInterfaceMethods<PatternDescriptorOpInterface>]> {
439  let description = [{
440    Apply opt-in patterns that convert reductions to contract:
441      - MultiReduceToContract
442      - CombineContractBroadcast
443      - CombineContractABTranspose
444      - CombineContractResultTranspose
445      - ReorderElementwiseOpsOnTranspose
446      - ReorderElementwiseOpsOnBroadcast
447      - ReorderCastOpsOnBroadcast
448
449    These patterns have the effect of rewriting a vector.multi_reduce into a
450    vector.contract.
451  }];
452
453  let assemblyFormat = "attr-dict";
454}
455
456#endif // VECTOR_TRANSFORM_OPS
457