diff --git a/mlir/include/mlir/Dialect/Linalg/Passes.h b/mlir/include/mlir/Dialect/Linalg/Passes.h --- a/mlir/include/mlir/Dialect/Linalg/Passes.h +++ b/mlir/include/mlir/Dialect/Linalg/Passes.h @@ -90,13 +90,6 @@ const linalg::LinalgTransformationFilter &filter = linalg::LinalgTransformationFilter()); -/// Create a LinalgStrategyPadPass. -std::unique_ptr> createLinalgStrategyPadPass( - StringRef opName = "", - const linalg::LinalgPaddingOptions &opt = linalg::LinalgPaddingOptions(), - const linalg::LinalgTransformationFilter &filter = - linalg::LinalgTransformationFilter()); - /// Create a LinalgStrategyRemoveMarkersPass. std::unique_ptr> createLinalgStrategyRemoveMarkersPass(); diff --git a/mlir/include/mlir/Dialect/Linalg/Passes.td b/mlir/include/mlir/Dialect/Linalg/Passes.td --- a/mlir/include/mlir/Dialect/Linalg/Passes.td +++ b/mlir/include/mlir/Dialect/Linalg/Passes.td @@ -187,19 +187,6 @@ ]; } -def LinalgStrategyPadPass - : Pass<"linalg-strategy-pad-pass", "func::FuncOp"> { - let summary = "Configurable pass to apply padding and hoisting."; - let constructor = "mlir::createLinalgStrategyPadPass()"; - let dependentDialects = ["linalg::LinalgDialect"]; - let options = [ - Option<"anchorFuncName", "anchor-func", "std::string", /*default=*/"", - "Which func op is the anchor to latch on.">, - Option<"anchorOpName", "anchor-op", "std::string", /*default=*/"", - "Which linalg op within the func is the anchor to latch on.">, - ]; -} - def LinalgStrategyRemoveMarkersPass : Pass<"linalg-strategy-remove-markers-pass", "func::FuncOp"> { let summary = "Cleanup pass that drops markers."; diff --git a/mlir/include/mlir/Dialect/Linalg/Transforms/CodegenStrategy.h b/mlir/include/mlir/Dialect/Linalg/Transforms/CodegenStrategy.h --- a/mlir/include/mlir/Dialect/Linalg/Transforms/CodegenStrategy.h +++ b/mlir/include/mlir/Dialect/Linalg/Transforms/CodegenStrategy.h @@ -64,23 +64,6 @@ linalg::LinalgTilingOptions options; }; -/// Represent one application of LinalgStrategyPadPass. -struct Pad : public Transformation { - Pad(StringRef name, linalg::LinalgPaddingOptions options, - LinalgTransformationFilter::FilterFunction f = nullptr) - : Transformation(std::move(f)), opName(name), - options(std::move(options)) {} - - void addToPassPipeline(OpPassManager &pm, - LinalgTransformationFilter m) const override { - pm.addPass(createLinalgStrategyPadPass(opName, options, m)); - } - -private: - std::string opName; - linalg::LinalgPaddingOptions options; -}; - /// Codegen strategy controls how a Linalg op is progressively lowered. struct CodegenStrategy { /// Append a pattern to tile the Op `opName` and fuse its producers with @@ -115,22 +98,6 @@ LinalgTransformationFilter::FilterFunction f = nullptr) { return b ? tile(opName, std::move(options), std::move(f)) : *this; } - /// Append a pattern to pad and hoist the operands of Op `opName` with padding - /// `options`. - CodegenStrategy & - pad(StringRef opName, const linalg::LinalgPaddingOptions &options, - const LinalgTransformationFilter::FilterFunction &f = nullptr) { - transformationSequence.emplace_back( - std::make_unique(opName, options, f)); - return *this; - } - /// Conditionally append a pattern to pad and hoist the operands of Op - /// `opName` with padding `options`. - CodegenStrategy & - padIf(bool b, StringRef opName, linalg::LinalgPaddingOptions options, - LinalgTransformationFilter::FilterFunction f = nullptr) { - return b ? pad(opName, std::move(options), std::move(f)) : *this; - } /// Configure the post staged-patterns global enabling passes options. CodegenStrategy & setVectorTransferToSCFOptions(LinalgEnablingOptions options) { diff --git a/mlir/include/mlir/Dialect/Linalg/Transforms/Transforms.h b/mlir/include/mlir/Dialect/Linalg/Transforms/Transforms.h --- a/mlir/include/mlir/Dialect/Linalg/Transforms/Transforms.h +++ b/mlir/include/mlir/Dialect/Linalg/Transforms/Transforms.h @@ -729,18 +729,9 @@ /// See `padding` for more details. struct LinalgPaddingPattern : public OpInterfaceRewritePattern { /// Construct a generic pattern applied to all LinalgOp that verify `filter`. - LinalgPaddingPattern( - MLIRContext *context, - LinalgPaddingOptions options = LinalgPaddingOptions(), - LinalgTransformationFilter f = LinalgTransformationFilter(), - PatternBenefit benefit = 1); - - /// Construct a pattern specifically applied to `opName`. - LinalgPaddingPattern( - StringRef opName, MLIRContext *context, - LinalgPaddingOptions options = LinalgPaddingOptions(), - LinalgTransformationFilter f = LinalgTransformationFilter(), - PatternBenefit benefit = 1); + LinalgPaddingPattern(MLIRContext *context, + LinalgPaddingOptions options = LinalgPaddingOptions(), + PatternBenefit benefit = 1); /// `matchAndRewrite` implementation that returns the significant transformed /// pieces of IR. @@ -753,8 +744,6 @@ } private: - /// LinalgTransformMarker handles special attribute manipulations. - LinalgTransformationFilter filter; /// Options to control padding and hoisting. LinalgPaddingOptions options; }; diff --git a/mlir/lib/Dialect/Linalg/Transforms/LinalgStrategyPasses.cpp b/mlir/lib/Dialect/Linalg/Transforms/LinalgStrategyPasses.cpp --- a/mlir/lib/Dialect/Linalg/Transforms/LinalgStrategyPasses.cpp +++ b/mlir/lib/Dialect/Linalg/Transforms/LinalgStrategyPasses.cpp @@ -123,38 +123,6 @@ LinalgTransformationFilter filter; }; -/// Configurable pass to apply hoisting and padding. -struct LinalgStrategyPadPass - : public impl::LinalgStrategyPadPassBase { - - LinalgStrategyPadPass() = default; - - LinalgStrategyPadPass(StringRef opName, LinalgPaddingOptions opt, - LinalgTransformationFilter filt) - : options(std::move(opt)), filter(std::move(filt)) { - this->anchorOpName.setValue(opName.str()); - } - - void runOnOperation() override { - auto funcOp = getOperation(); - if (!anchorFuncName.empty() && funcOp.getName() != anchorFuncName) - return; - - RewritePatternSet paddingPattern(funcOp.getContext()); - if (!anchorOpName.empty()) { - paddingPattern.add( - anchorOpName, funcOp.getContext(), options, filter); - } else { - paddingPattern.add(funcOp.getContext(), options, - filter); - } - (void)applyPatternsAndFoldGreedily(funcOp, std::move(paddingPattern)); - } - - LinalgPaddingOptions options; - LinalgTransformationFilter filter; -}; - /// Configurable pass to lower vector operations. struct LinalgStrategyRemoveMarkersPass : public impl::LinalgStrategyRemoveMarkersPassBase< @@ -188,14 +156,6 @@ return std::make_unique(opName, opt, filter); } -/// Create a LinalgStrategyPadPass. -std::unique_ptr> -mlir::createLinalgStrategyPadPass(StringRef opName, - const LinalgPaddingOptions &opt, - const LinalgTransformationFilter &filter) { - return std::make_unique(opName, opt, filter); -} - /// Create a LinalgStrategyRemoveMarkersPass. std::unique_ptr> mlir::createLinalgStrategyRemoveMarkersPass() { diff --git a/mlir/lib/Dialect/Linalg/Transforms/Transforms.cpp b/mlir/lib/Dialect/Linalg/Transforms/Transforms.cpp --- a/mlir/lib/Dialect/Linalg/Transforms/Transforms.cpp +++ b/mlir/lib/Dialect/Linalg/Transforms/Transforms.cpp @@ -396,24 +396,15 @@ /// Linalg padding pattern. mlir::linalg::LinalgPaddingPattern::LinalgPaddingPattern( - MLIRContext *context, LinalgPaddingOptions options, - LinalgTransformationFilter f, PatternBenefit benefit) - : OpInterfaceRewritePattern(context, benefit), - filter(std::move(f)), options(std::move(options)) {} - -mlir::linalg::LinalgPaddingPattern::LinalgPaddingPattern( - StringRef opName, MLIRContext *context, LinalgPaddingOptions options, - LinalgTransformationFilter f, PatternBenefit benefit) + MLIRContext *context, LinalgPaddingOptions options, PatternBenefit benefit) : OpInterfaceRewritePattern(context, benefit), - filter(f.addOpNameFilter(opName)), options(std::move(options)) {} + options(std::move(options)) {} FailureOr mlir::linalg::LinalgPaddingPattern::returningMatchAndRewrite( LinalgOp linalgOp, PatternRewriter &rewriter) const { if (!linalgOp.hasTensorSemantics()) return failure(); - if (failed(filter.checkAndNotify(rewriter, linalgOp))) - return failure(); // Pad the operation. LinalgOp paddedOp; @@ -448,15 +439,10 @@ if (failed(newResult)) continue; rewriter.replaceOp(padOp, *newResult); - - // Do not apply hoist padding to the newly introduced transpose operations. - for (GenericOp transposeOp : transposeOps) - filter.replaceLinalgTransformationFilter(rewriter, transposeOp); } // Replace the original operation to pad. rewriter.replaceOp(linalgOp, *newResults); - filter.replaceLinalgTransformationFilter(rewriter, paddedOp); return paddedOp; }