[mlir][linalg][bufferize][NFC] Utilize DestinationStyleOpInterface helper
authorMatthias Springer <springerm@google.com>
Wed, 18 Jan 2023 14:19:23 +0000 (15:19 +0100)
committerMatthias Springer <springerm@google.com>
Wed, 18 Jan 2023 14:19:55 +0000 (15:19 +0100)
`DstBufferizableOpInterfaceExternalModel` provides suitable default implementations for Linalg ops.

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

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

index c463e5f..f934a15 100644 (file)
@@ -9,6 +9,7 @@
 #include "mlir/Dialect/Linalg/Transforms/BufferizableOpInterfaceImpl.h"
 #include "mlir/Dialect/Bufferization/IR/BufferizableOpInterface.h"
 #include "mlir/Dialect/Bufferization/IR/Bufferization.h"
+#include "mlir/Dialect/Bufferization/IR/DstBufferizableOpInterfaceImpl.h"
 #include "mlir/Dialect/Linalg/IR/Linalg.h"
 #include "mlir/Dialect/Tensor/IR/Tensor.h"
 #include "mlir/IR/Dialect.h"
@@ -89,8 +90,8 @@ bufferizeDestinationStyleOpInterface(RewriterBase &rewriter,
 /// operates entirely on memrefs.
 template <typename OpTy>
 struct LinalgOpInterface
-    : public BufferizableOpInterface::ExternalModel<LinalgOpInterface<OpTy>,
-                                                    OpTy> {
+    : public DstBufferizableOpInterfaceExternalModel<LinalgOpInterface<OpTy>,
+                                                     OpTy> {
   bool bufferizesToMemoryRead(Operation *op, OpOperand &opOperand,
                               const AnalysisState &state) const {
     // Operand is read if it is used in the computation.
@@ -105,30 +106,6 @@ struct LinalgOpInterface
     return !bufferizableOp.getAliasingOpResult(opOperand, state).empty();
   }
 
-  SmallVector<OpOperand *>
-  getAliasingOpOperand(Operation *op, OpResult opResult,
-                       const AnalysisState &state) const {
-    auto genericOp = cast<DestinationStyleOpInterface>(op);
-
-    // The i-th OpResult may alias with the i-th "out" tensor.
-    return {genericOp.getDpsInitOperand(opResult.getResultNumber())};
-  }
-
-  SmallVector<OpResult> getAliasingOpResult(Operation *op, OpOperand &opOperand,
-                                            const AnalysisState &state) const {
-    auto genericOp = cast<DestinationStyleOpInterface>(op);
-
-    // The i-th "out" tensor may alias with the i-th OpResult.
-    if (genericOp.isDpsInit(&opOperand))
-      return {genericOp.getTiedOpResult(&opOperand)};
-    return {};
-  }
-
-  BufferRelation bufferRelation(Operation *op, OpResult opResult,
-                                const AnalysisState &state) const {
-    return BufferRelation::Equivalent;
-  }
-
   LogicalResult bufferize(Operation *op, RewriterBase &rewriter,
                           const BufferizationOptions &options) const {
     return bufferizeDestinationStyleOpInterface(