MLIR 23.0.0git
VectorTransformOps.cpp
Go to the documentation of this file.
1//===- VectorTransformOps.cpp - Implementation of Vector transform ops ----===//
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
10
22
23using namespace mlir;
24using namespace mlir::vector;
25using namespace mlir::transform;
26
27//===----------------------------------------------------------------------===//
28// Apply...ConversionPatternsOp
29//===----------------------------------------------------------------------===//
30
31void transform::ApplyVectorToLLVMConversionPatternsOp::populatePatterns(
32 TypeConverter &typeConverter, RewritePatternSet &patterns) {
34 static_cast<LLVMTypeConverter &>(typeConverter), patterns,
35 getReassociateFpReductions(), getForce_32bitVectorIndices(),
36 getUseVectorAlignment());
37}
38
39LogicalResult
40transform::ApplyVectorToLLVMConversionPatternsOp::verifyTypeConverter(
41 transform::TypeConverterBuilderOpInterface builder) {
42 if (builder.getTypeConverterType() != "LLVMTypeConverter")
43 return emitOpError("expected LLVMTypeConverter");
44 return success();
45}
46
47//===----------------------------------------------------------------------===//
48// Apply...PatternsOp
49//===----------------------------------------------------------------------===//
50
51void transform::ApplyCastAwayVectorLeadingOneDimPatternsOp::populatePatterns(
53 vector::populateCastAwayVectorLeadingOneDimPatterns(patterns);
54}
55
56void transform::ApplyFoldArithExtensionPatternsOp::populatePatterns(
59}
60
61void transform::ApplyFoldElementwiseToVectorPatternsOp::populatePatterns(
64}
65
66void transform::ApplyVectorReductionToContractPatternsOp::populatePatterns(
69}
70
71void transform::ApplyLowerCreateMaskPatternsOp::populatePatterns(
74}
75
76void transform::ApplyRankReducingSubviewPatternsOp::populatePatterns(
78 vector::populateVectorTransferDropUnitDimsPatterns(patterns);
79}
80
81void transform::ApplyTransferPermutationPatternsOp::populatePatterns(
84}
85
86void transform::ApplyDropUnitDimWithShapeCastPatternsOp::populatePatterns(
88 vector::populateDropUnitDimWithShapeCastPatterns(patterns);
89}
90
91void transform::ApplyDropInnerMostUnitDimsFromXferOpsPatternsOp::
92 populatePatterns(RewritePatternSet &patterns) {
94}
95
96void transform::ApplyLowerBitCastPatternsOp::populatePatterns(
99}
100
101void transform::ApplyLowerBroadcastPatternsOp::populatePatterns(
104}
105
106void transform::ApplyLowerContractionPatternsOp::populatePatterns(
109 /*benefit=*/1,
110 /*disableOuterProductLowering=*/true);
111}
112
113void transform::ApplyLowerMasksPatternsOp::populatePatterns(
116}
117
118void transform::ApplyLowerMaskedTransfersPatternsOp::populatePatterns(
121}
122
123void transform::ApplyMaterializeMasksPatternsOp::populatePatterns(
125 populateVectorMaskMaterializationPatterns(patterns,
126 /*force32BitVectorIndices=*/false);
127}
128
129void transform::ApplyLowerMultiReductionPatternsOp::populatePatterns(
131 vector::VectorTransformsOptions vectorTransformOptions;
132 vectorTransformOptions.setVectorMultiReductionLowering(getLoweringStrategy());
134 patterns, vectorTransformOptions.vectorMultiReductionLowering);
136 patterns, vectorTransformOptions.vectorMultiReductionLowering);
138 patterns, vectorTransformOptions.vectorMultiReductionLowering);
139}
140
141void transform::ApplyLowerOuterProductPatternsOp::populatePatterns(
144}
145
146void transform::ApplyLowerGatherPatternsOp::populatePatterns(
149}
150
151void transform::ApplyUnrollFromElementsPatternsOp::populatePatterns(
153 vector::populateVectorFromElementsUnrollPatterns(patterns);
154}
155
156void transform::ApplyUnrollToElementsPatternsOp::populatePatterns(
158 vector::populateVectorToElementsUnrollPatterns(patterns);
159}
160
161void transform::ApplyLowerScanPatternsOp::populatePatterns(
164}
165
166void transform::ApplyLowerShapeCastPatternsOp::populatePatterns(
169}
170
171void transform::ApplyLowerTransferPatternsOp::populatePatterns(
174 getMaxTransferRank());
175}
176
177void transform::ApplyLowerTransposePatternsOp::populatePatterns(
180 getLoweringStrategy());
181 if (getAvx2LoweringStrategy()) {
182 auto avx2LoweringOptions =
185 .lower4x8xf32(true)
186 .lower8x8xf32(true));
188 patterns, avx2LoweringOptions, /*benefit=*/10);
189 }
190}
191
192void transform::ApplyLowerInterleavePatternsOp::populatePatterns(
195}
196
197void transform::ApplyInterleaveToShufflePatternsOp::populatePatterns(
200}
201
202void transform::ApplyRewriteNarrowTypePatternsOp::populatePatterns(
204 populateVectorNarrowTypeRewritePatterns(patterns);
205 populateVectorTransposeNarrowTypeRewritePatterns(patterns);
206}
207
208void transform::ApplySplitTransferFullPartialPatternsOp::populatePatterns(
210 vector::VectorTransformsOptions vectorTransformOptions;
211 vectorTransformOptions.setVectorTransferSplit(getSplitTransferStrategy());
213}
214
215void transform::ApplyTransferToScfPatternsOp::populatePatterns(
217 VectorTransferToSCFOptions vectorTransferToSCFOptions =
219 .enableFullUnroll(getFullUnroll())
220 .setTargetRank(getMaxTransferRank());
221 populateVectorToSCFConversionPatterns(patterns, vectorTransferToSCFOptions);
222}
223
224void transform::ApplySinkVectorPatternsOp::populatePatterns(
227}
228
229void transform::ApplySinkVectorMemPatternsOp::populatePatterns(
231 vector::populateSinkVectorMemOpsPatterns(patterns);
232}
233
234void transform::ApplyFlattenVectorTransferOpsPatternsOp::populatePatterns(
236 vector::populateFlattenVectorTransferPatterns(patterns,
237 getTargetVectorBitwidth());
238}
239
240//===----------------------------------------------------------------------===//
241// Transform op registration
242//===----------------------------------------------------------------------===//
243
244namespace {
245/// Registers new ops and declares PDL as dependent dialect since the additional
246/// ops are using PDL types for operands and results.
247class VectorTransformDialectExtension
249 VectorTransformDialectExtension> {
250public:
251 MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(VectorTransformDialectExtension)
252
253 VectorTransformDialectExtension() {
254 declareGeneratedDialect<vector::VectorDialect>();
255 declareGeneratedDialect<LLVM::LLVMDialect>();
256 registerTransformOps<
257#define GET_OP_LIST
258#include "mlir/Dialect/Vector/TransformOps/VectorTransformOps.cpp.inc"
259 >();
260 }
261};
262} // namespace
263
264#define GET_OP_CLASSES
265#include "mlir/Dialect/Vector/TransformOps/VectorTransformOps.cpp.inc"
266
268 DialectRegistry &registry) {
269 registry.addExtensions<VectorTransformDialectExtension>();
270}
return success()
p<< " : "<< getMemRefType()<< ", "<< getType();}static LogicalResult verifyVectorMemoryOp(Operation *op, MemRefType memrefType, VectorType vectorType) { if(memrefType.getElementType() !=vectorType.getElementType()) return op-> emitOpError("requires memref and vector types of the same elemental type")
Given a list of lists of parsed operands, populates uniqueOperands with unique operands.
#define MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(CLASS_NAME)
Definition TypeID.h:331
The DialectRegistry maps a dialect namespace to a constructor for the matching dialect.
void addExtensions()
Add the given extensions to the registry.
Conversion from types to the LLVM IR dialect.
Base class for extensions of the Transform dialect that supports injecting operations into the Transf...
void populateVectorTransferPermutationMapLoweringPatterns(RewritePatternSet &patterns, PatternBenefit benefit=1)
Collect a set of transfer read/write lowering patterns that simplify the permutation map (e....
void populateElementwiseToVectorOpsPatterns(RewritePatternSet &patterns)
Collect a set of patterns that fold elementwise op on vectors to the vector dialect.
void populateVectorInterleaveToShufflePatterns(RewritePatternSet &patterns, PatternBenefit benefit=1)
void populateVectorShapeCastLoweringPatterns(RewritePatternSet &patterns, PatternBenefit benefit=1)
Populate the pattern set with the following patterns:
void populateVectorGatherLoweringPatterns(RewritePatternSet &patterns, PatternBenefit benefit=1)
Populate the pattern set with the following patterns:
void populateVectorTransferLoweringPatterns(RewritePatternSet &patterns, std::optional< unsigned > maxTransferRank=std::nullopt, PatternBenefit benefit=1)
Populate the pattern set with the following patterns:
void populateDropInnerMostUnitDimsXferOpPatterns(RewritePatternSet &patterns, PatternBenefit benefit=1)
Collect a set of patterns to collapse the most inner unit dims in xfer Ops.
void registerTransformDialectExtension(DialectRegistry &registry)
void populateVectorTransposeLoweringPatterns(RewritePatternSet &patterns, VectorTransposeLowering vectorTransposeLowering, PatternBenefit benefit=1)
Populate the pattern set with the following patterns:
void populateFoldArithExtensionPatterns(RewritePatternSet &patterns)
Collect a set of patterns that fold arithmetic extension on floating point into vector contract for t...
void populateSinkVectorOpsPatterns(RewritePatternSet &patterns, PatternBenefit benefit=1)
Patterns that remove redundant Vector Ops by re-ordering them with e.g.
void populateVectorMultiReductionUnrollingPatterns(RewritePatternSet &patterns, VectorMultiReductionLowering options, PatternBenefit benefit=1)
Populate the pattern set with the following patterns:
void populateVectorBroadcastLoweringPatterns(RewritePatternSet &patterns, PatternBenefit benefit=1)
Populate the pattern set with the following patterns:
void populateVectorBitCastLoweringPatterns(RewritePatternSet &patterns, int64_t targetRank=1, PatternBenefit benefit=1)
Populates the pattern set with the following patterns:
void populateVectorMultiReductionFlatteningPatterns(RewritePatternSet &patterns, VectorMultiReductionLowering options, PatternBenefit benefit=1)
Populate the pattern set with the following patterns:
void populateVectorOuterProductLoweringPatterns(RewritePatternSet &patterns, PatternBenefit benefit=1)
Populate the pattern set with the following patterns:
void populateVectorMaskOpLoweringPatterns(RewritePatternSet &patterns, PatternBenefit benefit=1)
Populate the pattern set with the following patterns:
void populateVectorReductionToContractPatterns(RewritePatternSet &patterns, PatternBenefit benefit=1)
Collect patterns to convert reduction op to vector.contract and fold transpose/broadcast ops into the...
void populateVectorMultiReductionTransformationPatterns(RewritePatternSet &patterns, VectorMultiReductionLowering options, PatternBenefit benefit=1)
Populate the pattern set with the following patterns:
void populateVectorTransferFullPartialPatterns(RewritePatternSet &patterns, const VectorTransformsOptions &options)
Populate patterns with the following patterns.
void populateVectorMaskLoweringPatternsForSideEffectingOps(RewritePatternSet &patterns)
Populates instances of MaskOpRewritePattern to lower masked operations with vector....
void populateVectorInterleaveLoweringPatterns(RewritePatternSet &patterns, int64_t targetRank=1, PatternBenefit benefit=1)
Populate the pattern set with the following patterns:
void populateVectorContractLoweringPatterns(RewritePatternSet &patterns, VectorContractLowering vectorContractLoweringOption, PatternBenefit benefit=1, bool disableOuterProductLowering=false)
Populate the pattern set with the following patterns:
void populateVectorScanLoweringPatterns(RewritePatternSet &patterns, PatternBenefit benefit=1)
Populate the pattern set with the following patterns:
void populateSpecializedTransposeLoweringPatterns(RewritePatternSet &patterns, LoweringOptions options=LoweringOptions(), int benefit=10)
Insert specialized transpose lowering patterns.
Include the generated interface declarations.
const FrozenRewritePatternSet & patterns
void populateVectorToSCFConversionPatterns(RewritePatternSet &patterns, const VectorTransferToSCFOptions &options=VectorTransferToSCFOptions())
Collect a set of patterns to convert from the Vector dialect to SCF + func.
void populateVectorToLLVMConversionPatterns(const LLVMTypeConverter &converter, RewritePatternSet &patterns, bool reassociateFPReductions=false, bool force32BitVectorIndices=false, bool useVectorAlignment=false)
Collect a set of patterns to convert from the Vector dialect to LLVM.
When lowering an N-d vector transfer op to an (N-1)-d vector transfer op, a temporary buffer is creat...
Definition VectorToSCF.h:52
VectorTransferToSCFOptions & setTargetRank(unsigned r)
Definition VectorToSCF.h:55
VectorTransferToSCFOptions & enableFullUnroll(bool u=true)
Definition VectorToSCF.h:68
Structure to control the behavior of vector transform patterns.
VectorMultiReductionLowering vectorMultiReductionLowering
Option to control the lowering of vector.multi_reduction.
VectorTransformsOptions & setVectorMultiReductionLowering(VectorMultiReductionLowering opt)
VectorTransformsOptions & setVectorTransferSplit(VectorTransferSplit opt)
Options for controlling specialized AVX2 lowerings.
Definition Transforms.h:184
LoweringOptions & setTransposeOptions(TransposeLoweringOptions options)
Definition Transforms.h:187
Structure to control the behavior of specialized AVX2 transpose lowering.
Definition Transforms.h:170