2222#include " mlir/IR/IntegerSet.h"
2323#include " llvm/ADT/SetVector.h"
2424#include " llvm/Support/Debug.h"
25+ #include " llvm/Support/DebugLog.h"
2526#include " llvm/Support/raw_ostream.h"
2627#include < optional>
2728
@@ -241,7 +242,7 @@ addNodeToMDG(Operation *nodeOp, MemRefDependenceGraph &mdg,
241242}
242243
243244bool MemRefDependenceGraph::init () {
244- LLVM_DEBUG ( llvm::dbgs ( ) << " --- Initializing MDG ---\n " ) ;
245+ LDBG ( ) << " --- Initializing MDG ---" ;
245246 // Map from a memref to the set of ids of the nodes that have ops accessing
246247 // the memref.
247248 DenseMap<Value, SetVector<unsigned >> memrefAccesses;
@@ -288,16 +289,15 @@ bool MemRefDependenceGraph::init() {
288289 // Return false if non-handled/unknown region-holding ops are found. We
289290 // won't know what such ops do or what its regions mean; for e.g., it may
290291 // not be an imperative op.
291- LLVM_DEBUG (llvm::dbgs ()
292- << " MDG init failed; unknown region-holding op found!\n " );
292+ LDBG () << " MDG init failed; unknown region-holding op found!" ;
293293 return false ;
294294 }
295295 // We aren't creating nodes for memory-effect free ops either with no
296296 // regions (unless it has results being used) or those with branch op
297297 // interface.
298298 }
299299
300- LLVM_DEBUG ( llvm::dbgs ( ) << " Created " << nodes.size () << " nodes\n " ) ;
300+ LDBG ( ) << " Created " << nodes.size () << " nodes" ;
301301
302302 // Add dependence edges between nodes which produce SSA values and their
303303 // users. Load ops can be considered as the ones producing SSA values.
@@ -556,9 +556,8 @@ MemRefDependenceGraph::getFusedLoopNestInsertionPoint(unsigned srcId,
556556 gatherDefiningNodes (dstId, definingNodes);
557557 if (llvm::any_of (definingNodes,
558558 [&](unsigned id) { return hasDependencePath (srcId, id); })) {
559- LLVM_DEBUG (llvm::dbgs ()
560- << " Can't fuse: a defining op with a user in the dst "
561- " loop has dependence from the src loop\n " );
559+ LDBG () << " Can't fuse: a defining op with a user in the dst "
560+ << " loop has dependence from the src loop" ;
562561 return nullptr ;
563562 }
564563
@@ -957,28 +956,28 @@ std::optional<bool> ComputationSliceState::isSliceValid() const {
957956 FlatAffineValueConstraints srcConstraints;
958957 // TODO: Store the source's domain to avoid computation at each depth.
959958 if (failed (getSourceAsConstraints (srcConstraints))) {
960- LLVM_DEBUG ( llvm::dbgs ( ) << " Unable to compute source's domain\n " ) ;
959+ LDBG ( ) << " Unable to compute source's domain" ;
961960 return std::nullopt ;
962961 }
963962 // As the set difference utility currently cannot handle symbols in its
964963 // operands, validity of the slice cannot be determined.
965964 if (srcConstraints.getNumSymbolVars () > 0 ) {
966- LLVM_DEBUG ( llvm::dbgs ( ) << " Cannot handle symbols in source domain\n " ) ;
965+ LDBG ( ) << " Cannot handle symbols in source domain" ;
967966 return std::nullopt ;
968967 }
969968 // TODO: Handle local vars in the source domains while using the 'projectOut'
970969 // utility below. Currently, aligning is not done assuming that there will be
971970 // no local vars in the source domain.
972971 if (srcConstraints.getNumLocalVars () != 0 ) {
973- LLVM_DEBUG ( llvm::dbgs ( ) << " Cannot handle locals in source domain\n " ) ;
972+ LDBG ( ) << " Cannot handle locals in source domain" ;
974973 return std::nullopt ;
975974 }
976975
977976 // Create constraints for the slice loop nest that would be created if the
978977 // fusion succeeds.
979978 FlatAffineValueConstraints sliceConstraints;
980979 if (failed (getAsConstraints (&sliceConstraints))) {
981- LLVM_DEBUG ( llvm::dbgs ( ) << " Unable to compute slice's domain\n " ) ;
980+ LDBG ( ) << " Unable to compute slice's domain" ;
982981 return std::nullopt ;
983982 }
984983
@@ -987,19 +986,19 @@ std::optional<bool> ComputationSliceState::isSliceValid() const {
987986 sliceConstraints.projectOut (ivs.size (),
988987 sliceConstraints.getNumVars () - ivs.size ());
989988
990- LLVM_DEBUG ( llvm::dbgs ( ) << " Domain of the source of the slice:\n " );
991- LLVM_DEBUG ( srcConstraints. dump ());
992- LLVM_DEBUG ( llvm::dbgs () << " Domain of the slice if this fusion succeeds "
993- " (expressed in terms of its source's IVs):\n " );
994- LLVM_DEBUG ( sliceConstraints. dump ()) ;
989+ LDBG ( ) << " Domain of the source of the slice:\n "
990+ << " Source constraints: " << srcConstraints
991+ << " \n Domain of the slice if this fusion succeeds "
992+ << " (expressed in terms of its source's IVs):\n "
993+ << " Slice constraints: " << sliceConstraints;
995994
996995 // TODO: Store 'srcSet' to avoid recalculating for each depth.
997996 PresburgerSet srcSet (srcConstraints);
998997 PresburgerSet sliceSet (sliceConstraints);
999998 PresburgerSet diffSet = sliceSet.subtract (srcSet);
1000999
10011000 if (!diffSet.isIntegerEmpty ()) {
1002- LLVM_DEBUG ( llvm::dbgs ( ) << " Incorrect slice\n " ) ;
1001+ LDBG ( ) << " Incorrect slice" ;
10031002 return false ;
10041003 }
10051004 return true ;
@@ -1172,8 +1171,7 @@ LogicalResult MemRefRegion::compute(Operation *op, unsigned loopDepth,
11721171
11731172 unsigned rank = access.getRank ();
11741173
1175- LLVM_DEBUG (llvm::dbgs () << " MemRefRegion::compute: " << *op
1176- << " \n depth: " << loopDepth << " \n " ;);
1174+ LDBG () << " MemRefRegion::compute: " << *op << " depth: " << loopDepth;
11771175
11781176 // 0-d memrefs.
11791177 if (rank == 0 ) {
@@ -1236,7 +1234,7 @@ LogicalResult MemRefRegion::compute(Operation *op, unsigned loopDepth,
12361234 if (auto constVal = getConstantIntValue (symbol))
12371235 cst.addBound (BoundType::EQ, symbol, constVal.value ());
12381236 } else {
1239- LLVM_DEBUG ( llvm::dbgs ( ) << " unknown affine dimensional value" ) ;
1237+ LDBG ( ) << " unknown affine dimensional value" ;
12401238 return failure ();
12411239 }
12421240 }
@@ -1260,7 +1258,7 @@ LogicalResult MemRefRegion::compute(Operation *op, unsigned loopDepth,
12601258 // Add access function equalities to connect loop IVs to data dimensions.
12611259 if (failed (cst.composeMap (&accessValueMap))) {
12621260 op->emitError (" getMemRefRegion: compose affine map failed" );
1263- LLVM_DEBUG ( accessValueMap.getAffineMap (). dump () );
1261+ LDBG () << " Access map: " << accessValueMap.getAffineMap ();
12641262 return failure ();
12651263 }
12661264
@@ -1317,8 +1315,7 @@ LogicalResult MemRefRegion::compute(Operation *op, unsigned loopDepth,
13171315 }
13181316 cst.removeTrivialRedundancy ();
13191317
1320- LLVM_DEBUG (llvm::dbgs () << " Memory region:\n " );
1321- LLVM_DEBUG (cst.dump ());
1318+ LDBG () << " Memory region: " << cst;
13221319 return success ();
13231320}
13241321
@@ -1346,14 +1343,14 @@ std::optional<int64_t> MemRefRegion::getRegionSize() {
13461343 auto memRefType = cast<MemRefType>(memref.getType ());
13471344
13481345 if (!memRefType.getLayout ().isIdentity ()) {
1349- LLVM_DEBUG ( llvm::dbgs ( ) << " Non-identity layout map not yet supported\n " ) ;
1346+ LDBG ( ) << " Non-identity layout map not yet supported" ;
13501347 return false ;
13511348 }
13521349
13531350 // Compute the extents of the buffer.
13541351 std::optional<int64_t > numElements = getConstantBoundingSizeAndShape ();
13551352 if (!numElements) {
1356- LLVM_DEBUG ( llvm::dbgs ( ) << " Dynamic shapes not yet supported\n " ) ;
1353+ LDBG ( ) << " Dynamic shapes not yet supported" ;
13571354 return std::nullopt ;
13581355 }
13591356 auto eltSize = getMemRefIntOrFloatEltSizeInBytes (memRefType);
@@ -1397,8 +1394,7 @@ LogicalResult mlir::affine::boundCheckLoadOrStoreOp(LoadOrStoreOp loadOrStoreOp,
13971394 /* addMemRefDimBounds=*/ false )))
13981395 return success ();
13991396
1400- LLVM_DEBUG (llvm::dbgs () << " Memory region" );
1401- LLVM_DEBUG (region.getConstraints ()->dump ());
1397+ LDBG () << " Memory region: " << region.getConstraints ();
14021398
14031399 bool outOfBounds = false ;
14041400 unsigned rank = loadOrStoreOp.getMemRefType ().getRank ();
@@ -1558,7 +1554,7 @@ mlir::affine::computeSliceUnion(ArrayRef<Operation *> opsA,
15581554 // Check if 'loopDepth' exceeds nesting depth of src/dst ops.
15591555 if ((!isBackwardSlice && loopDepth > getNestingDepth (a)) ||
15601556 (isBackwardSlice && loopDepth > getNestingDepth (b))) {
1561- LLVM_DEBUG ( llvm::dbgs ( ) << " Invalid loop depth\n " ) ;
1557+ LDBG ( ) << " Invalid loop depth" ;
15621558 return SliceComputationResult::GenericFailure;
15631559 }
15641560
@@ -1571,7 +1567,7 @@ mlir::affine::computeSliceUnion(ArrayRef<Operation *> opsA,
15711567 &dependenceConstraints, /* dependenceComponents=*/ nullptr ,
15721568 /* allowRAR=*/ readReadAccesses);
15731569 if (result.value == DependenceResult::Failure) {
1574- LLVM_DEBUG ( llvm::dbgs ( ) << " Dependence check failed\n " ) ;
1570+ LDBG ( ) << " Dependence check failed" ;
15751571 return SliceComputationResult::GenericFailure;
15761572 }
15771573 if (result.value == DependenceResult::NoDependence)
@@ -1586,8 +1582,7 @@ mlir::affine::computeSliceUnion(ArrayRef<Operation *> opsA,
15861582 if (sliceUnionCst.getNumDimAndSymbolVars () == 0 ) {
15871583 // Initialize 'sliceUnionCst' with the bounds computed in previous step.
15881584 if (failed (tmpSliceState.getAsConstraints (&sliceUnionCst))) {
1589- LLVM_DEBUG (llvm::dbgs ()
1590- << " Unable to compute slice bound constraints\n " );
1585+ LDBG () << " Unable to compute slice bound constraints" ;
15911586 return SliceComputationResult::GenericFailure;
15921587 }
15931588 assert (sliceUnionCst.getNumDimAndSymbolVars () > 0 );
@@ -1597,8 +1592,7 @@ mlir::affine::computeSliceUnion(ArrayRef<Operation *> opsA,
15971592 // Compute constraints for 'tmpSliceState' in 'tmpSliceCst'.
15981593 FlatAffineValueConstraints tmpSliceCst;
15991594 if (failed (tmpSliceState.getAsConstraints (&tmpSliceCst))) {
1600- LLVM_DEBUG (llvm::dbgs ()
1601- << " Unable to compute slice bound constraints\n " );
1595+ LDBG () << " Unable to compute slice bound constraints" ;
16021596 return SliceComputationResult::GenericFailure;
16031597 }
16041598
@@ -1630,16 +1624,15 @@ mlir::affine::computeSliceUnion(ArrayRef<Operation *> opsA,
16301624 if (sliceUnionCst.getNumLocalVars () > 0 ||
16311625 tmpSliceCst.getNumLocalVars () > 0 ||
16321626 failed (sliceUnionCst.unionBoundingBox (tmpSliceCst))) {
1633- LLVM_DEBUG (llvm::dbgs ()
1634- << " Unable to compute union bounding box of slice bounds\n " );
1627+ LDBG () << " Unable to compute union bounding box of slice bounds" ;
16351628 return SliceComputationResult::GenericFailure;
16361629 }
16371630 }
16381631 }
16391632
16401633 // Empty union.
16411634 if (sliceUnionCst.getNumDimAndSymbolVars () == 0 ) {
1642- LLVM_DEBUG ( llvm::dbgs ( ) << " empty slice union - unexpected\n " ) ;
1635+ LDBG ( ) << " empty slice union - unexpected" ;
16431636 return SliceComputationResult::GenericFailure;
16441637 }
16451638
@@ -1652,7 +1645,7 @@ mlir::affine::computeSliceUnion(ArrayRef<Operation *> opsA,
16521645 unsigned innermostCommonLoopDepth =
16531646 getInnermostCommonLoopDepth (ops, &surroundingLoops);
16541647 if (loopDepth > innermostCommonLoopDepth) {
1655- LLVM_DEBUG ( llvm::dbgs ( ) << " Exceeds max loop depth\n " ) ;
1648+ LDBG ( ) << " Exceeds max loop depth" ;
16561649 return SliceComputationResult::GenericFailure;
16571650 }
16581651
@@ -1696,7 +1689,7 @@ mlir::affine::computeSliceUnion(ArrayRef<Operation *> opsA,
16961689 // that the slice is valid, otherwise return appropriate failure status.
16971690 std::optional<bool > isSliceValid = sliceUnion->isSliceValid ();
16981691 if (!isSliceValid) {
1699- LLVM_DEBUG ( llvm::dbgs ( ) << " Cannot determine if the slice is valid\n " ) ;
1692+ LDBG ( ) << " Cannot determine if the slice is valid" ;
17001693 return SliceComputationResult::GenericFailure;
17011694 }
17021695 if (!*isSliceValid)
@@ -2050,17 +2043,20 @@ static std::optional<int64_t> getMemoryFootprintBytes(Block &block,
20502043 if (failed (
20512044 region->compute (opInst,
20522045 /* loopDepth=*/ getNestingDepth (&*block.begin ())))) {
2053- LLVM_DEBUG (opInst->emitError (" error obtaining memory region" ));
2046+ LDBG () << " Error obtaining memory region" ;
2047+ opInst->emitError (" error obtaining memory region" );
20542048 return failure ();
20552049 }
20562050
20572051 auto [it, inserted] = regions.try_emplace (region->memref );
20582052 if (inserted) {
20592053 it->second = std::move (region);
20602054 } else if (failed (it->second ->unionBoundingBox (*region))) {
2061- LLVM_DEBUG (opInst->emitWarning (
2055+ LDBG () << " getMemoryFootprintBytes: unable to perform a union on a "
2056+ " memory region" ;
2057+ opInst->emitWarning (
20622058 " getMemoryFootprintBytes: unable to perform a union on a memory "
2063- " region" )) ;
2059+ " region" );
20642060 return failure ();
20652061 }
20662062 return WalkResult::advance ();
0 commit comments