21
21
#include " mlir/Dialect/SCF/IR/SCF.h"
22
22
#include " mlir/IR/IRMapping.h"
23
23
#include " mlir/IR/IntegerSet.h"
24
+ #include " mlir/IR/OperationSupport.h"
24
25
#include " mlir/Transforms/GreedyPatternRewriteDriver.h"
25
26
#include " llvm/ADT/MapVector.h"
26
27
#include " llvm/Support/Debug.h"
28
+ #include " llvm/Support/DebugLog.h"
27
29
#include " llvm/Support/raw_ostream.h"
28
30
#include < optional>
29
31
@@ -365,12 +367,11 @@ checkIfHyperRectangular(MutableArrayRef<AffineForOp> input) {
365
367
if (input.size () <= 1 )
366
368
return success ();
367
369
if (failed (getIndexSet (ops, &cst))) {
368
- LLVM_DEBUG ( llvm::dbgs ( ) << " Index set computation failed!\n " ) ;
370
+ LDBG ( ) << " Index set computation failed!" ;
369
371
return failure ();
370
372
}
371
373
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!" ;
374
375
return failure ();
375
376
}
376
377
return success ();
@@ -385,14 +386,13 @@ static LogicalResult performPreTilingChecks(MutableArrayRef<AffineForOp> input,
385
386
386
387
if (llvm::any_of (input,
387
388
[](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" ;
390
390
return failure ();
391
391
}
392
392
393
393
// Check if the supplied `for` ops are all successively nested.
394
394
if (!isPerfectlyNested (input)) {
395
- LLVM_DEBUG ( llvm::dbgs ( ) << " input loops not perfectly nested" ) ;
395
+ LDBG ( ) << " input loops not perfectly nested" ;
396
396
return failure ();
397
397
}
398
398
@@ -1098,7 +1098,7 @@ LogicalResult mlir::affine::loopUnrollJamByFactor(AffineForOp forOp,
1098
1098
1099
1099
// If the trip count is lower than the unroll jam factor, no unroll jam.
1100
1100
if (mayBeConstantTripCount && *mayBeConstantTripCount < unrollJamFactor) {
1101
- LLVM_DEBUG ( llvm::dbgs ( ) << " [failed] trip count < unroll-jam factor\n " ) ;
1101
+ LDBG ( ) << " [failed] trip count < unroll-jam factor" ;
1102
1102
return failure ();
1103
1103
}
1104
1104
@@ -1766,9 +1766,7 @@ findHighestBlockForPlacement(const MemRefRegion ®ion, Block &block,
1766
1766
// We can't hoist past the definition of the memref being copied.
1767
1767
Value memref = region.memref ;
1768
1768
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" ;
1772
1770
break ;
1773
1771
}
1774
1772
@@ -1977,7 +1975,7 @@ static LogicalResult generateCopy(
1977
1975
auto memRefType = cast<MemRefType>(memref.getType ());
1978
1976
1979
1977
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" ;
1981
1979
return failure ();
1982
1980
}
1983
1981
@@ -1989,7 +1987,7 @@ static LogicalResult generateCopy(
1989
1987
1990
1988
unsigned rank = memRefType.getRank ();
1991
1989
if (rank == 0 ) {
1992
- LLVM_DEBUG ( llvm::dbgs ( ) << " Non-zero ranked memrefs supported\n " ) ;
1990
+ LDBG ( ) << " Non-zero ranked memrefs supported" ;
1993
1991
return failure ();
1994
1992
}
1995
1993
@@ -2001,29 +1999,27 @@ static LogicalResult generateCopy(
2001
1999
std::optional<int64_t > numElements =
2002
2000
region.getConstantBoundingSizeAndShape (&fastBufferShape, &lbs);
2003
2001
if (!numElements) {
2004
- LLVM_DEBUG ( llvm::dbgs ( ) << " Non-constant region size not supported\n " ) ;
2002
+ LDBG ( ) << " Non-constant region size not supported" ;
2005
2003
return failure ();
2006
2004
}
2007
2005
2008
2006
if (llvm::any_of (lbs, [](AffineMap lb) { return lb.getNumResults () > 1 ; })) {
2009
2007
// 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" ;
2012
2009
return failure ();
2013
2010
}
2014
2011
2015
2012
if (*numElements == 0 ) {
2016
- LLVM_DEBUG ( llvm::dbgs ( ) << " Nothing to copy\n " ) ;
2013
+ LDBG ( ) << " Nothing to copy" ;
2017
2014
return success ();
2018
2015
}
2019
2016
2020
2017
SmallVector<AffineMap, 4 > lbMaps (rank), ubMaps (rank);
2021
2018
for (unsigned i = 0 ; i < rank; ++i) {
2022
2019
region.getLowerAndUpperBound (i, lbMaps[i], ubMaps[i]);
2023
2020
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;
2027
2023
return failure ();
2028
2024
}
2029
2025
}
@@ -2122,7 +2118,7 @@ static LogicalResult generateCopy(
2122
2118
// TODO: use all stride levels once DmaStartOp is extended for
2123
2119
// multi-level strides.
2124
2120
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" ;
2126
2122
return failure ();
2127
2123
}
2128
2124
@@ -2309,10 +2305,11 @@ mlir::affine::affineDataCopyGenerate(Block::iterator begin, Block::iterator end,
2309
2305
// surrounding the this block range.
2310
2306
unsigned copyDepth = getNestingDepth (&*begin);
2311
2307
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 ());
2316
2313
2317
2314
// List of memory regions to copy for. We need a map vector to have a
2318
2315
// 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,
2349
2346
return ;
2350
2347
2351
2348
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" ;
2354
2351
return ;
2355
2352
}
2356
2353
2357
2354
// Compute the MemRefRegion accessed.
2358
2355
auto region = std::make_unique<MemRefRegion>(opInst->getLoc ());
2359
2356
if (failed (region->compute (opInst, copyDepth, /* sliceState=*/ nullptr ,
2360
2357
/* 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" ;
2364
2360
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" ;
2367
2362
error = true ;
2368
2363
return ;
2369
2364
}
@@ -2392,13 +2387,11 @@ mlir::affine::affineDataCopyGenerate(Block::iterator begin, Block::iterator end,
2392
2387
2393
2388
// Perform a union with the existing region.
2394
2389
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" ;
2398
2392
// If the union fails, we will overapproximate.
2399
2393
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" ;
2402
2395
error = true ;
2403
2396
return true ;
2404
2397
}
@@ -2428,8 +2421,7 @@ mlir::affine::affineDataCopyGenerate(Block::iterator begin, Block::iterator end,
2428
2421
});
2429
2422
2430
2423
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" ;
2433
2425
return failure ();
2434
2426
}
2435
2427
@@ -2466,8 +2458,7 @@ mlir::affine::affineDataCopyGenerate(Block::iterator begin, Block::iterator end,
2466
2458
processRegions (writeRegions);
2467
2459
2468
2460
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" ;
2471
2462
return failure ();
2472
2463
}
2473
2464
@@ -2608,7 +2599,7 @@ static AffineIfOp createSeparationCondition(MutableArrayRef<AffineForOp> loops,
2608
2599
/* boundFloorDivisor=*/ nullptr ,
2609
2600
/* ub=*/ nullptr , &fullTileLbPos,
2610
2601
&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" ;
2612
2603
return nullptr ;
2613
2604
}
2614
2605
@@ -2667,8 +2658,7 @@ createFullTiles(MutableArrayRef<AffineForOp> inputNest,
2667
2658
for (auto loop : inputNest) {
2668
2659
// TODO: straightforward to generalize to a non-unit stride.
2669
2660
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" ;
2672
2662
return failure ();
2673
2663
}
2674
2664
SmallVector<Operation *, 1 > loopOp{loop.getOperation ()};
@@ -2682,8 +2672,8 @@ createFullTiles(MutableArrayRef<AffineForOp> inputNest,
2682
2672
/* boundFloorDivisor=*/ nullptr ,
2683
2673
/* ub=*/ nullptr , &lbPos, &ubPos) ||
2684
2674
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" ;
2687
2677
return failure ();
2688
2678
}
2689
2679
@@ -2741,8 +2731,8 @@ mlir::affine::separateFullTiles(MutableArrayRef<AffineForOp> inputNest,
2741
2731
AffineIfOp ifOp = createSeparationCondition (inputNest, b);
2742
2732
if (!ifOp) {
2743
2733
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" ;
2746
2736
return failure ();
2747
2737
}
2748
2738
0 commit comments