brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.6 KiB · 1939195 Raw
49 lines · cpp
1//===- BufferViewFlowOpInterfaceImpl.cpp - Buffer View Flow Analysis ------===//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-exception6//7//===----------------------------------------------------------------------===//8 9#include "mlir/Dialect/MemRef/Transforms/BufferViewFlowOpInterfaceImpl.h"10 11#include "mlir/Dialect/Bufferization/IR/BufferViewFlowOpInterface.h"12#include "mlir/Dialect/MemRef/IR/MemRef.h"13 14using namespace mlir;15using namespace mlir::bufferization;16 17namespace mlir {18namespace memref {19namespace {20 21struct ReallocOpInterface22    : public BufferViewFlowOpInterface::ExternalModel<ReallocOpInterface,23                                                      ReallocOp> {24  void populateDependencies(25      Operation *op,26      const RegisterDependenciesFn &registerDependenciesFn) const {27    auto reallocOp = cast<ReallocOp>(op);28    // memref.realloc may return the source operand.29    registerDependenciesFn(reallocOp.getSource(), reallocOp.getResult());30  }31 32  bool mayBeTerminalBuffer(Operation *op, Value value) const {33    // The return value of memref.realloc is a terminal buffer because the op34    // may return a newly allocated buffer.35    return true;36  }37};38 39} // namespace40} // namespace memref41} // namespace mlir42 43void memref::registerBufferViewFlowOpInterfaceExternalModels(44    DialectRegistry &registry) {45  registry.addExtension(+[](MLIRContext *ctx, memref::MemRefDialect *dialect) {46    ReallocOp::attachInterface<ReallocOpInterface>(*ctx);47  });48}49