Skip to content

Commit

Permalink
[MLIR][Affine] Fix bug and MSAN issue in affine loop utils
Browse files Browse the repository at this point in the history
Fix bug and MSAN issue in affine loop utils introduced by
d25e022 (D146495). While on it,
fix/clean up issues in immediately surrounding code.

Differential Revision: https://reviews.llvm.org/D146698
  • Loading branch information
bondhugula committed Mar 23, 2023
1 parent 5b0055a commit e50f131
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions mlir/lib/Dialect/Affine/Utils/LoopUtils.cpp
Expand Up @@ -2057,6 +2057,8 @@ static LogicalResult generateCopy(
OpBuilder topBuilder(f.getBody());
Value zeroIndex = topBuilder.create<arith::ConstantIndexOp>(f.getLoc(), 0);

*sizeInBytes = 0;

if (begin == end)
return success();

Expand Down Expand Up @@ -2105,7 +2107,6 @@ static LogicalResult generateCopy(

if (*numElements == 0) {
LLVM_DEBUG(llvm::dbgs() << "Nothing to copy\n");
*sizeInBytes = 0;
return success();
}

Expand Down Expand Up @@ -2183,8 +2184,7 @@ static LogicalResult generateCopy(
// fastMemRefType is a constant shaped memref.
auto maySizeInBytes = getIntOrFloatMemRefSizeInBytes(fastMemRefType);
// We don't account for things of unknown size.
if (!maySizeInBytes)
maySizeInBytes = 0;
*sizeInBytes = maySizeInBytes ? *maySizeInBytes : 0;

LLVM_DEBUG(emitRemarkForBlock(*block)
<< "Creating fast buffer of type " << fastMemRefType
Expand All @@ -2193,7 +2193,6 @@ static LogicalResult generateCopy(
} else {
// Reuse the one already created.
fastMemRef = fastBufferMap[memref];
*sizeInBytes = 0;
}

auto numElementsSSA = top.create<arith::ConstantIndexOp>(loc, *numElements);
Expand Down Expand Up @@ -2554,13 +2553,13 @@ LogicalResult mlir::affineDataCopyGenerate(Block::iterator begin,
if (llvm::DebugFlag && (forOp = dyn_cast<AffineForOp>(&*begin))) {
LLVM_DEBUG(forOp.emitRemark()
<< llvm::divideCeil(totalCopyBuffersSizeInBytes, 1024)
<< " KiB of copy buffers in fast memory space for this block\n");
<< " KiB of copy buffers in fast memory space for this block");
}

if (totalCopyBuffersSizeInBytes > copyOptions.fastMemCapacityBytes) {
StringRef str = "Total size of all copy buffers' for this block "
"exceeds fast memory capacity\n";
block->getParentOp()->emitWarning(str);
block->getParentOp()->emitWarning(
"total size of all copy buffers' for this block exceeds fast memory "
"capacity");
}

return success();
Expand Down

0 comments on commit e50f131

Please sign in to comment.