Skip to content

Commit 208743c

Browse files
committed
[ShrinkBorrowScope] Replaced map with set.
The keys weren't used.
1 parent c0dda93 commit 208743c

File tree

1 file changed

+10
-16
lines changed

1 file changed

+10
-16
lines changed

lib/SILOptimizer/Utils/ShrinkBorrowScope.cpp

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,8 @@ struct Usage final {
7474
/// i.e. copied lifetime of the introducer.
7575
SmallPtrSet<SILInstruction *, 16> users;
7676
// The instructions from which the shrinking starts, the scope ending
77-
// instructions, keyed off the block in which they appear.
78-
llvm::SmallDenseMap<SILBasicBlock *, SILInstruction *> ends;
79-
80-
bool containsEnd(SILInstruction *end) const {
81-
auto iterator = ends.find(end->getParent());
82-
return iterator != ends.end() && iterator->second == end;
83-
};
77+
// instructions.
78+
llvm::SmallSetVector<SILInstruction *, 4> ends;
8479

8580
Usage(){};
8681
Usage(Usage const &) = delete;
@@ -95,13 +90,12 @@ bool findUsage(Context const &context, Usage &usage) {
9590
llvm::SmallVector<SILInstruction *, 16> scopeEndingInsts;
9691
context.borrowedValue.getLocalScopeEndingInstructions(scopeEndingInsts);
9792

98-
// Form a map of the scopeEndingInsts, keyed off the block they occur in.
93+
// Add all the end_borrows to the collection of ends.
9994
for (auto *instruction : scopeEndingInsts) {
10095
// If a scope ending instruction is not an end_borrow, bail out.
10196
if (!isa<EndBorrowInst>(instruction))
10297
return false;
103-
auto *block = instruction->getParent();
104-
usage.ends[block] = instruction;
98+
usage.ends.insert(instruction);
10599
}
106100

107101
SmallVector<Operand *, 16> uses;
@@ -163,8 +157,8 @@ class DataFlow final {
163157
reachability(&context.function, *this) {
164158
// Seed reachability with the scope ending uses from which the backwards
165159
// data flow will begin.
166-
for (auto pair : uses.ends) {
167-
reachability.initLastUse(pair.second);
160+
for (auto *end : uses.ends) {
161+
reachability.initLastUse(end);
168162
}
169163
}
170164
DataFlow(DataFlow const &) = delete;
@@ -394,11 +388,11 @@ bool Rewriter::run() {
394388

395389
if (madeChange) {
396390
// Remove all the original end_borrow instructions.
397-
for (auto pair : uses.ends) {
398-
if (reusedEndBorrowInsts.contains(pair.second)) {
391+
for (auto *end : uses.ends) {
392+
if (reusedEndBorrowInsts.contains(end)) {
399393
continue;
400394
}
401-
context.deleter.forceDelete(pair.getSecond());
395+
context.deleter.forceDelete(end);
402396
}
403397
}
404398

@@ -407,7 +401,7 @@ bool Rewriter::run() {
407401

408402
bool Rewriter::createEndBorrow(SILInstruction *insertionPoint) {
409403
if (auto *ebi = dyn_cast<EndBorrowInst>(insertionPoint)) {
410-
if (uses.containsEnd(insertionPoint)) {
404+
if (uses.ends.contains(insertionPoint)) {
411405
reusedEndBorrowInsts.insert(insertionPoint);
412406
return false;
413407
}

0 commit comments

Comments
 (0)