@@ -249,6 +249,7 @@ bool MemRefDependenceGraph::init() {
249249 // the memref.
250250 DenseMap<Value, SetVector<unsigned >> memrefAccesses;
251251
252+ // Create graph nodes.
252253 DenseMap<Operation *, unsigned > forToNodeMap;
253254 for (Operation &op : block) {
254255 if (auto forOp = dyn_cast<AffineForOp>(op)) {
@@ -300,11 +301,7 @@ bool MemRefDependenceGraph::init() {
300301 // interface.
301302 }
302303
303- for (auto &idAndNode : nodes) {
304- LLVM_DEBUG (llvm::dbgs () << " Create node " << idAndNode.first << " for:\n "
305- << *(idAndNode.second .op ) << " \n " );
306- (void )idAndNode;
307- }
304+ LLVM_DEBUG (llvm::dbgs () << " Created " << nodes.size () << " nodes\n " );
308305
309306 // Add dependence edges between nodes which produce SSA values and their
310307 // users. Load ops can be considered as the ones producing SSA values.
@@ -1556,9 +1553,9 @@ mlir::affine::computeSliceUnion(ArrayRef<Operation *> opsA,
15561553 FlatAffineValueConstraints sliceUnionCst;
15571554 assert (sliceUnionCst.getNumDimAndSymbolVars () == 0 );
15581555 std::vector<std::pair<Operation *, Operation *>> dependentOpPairs;
1559- for (auto *i : opsA) {
1556+ for (Operation *i : opsA) {
15601557 MemRefAccess srcAccess (i);
1561- for (auto *j : opsB) {
1558+ for (Operation *j : opsB) {
15621559 MemRefAccess dstAccess (j);
15631560 if (srcAccess.memref != dstAccess.memref )
15641561 continue ;
@@ -1587,7 +1584,7 @@ mlir::affine::computeSliceUnion(ArrayRef<Operation *> opsA,
15871584
15881585 // Compute slice bounds for 'srcAccess' and 'dstAccess'.
15891586 ComputationSliceState tmpSliceState;
1590- mlir::affine::getComputationSliceState (i, j, & dependenceConstraints,
1587+ mlir::affine::getComputationSliceState (i, j, dependenceConstraints,
15911588 loopDepth, isBackwardSlice,
15921589 &tmpSliceState);
15931590
@@ -1646,8 +1643,10 @@ mlir::affine::computeSliceUnion(ArrayRef<Operation *> opsA,
16461643 }
16471644
16481645 // Empty union.
1649- if (sliceUnionCst.getNumDimAndSymbolVars () == 0 )
1646+ if (sliceUnionCst.getNumDimAndSymbolVars () == 0 ) {
1647+ LLVM_DEBUG (llvm::dbgs () << " empty slice union - unexpected\n " );
16501648 return SliceComputationResult::GenericFailure;
1649+ }
16511650
16521651 // Gather loops surrounding ops from loop nest where slice will be inserted.
16531652 SmallVector<Operation *, 4 > ops;
@@ -1686,7 +1685,8 @@ mlir::affine::computeSliceUnion(ArrayRef<Operation *> opsA,
16861685 sliceUnion->ivs .clear ();
16871686 sliceUnionCst.getValues (0 , numSliceLoopIVs, &sliceUnion->ivs );
16881687
1689- // Set loop nest insertion point to block start at 'loopDepth'.
1688+ // Set loop nest insertion point to block start at 'loopDepth' for forward
1689+ // slices, while at the end for backward slices.
16901690 sliceUnion->insertPoint =
16911691 isBackwardSlice
16921692 ? surroundingLoops[loopDepth - 1 ].getBody ()->begin ()
@@ -1785,7 +1785,7 @@ const char *const kSliceFusionBarrierAttrName = "slice_fusion_barrier";
17851785// the other loop nest's IVs, symbols and constants (using 'isBackwardsSlice').
17861786void mlir::affine::getComputationSliceState (
17871787 Operation *depSourceOp, Operation *depSinkOp,
1788- FlatAffineValueConstraints * dependenceConstraints, unsigned loopDepth,
1788+ const FlatAffineValueConstraints & dependenceConstraints, unsigned loopDepth,
17891789 bool isBackwardSlice, ComputationSliceState *sliceState) {
17901790 // Get loop nest surrounding src operation.
17911791 SmallVector<AffineForOp, 4 > srcLoopIVs;
@@ -1804,30 +1804,28 @@ void mlir::affine::getComputationSliceState(
18041804 unsigned pos = isBackwardSlice ? numSrcLoopIVs + loopDepth : loopDepth;
18051805 unsigned num =
18061806 isBackwardSlice ? numDstLoopIVs - loopDepth : numSrcLoopIVs - loopDepth;
1807- dependenceConstraints->projectOut (pos, num);
1807+ FlatAffineValueConstraints sliceCst (dependenceConstraints);
1808+ sliceCst.projectOut (pos, num);
18081809
18091810 // Add slice loop IV values to 'sliceState'.
18101811 unsigned offset = isBackwardSlice ? 0 : loopDepth;
18111812 unsigned numSliceLoopIVs = isBackwardSlice ? numSrcLoopIVs : numDstLoopIVs;
1812- dependenceConstraints->getValues (offset, offset + numSliceLoopIVs,
1813- &sliceState->ivs );
1813+ sliceCst.getValues (offset, offset + numSliceLoopIVs, &sliceState->ivs );
18141814
18151815 // Set up lower/upper bound affine maps for the slice.
18161816 sliceState->lbs .resize (numSliceLoopIVs, AffineMap ());
18171817 sliceState->ubs .resize (numSliceLoopIVs, AffineMap ());
18181818
18191819 // Get bounds for slice IVs in terms of other IVs, symbols, and constants.
1820- dependenceConstraints->getSliceBounds (offset, numSliceLoopIVs,
1821- depSourceOp->getContext (),
1822- &sliceState->lbs , &sliceState->ubs );
1820+ sliceCst.getSliceBounds (offset, numSliceLoopIVs, depSourceOp->getContext (),
1821+ &sliceState->lbs , &sliceState->ubs );
18231822
18241823 // Set up bound operands for the slice's lower and upper bounds.
18251824 SmallVector<Value, 4 > sliceBoundOperands;
1826- unsigned numDimsAndSymbols = dependenceConstraints-> getNumDimAndSymbolVars ();
1825+ unsigned numDimsAndSymbols = sliceCst. getNumDimAndSymbolVars ();
18271826 for (unsigned i = 0 ; i < numDimsAndSymbols; ++i) {
1828- if (i < offset || i >= offset + numSliceLoopIVs) {
1829- sliceBoundOperands.push_back (dependenceConstraints->getValue (i));
1830- }
1827+ if (i < offset || i >= offset + numSliceLoopIVs)
1828+ sliceBoundOperands.push_back (sliceCst.getValue (i));
18311829 }
18321830
18331831 // Give each bound its own copy of 'sliceBoundOperands' for subsequent
@@ -2055,16 +2053,18 @@ static std::optional<int64_t> getMemoryFootprintBytes(Block &block,
20552053 if (failed (
20562054 region->compute (opInst,
20572055 /* loopDepth=*/ getNestingDepth (&*block.begin ())))) {
2058- return opInst->emitError (" error obtaining memory region\n " );
2056+ LLVM_DEBUG (opInst->emitError (" error obtaining memory region" ));
2057+ return failure ();
20592058 }
20602059
20612060 auto [it, inserted] = regions.try_emplace (region->memref );
20622061 if (inserted) {
20632062 it->second = std::move (region);
20642063 } else if (failed (it->second ->unionBoundingBox (*region))) {
2065- return opInst->emitWarning (
2064+ LLVM_DEBUG ( opInst->emitWarning (
20662065 " getMemoryFootprintBytes: unable to perform a union on a memory "
2067- " region" );
2066+ " region" ));
2067+ return failure ();
20682068 }
20692069 return WalkResult::advance ();
20702070 });
0 commit comments