From ec640382fc9378961697e2daa512a24ecac36fcb Mon Sep 17 00:00:00 2001 From: Nicolas Vasilache Date: Thu, 16 Feb 2023 07:02:21 -0800 Subject: [PATCH] [mlir][MemRef] NFC - Add debug information to MultiBuffer.cpp --- mlir/lib/Dialect/MemRef/Transforms/MultiBuffer.cpp | 32 +++++++++++++++++----- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/mlir/lib/Dialect/MemRef/Transforms/MultiBuffer.cpp b/mlir/lib/Dialect/MemRef/Transforms/MultiBuffer.cpp index c70b210..e094f5a 100644 --- a/mlir/lib/Dialect/MemRef/Transforms/MultiBuffer.cpp +++ b/mlir/lib/Dialect/MemRef/Transforms/MultiBuffer.cpp @@ -15,9 +15,14 @@ #include "mlir/Dialect/MemRef/Transforms/Passes.h" #include "mlir/IR/Dominance.h" #include "mlir/Interfaces/LoopLikeInterface.h" +#include "llvm/Support/Debug.h" using namespace mlir; +#define DEBUG_TYPE "memref-transforms" +#define DBGS() (llvm::dbgs() << "[" DEBUG_TYPE "]: ") +#define DBGSNL() (llvm::dbgs() << "\n") + /// Return true if the op fully overwrite the given `buffer` value. static bool overrideBuffer(Operation *op, Value buffer) { auto copyOp = dyn_cast(op); @@ -79,33 +84,46 @@ static Value getOrCreateValue(OpFoldResult res, OpBuilder &builder, // uses and requires updating subview ops. FailureOr mlir::memref::multiBuffer(memref::AllocOp allocOp, unsigned multiplier) { + LLVM_DEBUG(DBGS() << "Try multibuffer: " << allocOp << "\n"); DominanceInfo dom(allocOp->getParentOp()); LoopLikeOpInterface candidateLoop; for (Operation *user : allocOp->getUsers()) { auto parentLoop = user->getParentOfType(); - if (!parentLoop) + if (!parentLoop) { + LLVM_DEBUG(DBGS() << "Skip user: no parent loop\n"); return failure(); - /// Make sure there is no loop carried dependency on the allocation. - if (!overrideBuffer(user, allocOp.getResult())) + } + /// Make sure there is no loop-carried dependency on the allocation. + if (!overrideBuffer(user, allocOp.getResult())) { + LLVM_DEBUG(DBGS() << "Skip user: found loop-carried dependence\n"); continue; + } // If this user doesn't dominate all the other users keep looking. if (llvm::any_of(allocOp->getUsers(), [&](Operation *otherUser) { return !dom.dominates(user, otherUser); - })) + })) { + LLVM_DEBUG(DBGS() << "Skip user: does not dominate all other users\n"); continue; + } candidateLoop = parentLoop; break; } - if (!candidateLoop) + if (!candidateLoop) { + LLVM_DEBUG(DBGS() << "Skip alloc: no candidate loop\n"); return failure(); + } std::optional inductionVar = candidateLoop.getSingleInductionVar(); std::optional lowerBound = candidateLoop.getSingleLowerBound(); std::optional singleStep = candidateLoop.getSingleStep(); - if (!inductionVar || !lowerBound || !singleStep) + if (!inductionVar || !lowerBound || !singleStep) { + LLVM_DEBUG(DBGS() << "Skip alloc: no single iv, lb or step\n"); return failure(); + } - if (!dom.dominates(allocOp.getOperation(), candidateLoop)) + if (!dom.dominates(allocOp.getOperation(), candidateLoop)) { + LLVM_DEBUG(DBGS() << "Skip alloc: does not dominate candidate loop\n"); return failure(); + } OpBuilder builder(candidateLoop); SmallVector newShape(1, multiplier); -- 2.7.4