Skip to content

Commit 05fa8e8

Browse files
[mlir][Linalg] Retire LinalgStrategyLowerVectorsPass and filter-based patterns
Context: https://discourse.llvm.org/t/psa-retire-linalg-filter-based-patterns/63785 Depends on D135200 Differential Revision: https://reviews.llvm.org/D135222
1 parent 93b1256 commit 05fa8e8

File tree

6 files changed

+21
-223
lines changed

6 files changed

+21
-223
lines changed

mlir/include/mlir/Dialect/Linalg/Passes.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,6 @@ std::unique_ptr<OperationPass<func::FuncOp>> createLinalgStrategyDecomposePass(
103103
const linalg::LinalgTransformationFilter &filter =
104104
linalg::LinalgTransformationFilter());
105105

106-
/// Create a LinalgStrategyLowerVectorsPass.
107-
std::unique_ptr<OperationPass<func::FuncOp>>
108-
createLinalgStrategyLowerVectorsPass(
109-
linalg::LinalgVectorLoweringOptions opt =
110-
linalg::LinalgVectorLoweringOptions(),
111-
const linalg::LinalgTransformationFilter &filter =
112-
linalg::LinalgTransformationFilter());
113-
114106
/// Create a LinalgStrategyRemoveMarkersPass.
115107
std::unique_ptr<OperationPass<func::FuncOp>>
116108
createLinalgStrategyRemoveMarkersPass();

mlir/include/mlir/Dialect/Linalg/Passes.td

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -212,17 +212,6 @@ def LinalgStrategyDecomposePass
212212
];
213213
}
214214

215-
def LinalgStrategyLowerVectorsPass
216-
: Pass<"linalg-strategy-lower-vectors-pass", "func::FuncOp"> {
217-
let summary = "Configurable pass to lower vector operations.";
218-
let constructor = "mlir::createLinalgStrategyLowerVectorsPass()";
219-
let dependentDialects = ["linalg::LinalgDialect"];
220-
let options = [
221-
Option<"anchorFuncName", "anchor-func", "std::string", /*default=*/"",
222-
"Which func op is the anchor to latch on.">,
223-
];
224-
}
225-
226215
def LinalgStrategyRemoveMarkersPass
227216
: Pass<"linalg-strategy-remove-markers-pass", "func::FuncOp"> {
228217
let summary = "Cleanup pass that drops markers.";

mlir/include/mlir/Dialect/Linalg/Transforms/CodegenStrategy.h

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -92,22 +92,6 @@ struct Decompose : public Transformation {
9292
}
9393
};
9494

95-
/// Represent one application of createLinalgStrategyLowerVectorsPass.
96-
struct VectorLowering : public Transformation {
97-
explicit VectorLowering(
98-
linalg::LinalgVectorLoweringOptions options,
99-
LinalgTransformationFilter::FilterFunction f = nullptr)
100-
: Transformation(std::move(f)), options(options) {}
101-
102-
void addToPassPipeline(OpPassManager &pm,
103-
LinalgTransformationFilter m) const override {
104-
pm.addPass(createLinalgStrategyLowerVectorsPass(options, m));
105-
}
106-
107-
private:
108-
linalg::LinalgVectorLoweringOptions options;
109-
};
110-
11195
/// Codegen strategy controls how a Linalg op is progressively lowered.
11296
struct CodegenStrategy {
11397
/// Append a pattern to tile the Op `opName` and fuse its producers with
@@ -169,12 +153,6 @@ struct CodegenStrategy {
169153
decomposeIf(bool b, LinalgTransformationFilter::FilterFunction f = nullptr) {
170154
return b ? decompose(std::move(f)) : *this;
171155
}
172-
/// Append a pattern to lower all vector operations.
173-
CodegenStrategy &vectorLowering(LinalgVectorLoweringOptions options) {
174-
transformationSequence.emplace_back(
175-
std::make_unique<VectorLowering>(options));
176-
return *this;
177-
}
178156
/// Configure the post staged-patterns global enabling passes options.
179157
CodegenStrategy &
180158
setVectorTransferToSCFOptions(LinalgEnablingOptions options) {

mlir/include/mlir/Dialect/Linalg/Transforms/Transforms.h

Lines changed: 0 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -927,96 +927,6 @@ struct LinalgEnablingOptions {
927927
}
928928
};
929929

930-
/// Vector lowering options control how ops are lowered down to 1-D and scf.for
931-
/// form.
932-
struct LinalgVectorLoweringOptions {
933-
/// Enable lowering of vector.contract.
934-
/// In a progressive lowering of vectors, this would be the 1st step.
935-
bool contractionLowering = false;
936-
LinalgVectorLoweringOptions &enableContractionLowering(bool val = true) {
937-
contractionLowering = val;
938-
return *this;
939-
}
940-
/// Enable lowering of vector.multi_reduce.
941-
/// In a progressive lowering of vectors, this would be the 2nd step.
942-
bool multiReductionLowering = false;
943-
LinalgVectorLoweringOptions &enableMultiReductionLowering(bool val = true) {
944-
multiReductionLowering = val;
945-
return *this;
946-
}
947-
/// Trigger full / partial vector.transfer splits.
948-
/// In a progressive lowering of vectors, this would be the 3rd step.
949-
bool transferPartialRewrite = false;
950-
LinalgVectorLoweringOptions &enableTransferPartialRewrite(bool val = true) {
951-
transferPartialRewrite = val;
952-
return *this;
953-
}
954-
/// Enable lowering of vector.transfer to scf.
955-
/// In a progressive lowering of vectors, this would be the 4th step.
956-
bool transferToSCFConversion = false;
957-
LinalgVectorLoweringOptions &enableTransferToSCFConversion(bool val = true) {
958-
transferToSCFConversion = val;
959-
return *this;
960-
}
961-
/// Maximal transfer rank under which we do not lower further.
962-
int64_t maxTransferRank = 1;
963-
LinalgVectorLoweringOptions &setMaxTransferRank(int64_t val) {
964-
maxTransferRank = val;
965-
return *this;
966-
}
967-
/// Vector lowering operations may result in surprising behavior when
968-
/// composing multiple codegen strategies and must be enabled explicitly.
969-
/// In a progressive lowering of vectors, this would be the 5th step.
970-
bool transferLowering = true;
971-
LinalgVectorLoweringOptions &enableTransferLowering(bool val = true) {
972-
transferLowering = val;
973-
return *this;
974-
}
975-
/// Enable lowering of vector.shape_cast to insert/extract.
976-
/// In a progressive lowering of vectors, this would be the 6th step.
977-
bool shapeCastLowering = true;
978-
LinalgVectorLoweringOptions &enableShapeCastLowering(bool val = true) {
979-
shapeCastLowering = val;
980-
return *this;
981-
}
982-
/// Enable lowering of vector.transpose.
983-
/// In a progressive lowering of vectors, this would be the 7th step.
984-
bool transposeLowering = false;
985-
LinalgVectorLoweringOptions &enableVectorTransposeLowering(bool val = true) {
986-
transposeLowering = val;
987-
return *this;
988-
}
989-
/// Enable AVX2-specific lowerings.
990-
bool avx2Lowering = false;
991-
LinalgVectorLoweringOptions &enableAVX2Lowering(bool val = true) {
992-
avx2Lowering = val;
993-
return *this;
994-
}
995-
996-
/// Configure the post staged-patterns late vector.transfer to scf
997-
/// conversion.
998-
VectorTransferToSCFOptions vectorTransferToSCFOptions;
999-
LinalgVectorLoweringOptions &
1000-
setVectorTransferToSCFOptions(VectorTransferToSCFOptions options) {
1001-
vectorTransferToSCFOptions = options;
1002-
return *this;
1003-
}
1004-
/// Configure late vector transformations.
1005-
vector::VectorTransformsOptions vectorTransformOptions;
1006-
LinalgVectorLoweringOptions &
1007-
setVectorTransformsOptions(vector::VectorTransformsOptions options) {
1008-
vectorTransformOptions = options;
1009-
return *this;
1010-
}
1011-
/// Configure specialized vector lowerings.
1012-
x86vector::avx2::LoweringOptions avx2LoweringOptions;
1013-
LinalgVectorLoweringOptions &
1014-
setAVX2LoweringOptions(x86vector::avx2::LoweringOptions options) {
1015-
avx2LoweringOptions = options;
1016-
return *this;
1017-
}
1018-
};
1019-
1020930
//===----------------------------------------------------------------------===//
1021931
// Transformations exposed as rewrite patterns.
1022932
//===----------------------------------------------------------------------===//

mlir/lib/Dialect/Linalg/Transforms/LinalgStrategyPasses.cpp

Lines changed: 0 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -180,71 +180,6 @@ struct LinalgStrategyDecomposePass
180180
LinalgTransformationFilter filter;
181181
};
182182

183-
/// Configurable pass to lower vector operations.
184-
struct LinalgStrategyLowerVectorsPass
185-
: public impl::LinalgStrategyLowerVectorsPassBase<
186-
LinalgStrategyLowerVectorsPass> {
187-
188-
LinalgStrategyLowerVectorsPass(LinalgVectorLoweringOptions opt,
189-
LinalgTransformationFilter filt)
190-
: options(opt), filter(std::move(filt)) {}
191-
192-
void runOnOperation() override {
193-
auto funcOp = getOperation();
194-
if (!anchorFuncName.empty() && funcOp.getName() != anchorFuncName)
195-
return;
196-
197-
MLIRContext *context = funcOp.getContext();
198-
RewritePatternSet patterns(context);
199-
vector::populateVectorToVectorCanonicalizationPatterns(patterns);
200-
// In a progressive lowering of vectors, this would be the 1st step.
201-
if (options.contractionLowering) {
202-
patterns.add<ContractionOpToOuterProductOpLowering,
203-
ContractionOpToMatmulOpLowering, ContractionOpLowering>(
204-
options.vectorTransformOptions, context);
205-
vector::populateVectorTransferPermutationMapLoweringPatterns(patterns);
206-
}
207-
// In a progressive lowering of vectors, this would be the 2nd step.
208-
if (options.multiReductionLowering) {
209-
vector::populateVectorMultiReductionLoweringPatterns(
210-
patterns,
211-
options.vectorTransformOptions.vectorMultiReductionLowering);
212-
}
213-
// In a progressive lowering of vectors, this would be the 3rd step.
214-
if (options.transferPartialRewrite) {
215-
patterns.add<vector::VectorTransferFullPartialRewriter>(
216-
context, options.vectorTransformOptions);
217-
}
218-
// In a progressive lowering of vectors, this would be the 4th step.
219-
if (options.transferLowering) {
220-
vector::populateVectorTransferLoweringPatterns(patterns,
221-
options.maxTransferRank);
222-
}
223-
// In a progressive lowering of vectors, this would be the 5th step.
224-
if (options.transferToSCFConversion) {
225-
populateVectorToSCFConversionPatterns(
226-
patterns, options.vectorTransferToSCFOptions.setTargetRank(
227-
options.maxTransferRank));
228-
}
229-
// In a progressive lowering of vectors, this would be the 6th step.
230-
if (options.shapeCastLowering) {
231-
vector::populateVectorShapeCastLoweringPatterns(patterns);
232-
}
233-
// In a progressive lowering of vectors, this would be the 7th step.
234-
if (options.transposeLowering) {
235-
vector::populateVectorTransposeLoweringPatterns(
236-
patterns, options.vectorTransformOptions);
237-
if (options.avx2Lowering)
238-
x86vector::avx2::populateSpecializedTransposeLoweringPatterns(
239-
patterns, options.avx2LoweringOptions, /*benefit=*/10);
240-
}
241-
(void)applyPatternsAndFoldGreedily(funcOp, std::move(patterns));
242-
}
243-
244-
LinalgVectorLoweringOptions options;
245-
LinalgTransformationFilter filter;
246-
};
247-
248183
/// Configurable pass to lower vector operations.
249184
struct LinalgStrategyRemoveMarkersPass
250185
: public impl::LinalgStrategyRemoveMarkersPassBase<
@@ -294,13 +229,6 @@ mlir::createLinalgStrategyDecomposePass(
294229
return std::make_unique<LinalgStrategyDecomposePass>(filter);
295230
}
296231

297-
/// Create a LinalgStrategyLowerVectorsPass.
298-
std::unique_ptr<OperationPass<func::FuncOp>>
299-
mlir::createLinalgStrategyLowerVectorsPass(
300-
LinalgVectorLoweringOptions opt, const LinalgTransformationFilter &filter) {
301-
return std::make_unique<LinalgStrategyLowerVectorsPass>(opt, filter);
302-
}
303-
304232
/// Create a LinalgStrategyRemoveMarkersPass.
305233
std::unique_ptr<OperationPass<func::FuncOp>>
306234
mlir::createLinalgStrategyRemoveMarkersPass() {

mlir/test/lib/Dialect/Vector/TestVectorTransforms.cpp

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -235,39 +235,40 @@ struct TestVectorTransposeLowering
235235
}
236236

237237
void runOnOperation() override {
238-
RewritePatternSet patterns(&getContext());
238+
func::FuncOp funcOp = getOperation();
239+
MLIRContext *context = funcOp.getContext();
240+
RewritePatternSet patterns(context);
239241

240-
// Test on one pattern in isolation.
241-
// Explicitly disable shape_cast lowering.
242-
LinalgVectorLoweringOptions options = LinalgVectorLoweringOptions()
243-
.enableVectorTransposeLowering()
244-
.enableShapeCastLowering(false);
242+
vector::VectorTransformsOptions vectorTransformOptions;
245243
if (lowerToEltwise) {
246-
options = options.setVectorTransformsOptions(
247-
VectorTransformsOptions().setVectorTransposeLowering(
248-
VectorTransposeLowering::EltWise));
244+
vectorTransformOptions =
245+
vectorTransformOptions.setVectorTransposeLowering(
246+
VectorTransposeLowering::EltWise);
249247
}
250248
if (lowerToFlatTranspose) {
251-
options = options.setVectorTransformsOptions(
252-
VectorTransformsOptions().setVectorTransposeLowering(
253-
VectorTransposeLowering::Flat));
249+
vectorTransformOptions =
250+
vectorTransformOptions.setVectorTransposeLowering(
251+
VectorTransposeLowering::Flat);
254252
}
255253
if (lowerToShuffleTranspose) {
256-
options = options.setVectorTransformsOptions(
257-
VectorTransformsOptions().setVectorTransposeLowering(
258-
VectorTransposeLowering::Shuffle));
254+
vectorTransformOptions =
255+
vectorTransformOptions.setVectorTransposeLowering(
256+
VectorTransposeLowering::Shuffle);
259257
}
258+
vector::populateVectorTransposeLoweringPatterns(patterns,
259+
vectorTransformOptions);
260+
260261
if (lowerToAvx2) {
261-
options = options.enableAVX2Lowering().setAVX2LoweringOptions(
262+
auto avx2LoweringOptions =
262263
x86vector::avx2::LoweringOptions().setTransposeOptions(
263264
x86vector::avx2::TransposeLoweringOptions()
264265
.lower4x8xf32()
265-
.lower8x8xf32()));
266+
.lower8x8xf32());
267+
x86vector::avx2::populateSpecializedTransposeLoweringPatterns(
268+
patterns, avx2LoweringOptions, /*benefit=*/10);
266269
}
267270

268-
OpPassManager dynamicPM("func.func");
269-
dynamicPM.addPass(createLinalgStrategyLowerVectorsPass(options));
270-
if (failed(runPipeline(dynamicPM, getOperation())))
271+
if (failed(applyPatternsAndFoldGreedily(funcOp, std::move(patterns))))
271272
return signalPassFailure();
272273
}
273274
};

0 commit comments

Comments
 (0)