Skip to content

Commit 217968f

Browse files
committed
[MLIR] Adopt LDBG() debug macros in Affine/Utils/Loop(Fusion)Utils.cpp (NFC)
1 parent 2511b14 commit 217968f

File tree

2 files changed

+48
-57
lines changed

2 files changed

+48
-57
lines changed

mlir/lib/Dialect/Affine/Utils/LoopFusionUtils.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "mlir/IR/Operation.h"
2323
#include "mlir/IR/PatternMatch.h"
2424
#include "llvm/Support/Debug.h"
25+
#include "llvm/Support/DebugLog.h"
2526
#include "llvm/Support/raw_ostream.h"
2627
#include <optional>
2728

@@ -251,20 +252,20 @@ FusionResult mlir::affine::canFuseLoops(AffineForOp srcForOp,
251252
FusionStrategy fusionStrategy) {
252253
// Return 'failure' if 'dstLoopDepth == 0'.
253254
if (dstLoopDepth == 0) {
254-
LLVM_DEBUG(llvm::dbgs() << "Cannot fuse loop nests at depth 0\n");
255+
LDBG() << "Cannot fuse loop nests at depth 0";
255256
return FusionResult::FailPrecondition;
256257
}
257258
// Return 'failure' if 'srcForOp' and 'dstForOp' are not in the same block.
258259
auto *block = srcForOp->getBlock();
259260
if (block != dstForOp->getBlock()) {
260-
LLVM_DEBUG(llvm::dbgs() << "Cannot fuse loop nests in different blocks\n");
261+
LDBG() << "Cannot fuse loop nests in different blocks";
261262
return FusionResult::FailPrecondition;
262263
}
263264

264265
// Return 'failure' if no valid insertion point for fused loop nest in 'block'
265266
// exists which would preserve dependences.
266267
if (!getFusedLoopNestInsertionPoint(srcForOp, dstForOp)) {
267-
LLVM_DEBUG(llvm::dbgs() << "Fusion would violate dependences in block\n");
268+
LDBG() << "Fusion would violate dependences in block";
268269
return FusionResult::FailBlockDependence;
269270
}
270271

@@ -277,14 +278,14 @@ FusionResult mlir::affine::canFuseLoops(AffineForOp srcForOp,
277278
// Gather all load and store from 'forOpA' which precedes 'forOpB' in 'block'.
278279
SmallVector<Operation *, 4> opsA;
279280
if (!gatherLoadsAndStores(forOpA, opsA)) {
280-
LLVM_DEBUG(llvm::dbgs() << "Fusing loops with affine.if unsupported\n");
281+
LDBG() << "Fusing loops with affine.if unsupported";
281282
return FusionResult::FailPrecondition;
282283
}
283284

284285
// Gather all load and store from 'forOpB' which succeeds 'forOpA' in 'block'.
285286
SmallVector<Operation *, 4> opsB;
286287
if (!gatherLoadsAndStores(forOpB, opsB)) {
287-
LLVM_DEBUG(llvm::dbgs() << "Fusing loops with affine.if unsupported\n");
288+
LDBG() << "Fusing loops with affine.if unsupported";
288289
return FusionResult::FailPrecondition;
289290
}
290291

@@ -296,7 +297,7 @@ FusionResult mlir::affine::canFuseLoops(AffineForOp srcForOp,
296297
// TODO: 'getMaxLoopDepth' does not support forward slice fusion.
297298
assert(isSrcForOpBeforeDstForOp && "Unexpected forward slice fusion");
298299
if (getMaxLoopDepth(opsA, opsB) < dstLoopDepth) {
299-
LLVM_DEBUG(llvm::dbgs() << "Fusion would violate loop dependences\n");
300+
LDBG() << "Fusion would violate loop dependences";
300301
return FusionResult::FailFusionDependence;
301302
}
302303
}
@@ -339,12 +340,12 @@ FusionResult mlir::affine::canFuseLoops(AffineForOp srcForOp,
339340
strategyOpsA, opsB, dstLoopDepth, numCommonLoops,
340341
isSrcForOpBeforeDstForOp, srcSlice);
341342
if (sliceComputationResult.value == SliceComputationResult::GenericFailure) {
342-
LLVM_DEBUG(llvm::dbgs() << "computeSliceUnion failed\n");
343+
LDBG() << "computeSliceUnion failed";
343344
return FusionResult::FailPrecondition;
344345
}
345346
if (sliceComputationResult.value ==
346347
SliceComputationResult::IncorrectSliceFailure) {
347-
LLVM_DEBUG(llvm::dbgs() << "Incorrect slice computation\n");
348+
LDBG() << "Incorrect slice computation";
348349
return FusionResult::FailIncorrectSlice;
349350
}
350351

@@ -477,7 +478,7 @@ bool mlir::affine::getLoopNestStats(AffineForOp forOpRoot,
477478
auto *parentForOp = forOp->getParentOp();
478479
if (forOp != forOpRoot) {
479480
if (!isa<AffineForOp>(parentForOp)) {
480-
LLVM_DEBUG(llvm::dbgs() << "Expected parent AffineForOp\n");
481+
LDBG() << "Expected parent AffineForOp";
481482
return WalkResult::interrupt();
482483
}
483484
// Add mapping to 'forOp' from its parent AffineForOp.
@@ -498,7 +499,7 @@ bool mlir::affine::getLoopNestStats(AffineForOp forOpRoot,
498499
std::optional<uint64_t> maybeConstTripCount = getConstantTripCount(forOp);
499500
if (!maybeConstTripCount) {
500501
// Currently only constant trip count loop nests are supported.
501-
LLVM_DEBUG(llvm::dbgs() << "Non-constant trip count unsupported\n");
502+
LDBG() << "Non-constant trip count unsupported";
502503
return WalkResult::interrupt();
503504
}
504505

mlir/lib/Dialect/Affine/Utils/LoopUtils.cpp

Lines changed: 37 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@
2121
#include "mlir/Dialect/SCF/IR/SCF.h"
2222
#include "mlir/IR/IRMapping.h"
2323
#include "mlir/IR/IntegerSet.h"
24+
#include "mlir/IR/OperationSupport.h"
2425
#include "mlir/Transforms/GreedyPatternRewriteDriver.h"
2526
#include "llvm/ADT/MapVector.h"
2627
#include "llvm/Support/Debug.h"
28+
#include "llvm/Support/DebugLog.h"
2729
#include "llvm/Support/raw_ostream.h"
2830
#include <optional>
2931

@@ -365,12 +367,11 @@ checkIfHyperRectangular(MutableArrayRef<AffineForOp> input) {
365367
if (input.size() <= 1)
366368
return success();
367369
if (failed(getIndexSet(ops, &cst))) {
368-
LLVM_DEBUG(llvm::dbgs() << "Index set computation failed!\n");
370+
LDBG() << "Index set computation failed!";
369371
return failure();
370372
}
371373
if (!cst.isHyperRectangular(0, input.size())) {
372-
LLVM_DEBUG(llvm::dbgs()
373-
<< "Non-hyperrectangular nests not supported for tiling!\n");
374+
LDBG() << "Non-hyperrectangular nests not supported for tiling!";
374375
return failure();
375376
}
376377
return success();
@@ -385,14 +386,13 @@ static LogicalResult performPreTilingChecks(MutableArrayRef<AffineForOp> input,
385386

386387
if (llvm::any_of(input,
387388
[](AffineForOp op) { return op.getNumResults() > 0; })) {
388-
LLVM_DEBUG(llvm::dbgs()
389-
<< "Cannot tile nest where a loop has yield values\n");
389+
LDBG() << "Cannot tile nest where a loop has yield values";
390390
return failure();
391391
}
392392

393393
// Check if the supplied `for` ops are all successively nested.
394394
if (!isPerfectlyNested(input)) {
395-
LLVM_DEBUG(llvm::dbgs() << "input loops not perfectly nested");
395+
LDBG() << "input loops not perfectly nested";
396396
return failure();
397397
}
398398

@@ -1098,7 +1098,7 @@ LogicalResult mlir::affine::loopUnrollJamByFactor(AffineForOp forOp,
10981098

10991099
// If the trip count is lower than the unroll jam factor, no unroll jam.
11001100
if (mayBeConstantTripCount && *mayBeConstantTripCount < unrollJamFactor) {
1101-
LLVM_DEBUG(llvm::dbgs() << "[failed] trip count < unroll-jam factor\n");
1101+
LDBG() << "[failed] trip count < unroll-jam factor";
11021102
return failure();
11031103
}
11041104

@@ -1766,9 +1766,7 @@ findHighestBlockForPlacement(const MemRefRegion &region, Block &block,
17661766
// We can't hoist past the definition of the memref being copied.
17671767
Value memref = region.memref;
17681768
if (!memref.getParentRegion()->isAncestor(enclosingOp->getParentRegion())) {
1769-
LLVM_DEBUG(
1770-
llvm::dbgs()
1771-
<< "memref definition will end up not dominating hoist location\n");
1769+
LDBG() << "memref definition will end up not dominating hoist location";
17721770
break;
17731771
}
17741772

@@ -1977,7 +1975,7 @@ static LogicalResult generateCopy(
19771975
auto memRefType = cast<MemRefType>(memref.getType());
19781976

19791977
if (!memRefType.getLayout().isIdentity()) {
1980-
LLVM_DEBUG(llvm::dbgs() << "Non-identity layout map not yet supported\n");
1978+
LDBG() << "Non-identity layout map not yet supported";
19811979
return failure();
19821980
}
19831981

@@ -1989,7 +1987,7 @@ static LogicalResult generateCopy(
19891987

19901988
unsigned rank = memRefType.getRank();
19911989
if (rank == 0) {
1992-
LLVM_DEBUG(llvm::dbgs() << "Non-zero ranked memrefs supported\n");
1990+
LDBG() << "Non-zero ranked memrefs supported";
19931991
return failure();
19941992
}
19951993

@@ -2001,29 +1999,27 @@ static LogicalResult generateCopy(
20011999
std::optional<int64_t> numElements =
20022000
region.getConstantBoundingSizeAndShape(&fastBufferShape, &lbs);
20032001
if (!numElements) {
2004-
LLVM_DEBUG(llvm::dbgs() << "Non-constant region size not supported\n");
2002+
LDBG() << "Non-constant region size not supported";
20052003
return failure();
20062004
}
20072005

20082006
if (llvm::any_of(lbs, [](AffineMap lb) { return lb.getNumResults() > 1; })) {
20092007
// This can be supported in the future if needed.
2010-
LLVM_DEBUG(llvm::dbgs()
2011-
<< "Max lower bound for memref region start not supported\n");
2008+
LDBG() << "Max lower bound for memref region start not supported";
20122009
return failure();
20132010
}
20142011

20152012
if (*numElements == 0) {
2016-
LLVM_DEBUG(llvm::dbgs() << "Nothing to copy\n");
2013+
LDBG() << "Nothing to copy";
20172014
return success();
20182015
}
20192016

20202017
SmallVector<AffineMap, 4> lbMaps(rank), ubMaps(rank);
20212018
for (unsigned i = 0; i < rank; ++i) {
20222019
region.getLowerAndUpperBound(i, lbMaps[i], ubMaps[i]);
20232020
if (lbMaps[i].getNumResults() == 0 || ubMaps[i].getNumResults() == 0) {
2024-
LLVM_DEBUG(llvm::dbgs()
2025-
<< "Missing lower or upper bound for region along dimension: "
2026-
<< i << '\n');
2021+
LDBG() << "Missing lower or upper bound for region along dimension: "
2022+
<< i;
20272023
return failure();
20282024
}
20292025
}
@@ -2122,7 +2118,7 @@ static LogicalResult generateCopy(
21222118
// TODO: use all stride levels once DmaStartOp is extended for
21232119
// multi-level strides.
21242120
if (dmaStrideInfos.size() > 1) {
2125-
LLVM_DEBUG(llvm::dbgs() << "Only up to one level of stride supported\n");
2121+
LDBG() << "Only up to one level of stride supported";
21262122
return failure();
21272123
}
21282124

@@ -2309,10 +2305,11 @@ mlir::affine::affineDataCopyGenerate(Block::iterator begin, Block::iterator end,
23092305
// surrounding the this block range.
23102306
unsigned copyDepth = getNestingDepth(&*begin);
23112307

2312-
LLVM_DEBUG(llvm::dbgs() << "Generating copies at depth " << copyDepth
2313-
<< "\n");
2314-
LLVM_DEBUG(llvm::dbgs() << "from begin: " << *begin << "\n");
2315-
LLVM_DEBUG(llvm::dbgs() << "to inclusive end: " << *std::prev(end) << "\n");
2308+
LDBG() << "Generating copies at depth " << copyDepth;
2309+
LDBG() << "from begin: "
2310+
<< OpWithFlags(&*begin, OpPrintingFlags().skipRegions());
2311+
LDBG() << "to inclusive end: "
2312+
<< OpWithFlags(&*std::prev(end), OpPrintingFlags().skipRegions());
23162313

23172314
// List of memory regions to copy for. We need a map vector to have a
23182315
// guaranteed iteration order to write test cases. CHECK-DAG doesn't help here
@@ -2349,21 +2346,19 @@ mlir::affine::affineDataCopyGenerate(Block::iterator begin, Block::iterator end,
23492346
return;
23502347

23512348
if (!memref.getParentRegion()->isAncestor(block->getParent())) {
2352-
LLVM_DEBUG(llvm::dbgs() << "memref definition is inside of the depth at "
2353-
"which copy-in/copy-out would happen\n");
2349+
LDBG() << "memref definition is inside of the depth at "
2350+
<< "which copy-in/copy-out would happen";
23542351
return;
23552352
}
23562353

23572354
// Compute the MemRefRegion accessed.
23582355
auto region = std::make_unique<MemRefRegion>(opInst->getLoc());
23592356
if (failed(region->compute(opInst, copyDepth, /*sliceState=*/nullptr,
23602357
/*addMemRefDimBounds=*/false))) {
2361-
LLVM_DEBUG(llvm::dbgs()
2362-
<< "Error obtaining memory region: semi-affine maps?\n");
2363-
LLVM_DEBUG(llvm::dbgs() << "over-approximating to the entire memref\n");
2358+
LDBG() << "Error obtaining memory region: semi-affine maps?";
2359+
LDBG() << "over-approximating to the entire memref";
23642360
if (!getFullMemRefAsRegion(opInst, copyDepth, region.get())) {
2365-
LLVM_DEBUG(
2366-
opInst->emitError("non-constant memref sizes not yet supported"));
2361+
LDBG() << "non-constant memref sizes not yet supported";
23672362
error = true;
23682363
return;
23692364
}
@@ -2392,13 +2387,11 @@ mlir::affine::affineDataCopyGenerate(Block::iterator begin, Block::iterator end,
23922387

23932388
// Perform a union with the existing region.
23942389
if (failed(it->second->unionBoundingBox(*region))) {
2395-
LLVM_DEBUG(llvm::dbgs()
2396-
<< "Memory region bounding box failed; "
2397-
"over-approximating to the entire memref\n");
2390+
LDBG() << "Memory region bounding box failed; "
2391+
<< "over-approximating to the entire memref";
23982392
// If the union fails, we will overapproximate.
23992393
if (!getFullMemRefAsRegion(opInst, copyDepth, region.get())) {
2400-
LLVM_DEBUG(opInst->emitError(
2401-
"non-constant memref sizes not yet supported"));
2394+
LDBG() << "non-constant memref sizes not yet supported";
24022395
error = true;
24032396
return true;
24042397
}
@@ -2428,8 +2421,7 @@ mlir::affine::affineDataCopyGenerate(Block::iterator begin, Block::iterator end,
24282421
});
24292422

24302423
if (error) {
2431-
LLVM_DEBUG(begin->emitError(
2432-
"copy generation failed for one or more memref's in this block\n"));
2424+
LDBG() << "copy generation failed for one or more memref's in this block";
24332425
return failure();
24342426
}
24352427

@@ -2466,8 +2458,7 @@ mlir::affine::affineDataCopyGenerate(Block::iterator begin, Block::iterator end,
24662458
processRegions(writeRegions);
24672459

24682460
if (!ret) {
2469-
LLVM_DEBUG(begin->emitError(
2470-
"copy generation failed for one or more memref's in this block\n"));
2461+
LDBG() << "copy generation failed for one or more memref's in this block";
24712462
return failure();
24722463
}
24732464

@@ -2608,7 +2599,7 @@ static AffineIfOp createSeparationCondition(MutableArrayRef<AffineForOp> loops,
26082599
/*boundFloorDivisor=*/nullptr,
26092600
/*ub=*/nullptr, &fullTileLbPos,
26102601
&fullTileUbPos)) {
2611-
LLVM_DEBUG(llvm::dbgs() << "Can't get constant diff pair for a loop\n");
2602+
LDBG() << "Can't get constant diff pair for a loop";
26122603
return nullptr;
26132604
}
26142605

@@ -2667,8 +2658,7 @@ createFullTiles(MutableArrayRef<AffineForOp> inputNest,
26672658
for (auto loop : inputNest) {
26682659
// TODO: straightforward to generalize to a non-unit stride.
26692660
if (loop.getStepAsInt() != 1) {
2670-
LLVM_DEBUG(llvm::dbgs()
2671-
<< "[tile separation] non-unit stride not implemented\n");
2661+
LDBG() << "[tile separation] non-unit stride not implemented";
26722662
return failure();
26732663
}
26742664
SmallVector<Operation *, 1> loopOp{loop.getOperation()};
@@ -2682,8 +2672,8 @@ createFullTiles(MutableArrayRef<AffineForOp> inputNest,
26822672
/*boundFloorDivisor=*/nullptr,
26832673
/*ub=*/nullptr, &lbPos, &ubPos) ||
26842674
lbPos == ubPos) {
2685-
LLVM_DEBUG(llvm::dbgs() << "[tile separation] Can't get constant diff / "
2686-
"equalities not yet handled\n");
2675+
LDBG() << "[tile separation] Can't get constant diff / "
2676+
<< "equalities not yet handled";
26872677
return failure();
26882678
}
26892679

@@ -2741,8 +2731,8 @@ mlir::affine::separateFullTiles(MutableArrayRef<AffineForOp> inputNest,
27412731
AffineIfOp ifOp = createSeparationCondition(inputNest, b);
27422732
if (!ifOp) {
27432733
fullTileLoops.front().erase();
2744-
LLVM_DEBUG(llvm::dbgs() << "All tiles are full tiles, or failure creating "
2745-
"separation condition\n");
2734+
LDBG() << "All tiles are full tiles, or failure creating "
2735+
<< "separation condition";
27462736
return failure();
27472737
}
27482738

0 commit comments

Comments
 (0)