//===----------- MultiBuffering.cpp ---------------------------------------===// // // 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 multi buffering transformation. // //===----------------------------------------------------------------------===// #include "mlir/Dialect/Affine/IR/AffineOps.h" #include "mlir/Dialect/Arith/Utils/Utils.h" #include "mlir/Dialect/MemRef/IR/MemRef.h" #include "mlir/Dialect/MemRef/Transforms/Passes.h" #include "mlir/Dialect/MemRef/Transforms/Transforms.h" #include "mlir/IR/AffineExpr.h" #include "mlir/IR/BuiltinAttributes.h" #include "mlir/IR/Dominance.h" #include "mlir/IR/PatternMatch.h" #include "mlir/IR/ValueRange.h" #include "mlir/Interfaces/LoopLikeInterface.h" #include "llvm/ADT/STLExtras.h" #include "llvm/Support/Debug.h" usingnamespacemlir; #define DEBUG_TYPE … #define DBGS() … #define DBGSNL() … /// Return true if the op fully overwrite the given `buffer` value. static bool overrideBuffer(Operation *op, Value buffer) { … } /// Replace the uses of `oldOp` with the given `val` and for subview uses /// propagate the type change. Changing the memref type may require propagating /// it through subview ops so we cannot just do a replaceAllUse but need to /// propagate the type change and erase old subview ops. static void replaceUsesAndPropagateType(RewriterBase &rewriter, Operation *oldOp, Value val) { … } // Transformation to do multi-buffering/array expansion to remove dependencies // on the temporary allocation between consecutive loop iterations. // Returns success if the transformation happened and failure otherwise. // This is not a pattern as it requires propagating the new memref type to its // uses and requires updating subview ops. FailureOr<memref::AllocOp> mlir::memref::multiBuffer(RewriterBase &rewriter, memref::AllocOp allocOp, unsigned multiBufferingFactor, bool skipOverrideAnalysis) { … } FailureOr<memref::AllocOp> mlir::memref::multiBuffer(memref::AllocOp allocOp, unsigned multiBufferingFactor, bool skipOverrideAnalysis) { … }