@@ -249,6 +249,7 @@ bool MemRefDependenceGraph::init() {
249
249
// the memref.
250
250
DenseMap<Value, SetVector<unsigned >> memrefAccesses;
251
251
252
+ // Create graph nodes.
252
253
DenseMap<Operation *, unsigned > forToNodeMap;
253
254
for (Operation &op : block) {
254
255
if (auto forOp = dyn_cast<AffineForOp>(op)) {
@@ -300,11 +301,7 @@ bool MemRefDependenceGraph::init() {
300
301
// interface.
301
302
}
302
303
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 " );
308
305
309
306
// Add dependence edges between nodes which produce SSA values and their
310
307
// users. Load ops can be considered as the ones producing SSA values.
@@ -1556,9 +1553,9 @@ mlir::affine::computeSliceUnion(ArrayRef<Operation *> opsA,
1556
1553
FlatAffineValueConstraints sliceUnionCst;
1557
1554
assert (sliceUnionCst.getNumDimAndSymbolVars () == 0 );
1558
1555
std::vector<std::pair<Operation *, Operation *>> dependentOpPairs;
1559
- for (auto *i : opsA) {
1556
+ for (Operation *i : opsA) {
1560
1557
MemRefAccess srcAccess (i);
1561
- for (auto *j : opsB) {
1558
+ for (Operation *j : opsB) {
1562
1559
MemRefAccess dstAccess (j);
1563
1560
if (srcAccess.memref != dstAccess.memref )
1564
1561
continue ;
@@ -1587,7 +1584,7 @@ mlir::affine::computeSliceUnion(ArrayRef<Operation *> opsA,
1587
1584
1588
1585
// Compute slice bounds for 'srcAccess' and 'dstAccess'.
1589
1586
ComputationSliceState tmpSliceState;
1590
- mlir::affine::getComputationSliceState (i, j, & dependenceConstraints,
1587
+ mlir::affine::getComputationSliceState (i, j, dependenceConstraints,
1591
1588
loopDepth, isBackwardSlice,
1592
1589
&tmpSliceState);
1593
1590
@@ -1646,8 +1643,10 @@ mlir::affine::computeSliceUnion(ArrayRef<Operation *> opsA,
1646
1643
}
1647
1644
1648
1645
// Empty union.
1649
- if (sliceUnionCst.getNumDimAndSymbolVars () == 0 )
1646
+ if (sliceUnionCst.getNumDimAndSymbolVars () == 0 ) {
1647
+ LLVM_DEBUG (llvm::dbgs () << " empty slice union - unexpected\n " );
1650
1648
return SliceComputationResult::GenericFailure;
1649
+ }
1651
1650
1652
1651
// Gather loops surrounding ops from loop nest where slice will be inserted.
1653
1652
SmallVector<Operation *, 4 > ops;
@@ -1686,7 +1685,8 @@ mlir::affine::computeSliceUnion(ArrayRef<Operation *> opsA,
1686
1685
sliceUnion->ivs .clear ();
1687
1686
sliceUnionCst.getValues (0 , numSliceLoopIVs, &sliceUnion->ivs );
1688
1687
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.
1690
1690
sliceUnion->insertPoint =
1691
1691
isBackwardSlice
1692
1692
? surroundingLoops[loopDepth - 1 ].getBody ()->begin ()
@@ -1785,7 +1785,7 @@ const char *const kSliceFusionBarrierAttrName = "slice_fusion_barrier";
1785
1785
// the other loop nest's IVs, symbols and constants (using 'isBackwardsSlice').
1786
1786
void mlir::affine::getComputationSliceState (
1787
1787
Operation *depSourceOp, Operation *depSinkOp,
1788
- FlatAffineValueConstraints * dependenceConstraints, unsigned loopDepth,
1788
+ const FlatAffineValueConstraints & dependenceConstraints, unsigned loopDepth,
1789
1789
bool isBackwardSlice, ComputationSliceState *sliceState) {
1790
1790
// Get loop nest surrounding src operation.
1791
1791
SmallVector<AffineForOp, 4 > srcLoopIVs;
@@ -1804,30 +1804,28 @@ void mlir::affine::getComputationSliceState(
1804
1804
unsigned pos = isBackwardSlice ? numSrcLoopIVs + loopDepth : loopDepth;
1805
1805
unsigned num =
1806
1806
isBackwardSlice ? numDstLoopIVs - loopDepth : numSrcLoopIVs - loopDepth;
1807
- dependenceConstraints->projectOut (pos, num);
1807
+ FlatAffineValueConstraints sliceCst (dependenceConstraints);
1808
+ sliceCst.projectOut (pos, num);
1808
1809
1809
1810
// Add slice loop IV values to 'sliceState'.
1810
1811
unsigned offset = isBackwardSlice ? 0 : loopDepth;
1811
1812
unsigned numSliceLoopIVs = isBackwardSlice ? numSrcLoopIVs : numDstLoopIVs;
1812
- dependenceConstraints->getValues (offset, offset + numSliceLoopIVs,
1813
- &sliceState->ivs );
1813
+ sliceCst.getValues (offset, offset + numSliceLoopIVs, &sliceState->ivs );
1814
1814
1815
1815
// Set up lower/upper bound affine maps for the slice.
1816
1816
sliceState->lbs .resize (numSliceLoopIVs, AffineMap ());
1817
1817
sliceState->ubs .resize (numSliceLoopIVs, AffineMap ());
1818
1818
1819
1819
// 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 );
1823
1822
1824
1823
// Set up bound operands for the slice's lower and upper bounds.
1825
1824
SmallVector<Value, 4 > sliceBoundOperands;
1826
- unsigned numDimsAndSymbols = dependenceConstraints-> getNumDimAndSymbolVars ();
1825
+ unsigned numDimsAndSymbols = sliceCst. getNumDimAndSymbolVars ();
1827
1826
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));
1831
1829
}
1832
1830
1833
1831
// Give each bound its own copy of 'sliceBoundOperands' for subsequent
@@ -2055,16 +2053,18 @@ static std::optional<int64_t> getMemoryFootprintBytes(Block &block,
2055
2053
if (failed (
2056
2054
region->compute (opInst,
2057
2055
/* 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 ();
2059
2058
}
2060
2059
2061
2060
auto [it, inserted] = regions.try_emplace (region->memref );
2062
2061
if (inserted) {
2063
2062
it->second = std::move (region);
2064
2063
} else if (failed (it->second ->unionBoundingBox (*region))) {
2065
- return opInst->emitWarning (
2064
+ LLVM_DEBUG ( opInst->emitWarning (
2066
2065
" getMemoryFootprintBytes: unable to perform a union on a memory "
2067
- " region" );
2066
+ " region" ));
2067
+ return failure ();
2068
2068
}
2069
2069
return WalkResult::advance ();
2070
2070
});
0 commit comments