[Mlir-commits] [mlir] 6f3baf4 - [mlir][nfc] Clean-up ConvertToDestinationStyle.cpp.

Alexander Belyaev llvmlistbot at llvm.org
Thu Mar 2 01:31:52 PST 2023


Author: Alexander Belyaev
Date: 2023-03-02T10:31:33+01:00
New Revision: 6f3baf43820680841b0daebdde2c78b43175444b

URL: https://github.com/llvm/llvm-project/commit/6f3baf43820680841b0daebdde2c78b43175444b
DIFF: https://github.com/llvm/llvm-project/commit/6f3baf43820680841b0daebdde2c78b43175444b.diff

LOG: [mlir][nfc] Clean-up ConvertToDestinationStyle.cpp.

Differential Revision: https://reviews.llvm.org/D145147

Added: 
    

Modified: 
    mlir/lib/Dialect/Linalg/Transforms/ConvertToDestinationStyle.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Dialect/Linalg/Transforms/ConvertToDestinationStyle.cpp b/mlir/lib/Dialect/Linalg/Transforms/ConvertToDestinationStyle.cpp
index 85235ef2db37..16baebbd4ad9 100644
--- a/mlir/lib/Dialect/Linalg/Transforms/ConvertToDestinationStyle.cpp
+++ b/mlir/lib/Dialect/Linalg/Transforms/ConvertToDestinationStyle.cpp
@@ -367,46 +367,18 @@ Value linalg::bufferizeToAllocation(RewriterBase &rewriter, Value value,
 }
 
 namespace {
-/// Lower tensor.from_elements to a sequence of chained tensor.insert.
-struct FromElementsOpConverter : public OpRewritePattern<FromElementsOp> {
-  using OpRewritePattern<FromElementsOp>::OpRewritePattern;
-
-  LogicalResult matchAndRewrite(FromElementsOp fromElementsOp,
-                                PatternRewriter &rewriter) const override {
-    if (failed(
-            linalg::rewriteInDestinationPassingStyle(rewriter, fromElementsOp)))
-      return failure();
-    return success();
-  }
-};
 
-/// Lower tensor.generate to linalg.generic.
-struct GenerateOpConverter : public OpRewritePattern<GenerateOp> {
-  using OpRewritePattern<GenerateOp>::OpRewritePattern;
-
-  LogicalResult matchAndRewrite(GenerateOp generateOp,
-                                PatternRewriter &rewriter) const override {
-    if (failed(linalg::rewriteInDestinationPassingStyle(rewriter, generateOp)))
-      return failure();
-    return success();
-  }
-};
+template <typename OpTy>
+LogicalResult rewriteOpInDestinationPassingStyle(OpTy op,
+                                                 PatternRewriter &rewriter) {
+  return linalg::rewriteInDestinationPassingStyle(rewriter, op);
+}
 
-/// Lower tensor.pad to linalg.generic + tensor.insert_slice.
-struct PadOpConverter : public OpRewritePattern<PadOp> {
-  using OpRewritePattern<PadOp>::OpRewritePattern;
-
-  LogicalResult matchAndRewrite(PadOp padOp,
-                                PatternRewriter &rewriter) const override {
-    if (failed(linalg::rewriteInDestinationPassingStyle(rewriter, padOp)))
-      return failure();
-    return success();
-  }
-};
 } // namespace
 
 void linalg::populateConvertToDestinationStylePatterns(
     RewritePatternSet &patterns) {
-  patterns.insert<FromElementsOpConverter, GenerateOpConverter, PadOpConverter>(
-      patterns.getContext());
+  patterns.add(rewriteOpInDestinationPassingStyle<tensor::FromElementsOp>);
+  patterns.add(rewriteOpInDestinationPassingStyle<tensor::GenerateOp>);
+  patterns.add(rewriteOpInDestinationPassingStyle<tensor::PadOp>);
 }


        


More information about the Mlir-commits mailing list