/// Linalg generalization pattern.
///
/// Apply the `generalization` transformation as a pattern.
-/// `filter` controls LinalgTransformMarker matching and update when specified.
/// See `generalization` for more details.
+//
+// TODO: Automatic default pattern class that just unwraps a function returning
+// FailureOr<GenericOp>.
struct LinalgGeneralizationPattern
: public OpInterfaceRewritePattern<LinalgOp> {
- /// Construct a generic pattern applied to all LinalgOp that verify `filter`.
- LinalgGeneralizationPattern(
- MLIRContext *context,
- LinalgTransformationFilter f = LinalgTransformationFilter(),
- PatternBenefit benefit = 1);
-
- /// Construct a pattern specifically applied to `opName`.
- LinalgGeneralizationPattern(
- StringRef opName, MLIRContext *context,
- LinalgTransformationFilter f = LinalgTransformationFilter(),
- PatternBenefit benefit = 1);
+ using OpInterfaceRewritePattern<LinalgOp>::OpInterfaceRewritePattern;
/// `matchAndRewrite` implementation that returns the significant transformed
/// pieces of IR.
FailureOr<GenericOp>
- returningMatchAndRewrite(LinalgOp op, PatternRewriter &rewriter) const;
+ returningMatchAndRewrite(LinalgOp op, PatternRewriter &rewriter) const {
+ return generalizeNamedOp(rewriter, op);
+ }
LogicalResult matchAndRewrite(LinalgOp op,
PatternRewriter &rewriter) const override {
return returningMatchAndRewrite(op, rewriter);
}
-
-private:
- /// LinalgTransformMarker handles special attribute manipulations.
- LinalgTransformationFilter filter;
};
///
/// Populates `patterns` with patterns to convert spec-generated named ops to
/// linalg.generic ops.
-void populateLinalgNamedOpsGeneralizationPatterns(
- RewritePatternSet &patterns,
- const LinalgTransformationFilter &filter = LinalgTransformationFilter());
+void populateLinalgNamedOpsGeneralizationPatterns(RewritePatternSet &patterns);
/// Linalg decompose convolutions patterns
return paddedOp;
}
-/// Linalg generalization pattern.
-mlir::linalg::LinalgGeneralizationPattern::LinalgGeneralizationPattern(
- MLIRContext *context, LinalgTransformationFilter f, PatternBenefit benefit)
- : OpInterfaceRewritePattern<LinalgOp>(context, benefit),
- filter(std::move(f)) {}
-
-mlir::linalg::LinalgGeneralizationPattern::LinalgGeneralizationPattern(
- StringRef opName, MLIRContext *context, LinalgTransformationFilter f,
- PatternBenefit benefit)
- : OpInterfaceRewritePattern<LinalgOp>(context, benefit),
- filter(f.addOpNameFilter(opName)) {}
-
-FailureOr<GenericOp>
-mlir::linalg::LinalgGeneralizationPattern::returningMatchAndRewrite(
- LinalgOp linalgOp, PatternRewriter &rewriter) const {
- if (failed(filter.checkAndNotify(rewriter, linalgOp)))
- return failure();
- FailureOr<GenericOp> genericOp = generalizeNamedOp(rewriter, linalgOp);
- if (failed(genericOp))
- return failure();
- filter.replaceLinalgTransformationFilter(rewriter, *genericOp);
- return genericOp;
-}
-
LogicalResult mlir::linalg::CopyVectorizationPattern::matchAndRewrite(
memref::CopyOp copyOp, PatternRewriter &rewriter) const {
return vectorizeCopy(rewriter, copyOp);