//======- BufferViewFlowAnalysis.cpp - Buffer alias analysis -*- C++ -*-======// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// #include "mlir/Dialect/Bufferization/Transforms/BufferViewFlowAnalysis.h" #include "mlir/Dialect/Bufferization/IR/BufferViewFlowOpInterface.h" #include "mlir/Interfaces/CallInterfaces.h" #include "mlir/Interfaces/ControlFlowInterfaces.h" #include "mlir/Interfaces/FunctionInterfaces.h" #include "mlir/Interfaces/ViewLikeInterface.h" #include "llvm/ADT/SetOperations.h" #include "llvm/ADT/SetVector.h" usingnamespacemlir; usingnamespacemlir::bufferization; //===----------------------------------------------------------------------===// // BufferViewFlowAnalysis //===----------------------------------------------------------------------===// /// Constructs a new alias analysis using the op provided. BufferViewFlowAnalysis::BufferViewFlowAnalysis(Operation *op) { … } static BufferViewFlowAnalysis::ValueSetT resolveValues(const BufferViewFlowAnalysis::ValueMapT &map, Value value) { … } /// Find all immediate and indirect dependent buffers this value could /// potentially have. Note that the resulting set will also contain the value /// provided as it is a dependent alias of itself. BufferViewFlowAnalysis::ValueSetT BufferViewFlowAnalysis::resolve(Value rootValue) const { … } BufferViewFlowAnalysis::ValueSetT BufferViewFlowAnalysis::resolveReverse(Value rootValue) const { … } /// Removes the given values from all alias sets. void BufferViewFlowAnalysis::remove(const SetVector<Value> &aliasValues) { … } void BufferViewFlowAnalysis::rename(Value from, Value to) { … } /// This function constructs a mapping from values to its immediate /// dependencies. It iterates over all blocks, gets their predecessors, /// determines the values that will be passed to the corresponding block /// arguments and inserts them into the underlying map. Furthermore, it wires /// successor regions and branch-like return operations from nested regions. void BufferViewFlowAnalysis::build(Operation *op) { … } bool BufferViewFlowAnalysis::mayBeTerminalBuffer(Value value) const { … } //===----------------------------------------------------------------------===// // BufferOriginAnalysis //===----------------------------------------------------------------------===// /// Return "true" if the given value is the result of a memory allocation. static bool hasAllocateSideEffect(Value v) { … } /// Return "true" if the given value is a function block argument. static bool isFunctionArgument(Value v) { … } /// Given a memref value, return the "base" value by skipping over all /// ViewLikeOpInterface ops (if any) in the reverse use-def chain. static Value getViewBase(Value value) { … } BufferOriginAnalysis::BufferOriginAnalysis(Operation *op) : … { … } std::optional<bool> BufferOriginAnalysis::isSameAllocation(Value v1, Value v2) { … }