1*a45e58afSMatthias Springer //===- BufferViewFlowOpInterfaceImpl.cpp - Buffer View Flow Analysis ------===// 2*a45e58afSMatthias Springer // 3*a45e58afSMatthias Springer // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4*a45e58afSMatthias Springer // See https://llvm.org/LICENSE.txt for license information. 5*a45e58afSMatthias Springer // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6*a45e58afSMatthias Springer // 7*a45e58afSMatthias Springer //===----------------------------------------------------------------------===// 8*a45e58afSMatthias Springer 9*a45e58afSMatthias Springer #include "mlir/Dialect/MemRef/Transforms/BufferViewFlowOpInterfaceImpl.h" 10*a45e58afSMatthias Springer 11*a45e58afSMatthias Springer #include "mlir/Dialect/Bufferization/IR/BufferViewFlowOpInterface.h" 12*a45e58afSMatthias Springer #include "mlir/Dialect/MemRef/IR/MemRef.h" 13*a45e58afSMatthias Springer 14*a45e58afSMatthias Springer using namespace mlir; 15*a45e58afSMatthias Springer using namespace mlir::bufferization; 16*a45e58afSMatthias Springer 17*a45e58afSMatthias Springer namespace mlir { 18*a45e58afSMatthias Springer namespace memref { 19*a45e58afSMatthias Springer namespace { 20*a45e58afSMatthias Springer 21*a45e58afSMatthias Springer struct ReallocOpInterface 22*a45e58afSMatthias Springer : public BufferViewFlowOpInterface::ExternalModel<ReallocOpInterface, 23*a45e58afSMatthias Springer ReallocOp> { 24*a45e58afSMatthias Springer void populateDependenciesmlir::memref::__anonbf0ddcb90111::ReallocOpInterface25*a45e58afSMatthias Springer populateDependencies(Operation *op, 26*a45e58afSMatthias Springer RegisterDependenciesFn registerDependenciesFn) const { 27*a45e58afSMatthias Springer auto reallocOp = cast<ReallocOp>(op); 28*a45e58afSMatthias Springer // memref.realloc may return the source operand. 29*a45e58afSMatthias Springer registerDependenciesFn(reallocOp.getSource(), reallocOp.getResult()); 30*a45e58afSMatthias Springer } 31*a45e58afSMatthias Springer mayBeTerminalBuffermlir::memref::__anonbf0ddcb90111::ReallocOpInterface32*a45e58afSMatthias Springer bool mayBeTerminalBuffer(Operation *op, Value value) const { 33*a45e58afSMatthias Springer // The return value of memref.realloc is a terminal buffer because the op 34*a45e58afSMatthias Springer // may return a newly allocated buffer. 35*a45e58afSMatthias Springer return true; 36*a45e58afSMatthias Springer } 37*a45e58afSMatthias Springer }; 38*a45e58afSMatthias Springer 39*a45e58afSMatthias Springer } // namespace 40*a45e58afSMatthias Springer } // namespace memref 41*a45e58afSMatthias Springer } // namespace mlir 42*a45e58afSMatthias Springer registerBufferViewFlowOpInterfaceExternalModels(DialectRegistry & registry)43*a45e58afSMatthias Springervoid memref::registerBufferViewFlowOpInterfaceExternalModels( 44*a45e58afSMatthias Springer DialectRegistry ®istry) { 45*a45e58afSMatthias Springer registry.addExtension(+[](MLIRContext *ctx, memref::MemRefDialect *dialect) { 46*a45e58afSMatthias Springer ReallocOp::attachInterface<ReallocOpInterface>(*ctx); 47*a45e58afSMatthias Springer }); 48*a45e58afSMatthias Springer } 49