//===- OptimizeAllocationLiveness.cpp - impl. optimize allocation liveness pass //-===// // // 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 // //===----------------------------------------------------------------------===// // // This file implements a pass for optimizing allocation liveness. // The pass moves the deallocation operation after the last user of the // allocated buffer. //===----------------------------------------------------------------------===// #include "mlir/Dialect/Bufferization/Transforms/BufferViewFlowAnalysis.h" #include "mlir/Dialect/Bufferization/Transforms/Passes.h" #include "mlir/Dialect/Func/IR/FuncOps.h" #include "mlir/Dialect/MemRef/IR/MemRef.h" #include "mlir/IR/Operation.h" #include "llvm/Support/Debug.h" #define DEBUG_TYPE … #define DBGS() … #define LDBG(X) … namespace mlir { namespace bufferization { #define GEN_PASS_DEF_OPTIMIZEALLOCATIONLIVENESS #include "mlir/Dialect/Bufferization/Transforms/Passes.h.inc" } // namespace bufferization } // namespace mlir usingnamespacemlir; namespace { //===----------------------------------------------------------------------===// // Helper functions //===----------------------------------------------------------------------===// /// Return true if `a` happens before `b`, i.e., `a` or one of its ancestors /// properly dominates `b` and `b` is not inside `a`. static bool happensBefore(Operation *a, Operation *b) { … } /// This method searches for a user of value that is a dealloc operation. /// If multiple users with free effect are found, return nullptr. Operation *findUserWithFreeSideEffect(Value value) { … } /// Checks if the given op allocates memory. static bool hasMemoryAllocEffect(MemoryEffectOpInterface memEffectOp) { … } struct OptimizeAllocationLiveness : public bufferization::impl::OptimizeAllocationLivenessBase< OptimizeAllocationLiveness> { … }; } // end anonymous namespace //===----------------------------------------------------------------------===// // OptimizeAllocatinliveness construction //===----------------------------------------------------------------------===// std::unique_ptr<Pass> mlir::bufferization::createOptimizeAllocationLivenessPass() { … }