Skip to content

Commit 27c634a

Browse files
[mlir][Linalg] Retire LinalgStrategyPeelPass and filter-based pattern.
Context: https://discourse.llvm.org/t/psa-retire-linalg-filter-based-patterns/63785 Differential Revision: https://reviews.llvm.org/D135200
1 parent ac06f71 commit 27c634a

File tree

6 files changed

+0
-171
lines changed

6 files changed

+0
-171
lines changed

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

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

106-
/// Create a LinalgStrategyPeelPass.
107-
std::unique_ptr<OperationPass<func::FuncOp>> createLinalgStrategyPeelPass(
108-
StringRef opName = "",
109-
const linalg::LinalgPeelOptions &opt = linalg::LinalgPeelOptions(),
110-
const linalg::LinalgTransformationFilter &filter =
111-
linalg::LinalgTransformationFilter());
112-
113106
/// Create a LinalgStrategyLowerVectorsPass.
114107
std::unique_ptr<OperationPass<func::FuncOp>>
115108
createLinalgStrategyLowerVectorsPass(

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

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

215-
def LinalgStrategyPeelPass
216-
: Pass<"linalg-strategy-peel-pass", "func::FuncOp"> {
217-
let summary = "Configurable pass to apply pattern-based linalg peeling.";
218-
let constructor = "mlir::createLinalgStrategyPeelPass()";
219-
let dependentDialects = [
220-
"linalg::LinalgDialect",
221-
"scf::SCFDialect"
222-
];
223-
let options = [
224-
Option<"anchorFuncName", "anchor-func", "std::string", /*default=*/"",
225-
"Which func op is the anchor to latch on.">,
226-
Option<"anchorOpName", "anchor-op", "std::string", /*default=*/"",
227-
"Which linalg op within the func is the anchor to latch on.">,
228-
];
229-
}
230-
231215
def LinalgStrategyLowerVectorsPass
232216
: Pass<"linalg-strategy-lower-vectors-pass", "func::FuncOp"> {
233217
let summary = "Configurable pass to lower vector operations.";

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

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

95-
/// Represent one application of createLinalgStrategyPeelPass.
96-
struct Peel : public Transformation {
97-
explicit Peel(linalg::LinalgPeelOptions options,
98-
LinalgTransformationFilter::FilterFunction f = nullptr)
99-
: Transformation(std::move(f)), options(options) {}
100-
101-
Peel(StringRef name, linalg::LinalgPeelOptions options,
102-
LinalgTransformationFilter::FilterFunction f = nullptr)
103-
: Transformation(std::move(f)), opName(name), options(options) {}
104-
105-
void addToPassPipeline(OpPassManager &pm,
106-
LinalgTransformationFilter m) const override {
107-
pm.addPass(createLinalgStrategyPeelPass(opName, options, m));
108-
}
109-
110-
private:
111-
std::string opName;
112-
linalg::LinalgPeelOptions options;
113-
};
114-
11595
/// Represent one application of createLinalgStrategyLowerVectorsPass.
11696
struct VectorLowering : public Transformation {
11797
explicit VectorLowering(
@@ -189,20 +169,6 @@ struct CodegenStrategy {
189169
decomposeIf(bool b, LinalgTransformationFilter::FilterFunction f = nullptr) {
190170
return b ? decompose(std::move(f)) : *this;
191171
}
192-
/// Append a pattern to peel 'LinalgOpType'.
193-
CodegenStrategy &
194-
peel(StringRef opName, const LinalgPeelOptions &options,
195-
const LinalgTransformationFilter::FilterFunction &f = nullptr) {
196-
transformationSequence.emplace_back(
197-
std::make_unique<Peel>(opName, options, f));
198-
return *this;
199-
}
200-
/// Conditionally append a pattern to peel 'LinalgOpType'.
201-
CodegenStrategy &
202-
peelIf(bool b, StringRef opName, const LinalgPeelOptions &options,
203-
LinalgTransformationFilter::FilterFunction f = nullptr) {
204-
return b ? peel(opName, options, std::move(f)) : *this;
205-
}
206172
/// Append a pattern to lower all vector operations.
207173
CodegenStrategy &vectorLowering(LinalgVectorLoweringOptions options) {
208174
transformationSequence.emplace_back(

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

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -881,49 +881,6 @@ struct LinalgGeneralizationPattern
881881
LinalgTransformationFilter filter;
882882
};
883883

884-
///
885-
/// Linalg peeling patterns.
886-
///
887-
888-
/// Compute the loops to peel and return them in a SmallVector. Loops will be
889-
/// peeled in order of appearance in the SmallVector. This order will impact the
890-
/// output IR. If an inner-to-outer order is provided, the peeled iterations of
891-
/// the outer loops will also contain the peeled inner loops. If an
892-
/// outer-to-inner order is provided, the peeled iterations of the outer loops
893-
/// will not contain any peeled inner loops.
894-
using LoopsToPeelComputationFunction = std::function<void(
895-
OpBuilder &, Operation *, SmallVectorImpl<scf::ForOp> &)>;
896-
897-
struct LinalgPeelOptions {
898-
LoopsToPeelComputationFunction loopsToPeelComputationFunction = nullptr;
899-
};
900-
901-
/// `filter` controls LinalgTransformMarker matching and update when specified.
902-
struct LinalgPeelingPattern : public OpInterfaceRewritePattern<LinalgOp> {
903-
/// Construct a generic pattern applied to all LinalgOp that verify `filter`.
904-
LinalgPeelingPattern(
905-
MLIRContext *context,
906-
LinalgTransformationFilter f = LinalgTransformationFilter(),
907-
LinalgPeelOptions options = LinalgPeelOptions(),
908-
PatternBenefit benefit = 1);
909-
910-
/// Construct a pattern specifically applied to `opName`.
911-
LinalgPeelingPattern(
912-
StringRef opName, MLIRContext *context,
913-
LinalgPeelOptions options = LinalgPeelOptions(),
914-
LinalgTransformationFilter f = LinalgTransformationFilter(),
915-
PatternBenefit benefit = 1);
916-
917-
LogicalResult matchAndRewrite(LinalgOp linalgOp,
918-
PatternRewriter &rewriter) const override;
919-
920-
private:
921-
/// LinalgTransformMarker handles special attribute manipulations.
922-
const LinalgTransformationFilter filter;
923-
/// Peeling options.
924-
const LinalgPeelOptions options;
925-
};
926-
927884
///
928885
/// Linalg vectorization patterns.
929886
///

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

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

183-
/// Configurable pass to apply pattern-based linalg peeling.
184-
struct LinalgStrategyPeelPass
185-
: public impl::LinalgStrategyPeelPassBase<LinalgStrategyPeelPass> {
186-
187-
LinalgStrategyPeelPass() = default;
188-
189-
LinalgStrategyPeelPass(StringRef opName, LinalgPeelOptions opt,
190-
LinalgTransformationFilter filt)
191-
: options(std::move(opt)), filter(std::move(filt)) {
192-
this->anchorOpName.setValue(opName.str());
193-
}
194-
195-
void runOnOperation() override {
196-
auto funcOp = getOperation();
197-
if (!anchorFuncName.empty() && funcOp.getName() != anchorFuncName)
198-
return;
199-
200-
RewritePatternSet peelingPatterns(funcOp.getContext());
201-
if (!anchorOpName.empty()) {
202-
peelingPatterns.add<LinalgPeelingPattern>(
203-
anchorOpName, funcOp.getContext(), options, filter);
204-
} else {
205-
peelingPatterns.add<LinalgPeelingPattern>(funcOp.getContext(), filter,
206-
options);
207-
}
208-
if (failed(
209-
applyPatternsAndFoldGreedily(funcOp, std::move(peelingPatterns))))
210-
return signalPassFailure();
211-
}
212-
213-
LinalgPeelOptions options;
214-
LinalgTransformationFilter filter;
215-
};
216-
217183
/// Configurable pass to lower vector operations.
218184
struct LinalgStrategyLowerVectorsPass
219185
: public impl::LinalgStrategyLowerVectorsPassBase<
@@ -328,14 +294,6 @@ mlir::createLinalgStrategyDecomposePass(
328294
return std::make_unique<LinalgStrategyDecomposePass>(filter);
329295
}
330296

331-
/// Create a LinalgStrategyPeelPass.
332-
std::unique_ptr<OperationPass<func::FuncOp>>
333-
mlir::createLinalgStrategyPeelPass(StringRef opName,
334-
const LinalgPeelOptions &opt,
335-
const LinalgTransformationFilter &filter) {
336-
return std::make_unique<LinalgStrategyPeelPass>(opName, opt, filter);
337-
}
338-
339297
/// Create a LinalgStrategyLowerVectorsPass.
340298
std::unique_ptr<OperationPass<func::FuncOp>>
341299
mlir::createLinalgStrategyLowerVectorsPass(

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

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -561,35 +561,6 @@ mlir::linalg::LinalgGeneralizationPattern::returningMatchAndRewrite(
561561
return genericOp;
562562
}
563563

564-
mlir::linalg::LinalgPeelingPattern::LinalgPeelingPattern(
565-
MLIRContext *context, LinalgTransformationFilter f,
566-
LinalgPeelOptions options, PatternBenefit benefit)
567-
: OpInterfaceRewritePattern<LinalgOp>(context, benefit),
568-
filter(std::move(f)), options(std::move(options)) {}
569-
570-
mlir::linalg::LinalgPeelingPattern::LinalgPeelingPattern(
571-
StringRef opName, MLIRContext *context, LinalgPeelOptions options,
572-
LinalgTransformationFilter f, PatternBenefit benefit)
573-
: OpInterfaceRewritePattern<LinalgOp>(context, benefit),
574-
filter(f.addOpNameFilter(opName)), options(std::move(options)) {}
575-
576-
LogicalResult mlir::linalg::LinalgPeelingPattern::matchAndRewrite(
577-
LinalgOp linalgOp, PatternRewriter &rewriter) const {
578-
if (failed(filter.checkAndNotify(rewriter, linalgOp)))
579-
return failure();
580-
581-
// Increase marker counter even if peeling doesn't happen for this op.
582-
filter.replaceLinalgTransformationFilter(rewriter, linalgOp);
583-
584-
if (!options.loopsToPeelComputationFunction)
585-
return failure();
586-
587-
SmallVector<scf::ForOp, 4> loopsToPeel;
588-
options.loopsToPeelComputationFunction(rewriter, linalgOp, loopsToPeel);
589-
peelLoops(rewriter, loopsToPeel);
590-
return success();
591-
}
592-
593564
LogicalResult mlir::linalg::CopyVectorizationPattern::matchAndRewrite(
594565
memref::CopyOp copyOp, PatternRewriter &rewriter) const {
595566
return vectorizeCopy(rewriter, copyOp);

0 commit comments

Comments
 (0)