MLIR  20.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 
24 
25 using namespace mlir;
26 using namespace mlir::vector;
27 using namespace mlir::transform;
28 
29 //===----------------------------------------------------------------------===//
30 // Apply...ConversionPatternsOp
31 //===----------------------------------------------------------------------===//
32 
33 void transform::ApplyVectorToLLVMConversionPatternsOp::populatePatterns(
34  TypeConverter &typeConverter, RewritePatternSet &patterns) {
36  static_cast<LLVMTypeConverter &>(typeConverter), patterns,
37  getReassociateFpReductions(), getForce_32bitVectorIndices());
38 }
39 
40 LogicalResult
41 transform::ApplyVectorToLLVMConversionPatternsOp::verifyTypeConverter(
42  transform::TypeConverterBuilderOpInterface builder) {
43  if (builder.getTypeConverterType() != "LLVMTypeConverter")
44  return emitOpError("expected LLVMTypeConverter");
45  return success();
46 }
47 
48 //===----------------------------------------------------------------------===//
49 // Apply...PatternsOp
50 //===----------------------------------------------------------------------===//
51 
52 void transform::ApplyCastAwayVectorLeadingOneDimPatternsOp::populatePatterns(
53  RewritePatternSet &patterns) {
55 }
56 
57 void transform::ApplyFoldArithExtensionPatternsOp::populatePatterns(
58  RewritePatternSet &patterns) {
60 }
61 
62 void transform::ApplyFoldElementwiseToVectorPatternsOp::populatePatterns(
63  RewritePatternSet &patterns) {
65 }
66 
67 void transform::ApplyVectorReductionToContractPatternsOp::populatePatterns(
68  RewritePatternSet &patterns) {
71 }
72 
73 void transform::ApplyLowerCreateMaskPatternsOp::populatePatterns(
74  RewritePatternSet &patterns) {
76 }
77 
78 void transform::ApplyRankReducingSubviewPatternsOp::populatePatterns(
79  RewritePatternSet &patterns) {
81 }
82 
83 void transform::ApplyTransferPermutationPatternsOp::populatePatterns(
84  RewritePatternSet &patterns) {
86 }
87 
88 void transform::ApplyDropUnitDimWithShapeCastPatternsOp::populatePatterns(
89  RewritePatternSet &patterns) {
91 }
92 
93 void transform::ApplyLowerBitCastPatternsOp::populatePatterns(
94  RewritePatternSet &patterns) {
96 }
97 
98 void transform::ApplyLowerBroadcastPatternsOp::populatePatterns(
99  RewritePatternSet &patterns) {
101 }
102 
103 void transform::ApplyLowerContractionPatternsOp::populatePatterns(
104  RewritePatternSet &patterns) {
105  vector::VectorTransformsOptions vectorTransformOptions;
106  vectorTransformOptions.setVectorTransformsOptions(getLoweringStrategy());
107  populateVectorContractLoweringPatterns(patterns, vectorTransformOptions,
108  /*benefit=*/1,
109  /*disableOuterProductLowering=*/true);
110 }
111 
112 void transform::ApplyLowerMasksPatternsOp::populatePatterns(
113  RewritePatternSet &patterns) {
115 }
116 
117 void transform::ApplyLowerMaskedTransfersPatternsOp::populatePatterns(
118  RewritePatternSet &patterns) {
120 }
121 
122 void transform::ApplyMaterializeMasksPatternsOp::populatePatterns(
123  RewritePatternSet &patterns) {
125  /*force32BitVectorIndices=*/false);
126 }
127 
128 void transform::ApplyLowerMultiReductionPatternsOp::populatePatterns(
129  RewritePatternSet &patterns) {
130  vector::VectorTransformsOptions vectorTransformOptions;
131  vectorTransformOptions.setVectorMultiReductionLowering(getLoweringStrategy());
133  patterns, vectorTransformOptions.vectorMultiReductionLowering);
134 }
135 
136 void transform::ApplyLowerOuterProductPatternsOp::populatePatterns(
137  RewritePatternSet &patterns) {
139 }
140 
141 void transform::ApplyLowerGatherPatternsOp::populatePatterns(
142  RewritePatternSet &patterns) {
144 }
145 
146 void transform::ApplyLowerScanPatternsOp::populatePatterns(
147  RewritePatternSet &patterns) {
149 }
150 
151 void transform::ApplyLowerShapeCastPatternsOp::populatePatterns(
152  RewritePatternSet &patterns) {
154 }
155 
156 void transform::ApplyLowerTransferPatternsOp::populatePatterns(
157  RewritePatternSet &patterns) {
159  getMaxTransferRank());
160 }
161 
162 void transform::ApplyLowerTransposePatternsOp::populatePatterns(
163  RewritePatternSet &patterns) {
165  patterns, vector::VectorTransformsOptions().setVectorTransposeLowering(
166  getLoweringStrategy()));
167  if (getAvx2LoweringStrategy()) {
168  auto avx2LoweringOptions =
171  .lower4x8xf32(true)
172  .lower8x8xf32(true));
174  patterns, avx2LoweringOptions, /*benefit=*/10);
175  }
176 }
177 
178 void transform::ApplyLowerInterleavePatternsOp::populatePatterns(
179  RewritePatternSet &patterns) {
181 }
182 
183 void transform::ApplyInterleaveToShufflePatternsOp::populatePatterns(
184  RewritePatternSet &patterns) {
186 }
187 
188 void transform::ApplyRewriteNarrowTypePatternsOp::populatePatterns(
189  RewritePatternSet &patterns) {
192 }
193 
194 void transform::ApplySplitTransferFullPartialPatternsOp::populatePatterns(
195  RewritePatternSet &patterns) {
196  vector::VectorTransformsOptions vectorTransformOptions;
197  vectorTransformOptions.setVectorTransferSplit(getSplitTransferStrategy());
198  populateVectorTransferFullPartialPatterns(patterns, vectorTransformOptions);
199 }
200 
201 void transform::ApplyTransferToScfPatternsOp::populatePatterns(
202  RewritePatternSet &patterns) {
203  VectorTransferToSCFOptions vectorTransferToSCFOptions =
205  .enableFullUnroll(getFullUnroll())
206  .setTargetRank(getMaxTransferRank());
207  populateVectorToSCFConversionPatterns(patterns, vectorTransferToSCFOptions);
208 }
209 
210 //===----------------------------------------------------------------------===//
211 // Transform op registration
212 //===----------------------------------------------------------------------===//
213 
214 namespace {
215 /// Registers new ops and declares PDL as dependent dialect since the additional
216 /// ops are using PDL types for operands and results.
217 class VectorTransformDialectExtension
219  VectorTransformDialectExtension> {
220 public:
221  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(VectorTransformDialectExtension)
222 
223  VectorTransformDialectExtension() {
224  declareGeneratedDialect<vector::VectorDialect>();
225  declareGeneratedDialect<LLVM::LLVMDialect>();
226  registerTransformOps<
227 #define GET_OP_LIST
228 #include "mlir/Dialect/Vector/TransformOps/VectorTransformOps.cpp.inc"
229  >();
230  }
231 };
232 } // namespace
233 
234 #define GET_OP_CLASSES
235 #include "mlir/Dialect/Vector/TransformOps/VectorTransformOps.cpp.inc"
236 
238  DialectRegistry &registry) {
239  registry.addExtensions<VectorTransformDialectExtension>();
240 }
#define MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(CLASS_NAME)
Definition: TypeID.h:274
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.
Definition: TypeConverter.h:35
Type conversion class.
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 populateDropUnitDimWithShapeCastPatterns(RewritePatternSet &patterns, PatternBenefit benefit=1)
Collect a set of patterns that use vector.shape_cast to help fold unit dims.
void populateVectorNarrowTypeRewritePatterns(RewritePatternSet &patterns, PatternBenefit benefit=1)
Appends patterns for rewriting vector operations over narrow types with ops over wider types.
void populateVectorTransposeLoweringPatterns(RewritePatternSet &patterns, VectorTransformsOptions options, PatternBenefit benefit=1)
Populate the pattern set with the following patterns:
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 populateVectorTransferDropUnitDimsPatterns(RewritePatternSet &patterns, PatternBenefit benefit=1)
Collect a set of one dimension removal patterns.
void registerTransformDialectExtension(DialectRegistry &registry)
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 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 populateVectorMaskMaterializationPatterns(RewritePatternSet &patterns, bool force32BitVectorIndices, PatternBenefit benefit=1)
These patterns materialize masks for various vector ops such as transfers.
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 populateVectorMultiReductionLoweringPatterns(RewritePatternSet &patterns, VectorMultiReductionLowering options, PatternBenefit benefit=1)
Collect a set of patterns to convert vector.multi_reduction op into a sequence of vector....
void populateVectorReductionToContractPatterns(RewritePatternSet &patterns, PatternBenefit benefit=1)
Collect patterns to convert reduction op to vector.contract and fold transpose/broadcast ops into the...
void populateVectorContractLoweringPatterns(RewritePatternSet &patterns, VectorTransformsOptions options, PatternBenefit benefit=1, bool disableOuterProductLowering=false)
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 populateCastAwayVectorLeadingOneDimPatterns(RewritePatternSet &patterns, PatternBenefit benefit=1)
Collect a set of leading one dimension removal patterns.
void populateVectorTransposeNarrowTypeRewritePatterns(RewritePatternSet &patterns, PatternBenefit benefit=1)
Appends patterns for emulating a sub-byte vector transpose.
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.
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)
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 & enableFullUnroll(bool u=true)
Definition: VectorToSCF.h:68
VectorTransferToSCFOptions & setTargetRank(unsigned r)
Definition: VectorToSCF.h:55
Structure to control the behavior of vector transform patterns.
VectorTransformsOptions & setVectorMultiReductionLowering(VectorMultiReductionLowering opt)
VectorMultiReductionLowering vectorMultiReductionLowering
Option to control the lowering of vector.multi_reduction.
VectorTransformsOptions & setVectorTransferSplit(VectorTransferSplit opt)
VectorTransformsOptions & setVectorTransformsOptions(VectorContractLowering opt)
Options for controlling specialized AVX2 lowerings.
Definition: Transforms.h:159
LoweringOptions & setTransposeOptions(TransposeLoweringOptions options)
Definition: Transforms.h:162
Structure to control the behavior of specialized AVX2 transpose lowering.
Definition: Transforms.h:145