[Mlir-commits] [mlir] 4641c63 - [mlir][Bufferization] Use DestinationStyleOpInterface where possible.

Adrian Kuegel llvmlistbot at llvm.org
Tue Aug 23 05:22:07 PDT 2022


Author: Adrian Kuegel
Date: 2022-08-23T14:21:47+02:00
New Revision: 4641c6386b41dbd05805895d45d1bb94ed35d307

URL: https://github.com/llvm/llvm-project/commit/4641c6386b41dbd05805895d45d1bb94ed35d307
DIFF: https://github.com/llvm/llvm-project/commit/4641c6386b41dbd05805895d45d1bb94ed35d307.diff

LOG: [mlir][Bufferization] Use DestinationStyleOpInterface where possible.

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

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Dialect/Linalg/Transforms/BufferizableOpInterfaceImpl.cpp b/mlir/lib/Dialect/Linalg/Transforms/BufferizableOpInterfaceImpl.cpp
index fce193eaf7c95..abc430faddefe 100644
--- a/mlir/lib/Dialect/Linalg/Transforms/BufferizableOpInterfaceImpl.cpp
+++ b/mlir/lib/Dialect/Linalg/Transforms/BufferizableOpInterfaceImpl.cpp
@@ -20,9 +20,11 @@ using namespace mlir::bufferization;
 
 namespace {
 
-/// Generic conversion for any LinalgOp on tensors.
-static LogicalResult bufferizeLinalgOp(RewriterBase &rewriter, LinalgOp op,
-                                       const BufferizationOptions &options) {
+/// Generic conversion for any DestinationStyleOpInterface on tensors.
+static LogicalResult
+bufferizeDestinationStyleOpInterface(RewriterBase &rewriter,
+                                     DestinationStyleOpInterface op,
+                                     const BufferizationOptions &options) {
   // Take a guard before anything else.
   OpBuilder::InsertionGuard g(rewriter);
   rewriter.setInsertionPoint(op);
@@ -71,7 +73,7 @@ static LogicalResult bufferizeLinalgOp(RewriterBase &rewriter, LinalgOp op,
   // new op. Since the new op does not have any tensor results, it does not
   // return anything.
   assert(op->getNumRegions() == 1 && "expected that op has 1 region");
-  auto newOp = cast<LinalgOp>(op.cloneWithoutRegions(
+  auto newOp = cast<DestinationStyleOpInterface>(op.cloneWithoutRegions(
       rewriter, op.getLoc(), /*resultTypes=*/TypeRange{}, newOperands));
   rewriter.inlineRegionBefore(op->getRegion(0), newOp->getRegion(0),
                               newOp->getRegion(0).begin());
@@ -105,7 +107,7 @@ struct LinalgOpInterface
   SmallVector<OpOperand *>
   getAliasingOpOperand(Operation *op, OpResult opResult,
                        const AnalysisState &state) const {
-    auto genericOp = cast<linalg::LinalgOp>(op);
+    auto genericOp = cast<DestinationStyleOpInterface>(op);
 
     // The i-th OpResult may alias with the i-th "out" tensor.
     return {genericOp.getOutputOperand(opResult.getResultNumber())};
@@ -113,7 +115,7 @@ struct LinalgOpInterface
 
   SmallVector<OpResult> getAliasingOpResult(Operation *op, OpOperand &opOperand,
                                             const AnalysisState &state) const {
-    auto genericOp = cast<linalg::LinalgOp>(op);
+    auto genericOp = cast<linalg::DestinationStyleOpInterface>(op);
 
     // The i-th "out" tensor may alias with the i-th OpResult.
     if (genericOp.isOutputTensor(&opOperand))
@@ -128,7 +130,8 @@ struct LinalgOpInterface
 
   LogicalResult bufferize(Operation *op, RewriterBase &rewriter,
                           const BufferizationOptions &options) const {
-    return bufferizeLinalgOp(rewriter, cast<LinalgOp>(op), options);
+    return bufferizeDestinationStyleOpInterface(
+        rewriter, cast<DestinationStyleOpInterface>(op), options);
   }
 };
 


        


More information about the Mlir-commits mailing list