@@ -74,13 +74,8 @@ struct Usage final {
74
74
// / i.e. copied lifetime of the introducer.
75
75
SmallPtrSet<SILInstruction *, 16 > users;
76
76
// 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;
84
79
85
80
Usage (){};
86
81
Usage (Usage const &) = delete ;
@@ -95,13 +90,12 @@ bool findUsage(Context const &context, Usage &usage) {
95
90
llvm::SmallVector<SILInstruction *, 16 > scopeEndingInsts;
96
91
context.borrowedValue .getLocalScopeEndingInstructions (scopeEndingInsts);
97
92
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 .
99
94
for (auto *instruction : scopeEndingInsts) {
100
95
// If a scope ending instruction is not an end_borrow, bail out.
101
96
if (!isa<EndBorrowInst>(instruction))
102
97
return false ;
103
- auto *block = instruction->getParent ();
104
- usage.ends [block] = instruction;
98
+ usage.ends .insert (instruction);
105
99
}
106
100
107
101
SmallVector<Operand *, 16 > uses;
@@ -163,8 +157,8 @@ class DataFlow final {
163
157
reachability (&context.function, *this ) {
164
158
// Seed reachability with the scope ending uses from which the backwards
165
159
// 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 );
168
162
}
169
163
}
170
164
DataFlow (DataFlow const &) = delete;
@@ -394,11 +388,11 @@ bool Rewriter::run() {
394
388
395
389
if (madeChange) {
396
390
// 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 )) {
399
393
continue ;
400
394
}
401
- context.deleter .forceDelete (pair. getSecond () );
395
+ context.deleter .forceDelete (end );
402
396
}
403
397
}
404
398
@@ -407,7 +401,7 @@ bool Rewriter::run() {
407
401
408
402
bool Rewriter::createEndBorrow (SILInstruction *insertionPoint) {
409
403
if (auto *ebi = dyn_cast<EndBorrowInst>(insertionPoint)) {
410
- if (uses.containsEnd (insertionPoint)) {
404
+ if (uses.ends . contains (insertionPoint)) {
411
405
reusedEndBorrowInsts.insert (insertionPoint);
412
406
return false ;
413
407
}
0 commit comments