Skip to content

Commit

Permalink
[mlir][Linalg] NFC - Drop LinalgLoweringPattern
Browse files Browse the repository at this point in the history
Linalg ops are generally lowered to loops using a pass and the individual application
of patterns has no concrete uses.
If/when necessary, this can later be reintroduced via a proper transform dialect op.

Differential Revision: https://reviews.llvm.org/D135766
  • Loading branch information
nicolasvasilache committed Oct 12, 2022
1 parent 0b92640 commit bbe4441
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 75 deletions.
60 changes: 0 additions & 60 deletions mlir/include/mlir/Dialect/Linalg/Transforms/Transforms.h
Original file line number Diff line number Diff line change
Expand Up @@ -842,66 +842,6 @@ struct LinalgEnablingOptions {
//===----------------------------------------------------------------------===//
// Transformations exposed as rewrite patterns.
//===----------------------------------------------------------------------===//
///
/// Linalg lowering patterns.
///
/// Apply the `linalgLowerOpToLoops` transformation as a pattern.
/// `filter` controls LinalgTransformMarker matching and update when specified.
/// See `linalgLowerOpToLoops` for more details.
enum class LinalgLoweringType {
LibraryCall = 0,
Loops = 1,
AffineLoops = 2,
ParallelLoops = 3
};

template <typename OpTy>
struct LinalgLoweringPattern : public RewritePattern {
LinalgLoweringPattern(
MLIRContext *context, LinalgLoweringType loweringType,
LinalgTransformationFilter f = LinalgTransformationFilter(),
PatternBenefit benefit = 1)
: RewritePattern(OpTy::getOperationName(), benefit, context),
filter(std::move(f)), loweringType(loweringType) {}

// TODO: Move implementation to .cpp once named ops are auto-generated.
LogicalResult matchAndRewrite(Operation *op,
PatternRewriter &rewriter) const override {
LinalgOp linalgOp = dyn_cast<LinalgOp>(op);
if (!linalgOp)
return failure();
if (failed(filter.checkAndNotify(rewriter, linalgOp)))
return failure();

switch (loweringType) {
case LinalgLoweringType::LibraryCall:
// TODO: Move lowering to library calls here.
return failure();
case LinalgLoweringType::Loops:
if (failed(linalgOpToLoops(rewriter, op)))
return failure();
break;
case LinalgLoweringType::AffineLoops:
if (failed(linalgOpToAffineLoops(rewriter, op)))
return failure();
break;
case LinalgLoweringType::ParallelLoops:
if (failed(linalgOpToParallelLoops(rewriter, op)))
return failure();
break;
}

rewriter.eraseOp(op);
return success();
}

private:
/// LinalgTransformMarker handles special attribute manipulations.
LinalgTransformationFilter filter;
/// Controls whether the pattern lowers to library calls, scf.for, affine.for
/// or scf.parallel.
LinalgLoweringType loweringType;
};

/// Linalg generalization patterns

Expand Down
9 changes: 1 addition & 8 deletions mlir/test/Dialect/Linalg/transform-patterns.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,9 @@ transform.sequence failures(propagate) {

// CHECK-LABEL: func @dot
// CHECK-DAG: %[[c0:.*]] = arith.constant 0 : index
// CHECK-DAG: %[[c1:.*]] = arith.constant 1 : index
// CHECK-DAG: %[[c8000:.*]] = arith.constant 8000 : index
// CHECK: scf.for {{.*}} = %[[c0]] to {{.*}} step %[[c8000]] {
// CHECK: scf.for {{.*}} = %[[c0]] to {{.*}} step %[[c1]] {
// CHECK: load
// CHECK: load
// CHECK: load
// CHECK: arith.mulf
// CHECK: arith.addf
// CHECK: store
// CHECK: linalg.dot

// -----

Expand Down
7 changes: 0 additions & 7 deletions mlir/test/lib/Dialect/Linalg/TestLinalgTransforms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,6 @@ static void applyPatterns(func::FuncOp funcOp) {
MLIRContext *ctx = funcOp.getContext();
RewritePatternSet patterns(ctx);

//===--------------------------------------------------------------------===//
// Linalg to loops patterns.
//===--------------------------------------------------------------------===//
patterns.add<LinalgLoweringPattern<DotOp>>(
ctx,
/*loweringType=*/LinalgLoweringType::Loops);

//===--------------------------------------------------------------------===//
// Linalg distribution patterns.
//===--------------------------------------------------------------------===//
Expand Down

0 comments on commit bbe4441

Please sign in to comment.