@@ -96,9 +96,6 @@ using namespace mlir;
9696
9797namespace {
9898
99- using BlockingUsesMap =
100- llvm::MapVector<Operation *, SmallPtrSet<OpOperand *, 4 >>;
101-
10299// / Information computed during promotion analysis used to perform actual
103100// / promotion.
104101struct MemorySlotPromotionInfo {
@@ -109,7 +106,7 @@ struct MemorySlotPromotionInfo {
109106 // / its uses, it is because the defining ops of the blocking uses requested
110107 // / it. The defining ops therefore must also have blocking uses or be the
111108 // / starting point of the bloccking uses.
112- BlockingUsesMap userToBlockingUses;
109+ DenseMap<Operation *, SmallPtrSet<OpOperand *, 4 >> userToBlockingUses;
113110};
114111
115112// / Computes information for basic slot promotion. This will check that direct
@@ -132,7 +129,8 @@ class MemorySlotPromotionAnalyzer {
132129 // / uses (typically, removing its users because it will delete itself to
133130 // / resolve its own blocking uses). This will fail if one of the transitive
134131 // / users cannot remove a requested use, and should prevent promotion.
135- LogicalResult computeBlockingUses (BlockingUsesMap &userToBlockingUses);
132+ LogicalResult computeBlockingUses (
133+ DenseMap<Operation *, SmallPtrSet<OpOperand *, 4 >> &userToBlockingUses);
136134
137135 // / Computes in which blocks the value stored in the slot is actually used,
138136 // / meaning blocks leading to a load. This method uses `definingBlocks`, the
@@ -235,7 +233,7 @@ Value MemorySlotPromoter::getLazyDefaultValue() {
235233}
236234
237235LogicalResult MemorySlotPromotionAnalyzer::computeBlockingUses (
238- BlockingUsesMap &userToBlockingUses) {
236+ DenseMap<Operation *, SmallPtrSet<OpOperand *, 4 >> &userToBlockingUses) {
239237 // The promotion of an operation may require the promotion of further
240238 // operations (typically, removing operations that use an operation that must
241239 // delete itself). We thus need to start from the use of the slot pointer and
@@ -245,7 +243,7 @@ LogicalResult MemorySlotPromotionAnalyzer::computeBlockingUses(
245243 // use it.
246244 for (OpOperand &use : slot.ptr .getUses ()) {
247245 SmallPtrSet<OpOperand *, 4 > &blockingUses =
248- userToBlockingUses[ use.getOwner ()] ;
246+ userToBlockingUses. getOrInsertDefault ( use.getOwner ()) ;
249247 blockingUses.insert (&use);
250248 }
251249
@@ -283,7 +281,7 @@ LogicalResult MemorySlotPromotionAnalyzer::computeBlockingUses(
283281 assert (llvm::is_contained (user->getResults (), blockingUse->get ()));
284282
285283 SmallPtrSetImpl<OpOperand *> &newUserBlockingUseSet =
286- userToBlockingUses[ blockingUse->getOwner ()] ;
284+ userToBlockingUses. getOrInsertDefault ( blockingUse->getOwner ()) ;
287285 newUserBlockingUseSet.insert (blockingUse);
288286 }
289287 }
@@ -518,21 +516,14 @@ void MemorySlotPromoter::computeReachingDefInRegion(Region *region,
518516}
519517
520518void MemorySlotPromoter::removeBlockingUses () {
521- llvm::SmallVector<Operation *> usersToRemoveUses (
522- llvm::make_first_range (info.userToBlockingUses ));
523-
524- // The uses need to be traversed in *reverse dominance* order to ensure that
525- // transitive replacements are performed correctly.
526- // NOTE: The order can be non-deterministic, due to a pointer comparision, but
527- // this has no effect on the result of the pattern. This is necessary to get a
528- // strict weak order relation.
529- llvm::sort (usersToRemoveUses, [&](Operation *lhs, Operation *rhs) {
530- return dominance.properlyDominates (rhs, lhs) ||
531- (!dominance.properlyDominates (lhs, rhs) && rhs < lhs);
532- });
519+ llvm::SetVector<Operation *> usersToRemoveUses;
520+ for (auto &user : llvm::make_first_range (info.userToBlockingUses ))
521+ usersToRemoveUses.insert (user);
522+ SetVector<Operation *> sortedUsersToRemoveUses =
523+ mlir::topologicalSort (usersToRemoveUses);
533524
534525 llvm::SmallVector<Operation *> toErase;
535- for (Operation *toPromote : usersToRemoveUses ) {
526+ for (Operation *toPromote : llvm::reverse (sortedUsersToRemoveUses) ) {
536527 if (auto toPromoteMemOp = dyn_cast<PromotableMemOpInterface>(toPromote)) {
537528 Value reachingDef = reachingDefs.lookup (toPromoteMemOp);
538529 // If no reaching definition is known, this use is outside the reach of
0 commit comments