@@ -96,9 +96,6 @@ using namespace mlir;
96
96
97
97
namespace {
98
98
99
- using BlockingUsesMap =
100
- llvm::MapVector<Operation *, SmallPtrSet<OpOperand *, 4 >>;
101
-
102
99
// / Information computed during promotion analysis used to perform actual
103
100
// / promotion.
104
101
struct MemorySlotPromotionInfo {
@@ -109,7 +106,7 @@ struct MemorySlotPromotionInfo {
109
106
// / its uses, it is because the defining ops of the blocking uses requested
110
107
// / it. The defining ops therefore must also have blocking uses or be the
111
108
// / starting point of the bloccking uses.
112
- BlockingUsesMap userToBlockingUses;
109
+ DenseMap<Operation *, SmallPtrSet<OpOperand *, 4 >> userToBlockingUses;
113
110
};
114
111
115
112
// / Computes information for basic slot promotion. This will check that direct
@@ -132,7 +129,8 @@ class MemorySlotPromotionAnalyzer {
132
129
// / uses (typically, removing its users because it will delete itself to
133
130
// / resolve its own blocking uses). This will fail if one of the transitive
134
131
// / 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);
136
134
137
135
// / Computes in which blocks the value stored in the slot is actually used,
138
136
// / meaning blocks leading to a load. This method uses `definingBlocks`, the
@@ -235,7 +233,7 @@ Value MemorySlotPromoter::getLazyDefaultValue() {
235
233
}
236
234
237
235
LogicalResult MemorySlotPromotionAnalyzer::computeBlockingUses (
238
- BlockingUsesMap &userToBlockingUses) {
236
+ DenseMap<Operation *, SmallPtrSet<OpOperand *, 4 >> &userToBlockingUses) {
239
237
// The promotion of an operation may require the promotion of further
240
238
// operations (typically, removing operations that use an operation that must
241
239
// delete itself). We thus need to start from the use of the slot pointer and
@@ -245,7 +243,7 @@ LogicalResult MemorySlotPromotionAnalyzer::computeBlockingUses(
245
243
// use it.
246
244
for (OpOperand &use : slot.ptr .getUses ()) {
247
245
SmallPtrSet<OpOperand *, 4 > &blockingUses =
248
- userToBlockingUses[ use.getOwner ()] ;
246
+ userToBlockingUses. getOrInsertDefault ( use.getOwner ()) ;
249
247
blockingUses.insert (&use);
250
248
}
251
249
@@ -283,7 +281,7 @@ LogicalResult MemorySlotPromotionAnalyzer::computeBlockingUses(
283
281
assert (llvm::is_contained (user->getResults (), blockingUse->get ()));
284
282
285
283
SmallPtrSetImpl<OpOperand *> &newUserBlockingUseSet =
286
- userToBlockingUses[ blockingUse->getOwner ()] ;
284
+ userToBlockingUses. getOrInsertDefault ( blockingUse->getOwner ()) ;
287
285
newUserBlockingUseSet.insert (blockingUse);
288
286
}
289
287
}
@@ -518,16 +516,14 @@ void MemorySlotPromoter::computeReachingDefInRegion(Region *region,
518
516
}
519
517
520
518
void MemorySlotPromoter::removeBlockingUses () {
521
- llvm::SmallVector<Operation *> usersToRemoveUses (
522
- llvm::make_first_range (info.userToBlockingUses ));
523
- // The uses need to be traversed in *reverse dominance* order to ensure that
524
- // transitive replacements are performed correctly.
525
- llvm::sort (usersToRemoveUses, [&](Operation *lhs, Operation *rhs) {
526
- return dominance.properlyDominates (rhs, lhs);
527
- });
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);
528
524
529
525
llvm::SmallVector<Operation *> toErase;
530
- for (Operation *toPromote : usersToRemoveUses ) {
526
+ for (Operation *toPromote : llvm::reverse (sortedUsersToRemoveUses) ) {
531
527
if (auto toPromoteMemOp = dyn_cast<PromotableMemOpInterface>(toPromote)) {
532
528
Value reachingDef = reachingDefs.lookup (toPromoteMemOp);
533
529
// If no reaching definition is known, this use is outside the reach of
0 commit comments