1 //===- DstBufferizableOpInterfaceImpl.h - Dst Op Bufferization --*- C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #ifndef MLIR_DIALECT_BUFFERIZATION_IR_DSTBUFFERIZABLEOPINTERFACEIMPL_H_ 10 #define MLIR_DIALECT_BUFFERIZATION_IR_DSTBUFFERIZABLEOPINTERFACEIMPL_H_ 11 12 #include "mlir/Dialect/Bufferization/IR/BufferizableOpInterface.h" 13 #include "mlir/Interfaces/DestinationStyleOpInterface.h" 14 15 namespace mlir { 16 namespace bufferization { 17 18 /// Bufferizable ops that implement the DestinationStyleOpInterface can use this 19 /// external model base class. It provides default implementations for various 20 /// required interface methods. 21 template <typename ConcreteModel, typename ConcreteOp> 22 struct DstBufferizableOpInterfaceExternalModel 23 : public BufferizableOpInterface::ExternalModel<ConcreteModel, ConcreteOp> { bufferizesToMemoryReadDstBufferizableOpInterfaceExternalModel24 bool bufferizesToMemoryRead(Operation *op, OpOperand &opOperand, 25 const AnalysisState &state) const { 26 // All inputs and outputs bufferize to a memory read. 27 assert(isa<DestinationStyleOpInterface>(op) && 28 "expected that op implements DestinationStyleOpInterface"); 29 return true; 30 } 31 bufferizesToMemoryWriteDstBufferizableOpInterfaceExternalModel32 bool bufferizesToMemoryWrite(Operation *op, OpOperand &opOperand, 33 const AnalysisState &state) const { 34 // Only outputs bufferize to a memory write. 35 auto dstOp = cast<DestinationStyleOpInterface>(op); 36 return dstOp.isDpsInit(&opOperand); 37 } 38 getAliasingValuesDstBufferizableOpInterfaceExternalModel39 AliasingValueList getAliasingValues(Operation *op, OpOperand &opOperand, 40 const AnalysisState &state) const { 41 // Output operands alias with their respective tied OpResults. 42 auto dstOp = cast<DestinationStyleOpInterface>(op); 43 if (dstOp.isDpsInit(&opOperand)) 44 return {{dstOp.getTiedOpResult(&opOperand), BufferRelation::Equivalent}}; 45 return {}; 46 } 47 }; 48 49 } // namespace bufferization 50 } // namespace mlir 51 52 #endif // MLIR_DIALECT_BUFFERIZATION_IR_DSTBUFFERIZABLEOPINTERFACEIMPL_H_ 53