@@ -51,8 +51,6 @@ class ShrinkBorrowScope {
5151 // / which is itself a deinit barrier.
5252 SmallPtrSet<SILBasicBlock *, 8 > barredBlocks;
5353
54- llvm::SmallDenseMap<ApplySite, size_t > transitiveUsesPerApplySite;
55-
5654 // The list of blocks to look for new points at which to insert end_borrows
5755 // in. A block must not be processed if all of its successors have not yet
5856 // been. For that reason, it is necessary to allow the same block to be
@@ -136,48 +134,16 @@ class ShrinkBorrowScope {
136134 }
137135 }
138136
139- size_t usesInApply (ApplySite apply) {
140- if (auto count = transitiveUsesPerApplySite.lookup (apply))
141- return count;
142- return 0 ;
143- }
144-
145137 bool canHoistOverInstruction (SILInstruction *instruction) {
146138 return tryHoistOverInstruction (instruction, /* rewrite=*/ false );
147139 }
148140
149141 bool tryHoistOverInstruction (SILInstruction *instruction, bool rewrite = true ) {
142+ if (instruction == introducer) {
143+ return false ;
144+ }
150145 if (users.contains (instruction)) {
151- if (auto apply = ApplySite::isa (instruction)) {
152- SmallVector<int , 2 > rewritableArgumentIndices;
153- auto count = apply.getNumArguments ();
154- for (unsigned index = 0 ; index < count; ++index) {
155- auto argument = apply.getArgument (index);
156- if (canReplaceValueWithBorrowedValue (argument)) {
157- rewritableArgumentIndices.push_back (index);
158- }
159- }
160- if (rewritableArgumentIndices.size () != usesInApply (apply)) {
161- return false ;
162- }
163- if (rewrite) {
164- // We can rewrite all the arguments which are transitive uses of the
165- // borrow.
166- for (auto index : rewritableArgumentIndices) {
167- auto argument = apply.getArgument (index);
168- auto borrowee = introducer->getOperand ();
169- if (auto *cvi = dyn_cast<CopyValueInst>(argument)) {
170- cvi->setOperand (borrowee);
171- modifiedCopyValueInsts.push_back (cvi);
172- madeChange = true ;
173- } else {
174- apply.setArgument (index, borrowee);
175- madeChange = true ;
176- }
177- }
178- }
179- return true ;
180- } else if (auto *bbi = dyn_cast<BeginBorrowInst>(instruction)) {
146+ if (auto *bbi = dyn_cast<BeginBorrowInst>(instruction)) {
181147 if (bbi->isLexical () &&
182148 canReplaceValueWithBorrowedValue (bbi->getOperand ())) {
183149 if (rewrite) {
@@ -234,9 +200,6 @@ bool ShrinkBorrowScope::populateUsers() {
234200 for (auto *use : uses) {
235201 auto *user = use->getUser ();
236202 users.insert (user);
237- if (auto apply = ApplySite::isa (user)) {
238- ++transitiveUsesPerApplySite[apply];
239- }
240203 }
241204 return true ;
242205}
@@ -298,20 +261,12 @@ void ShrinkBorrowScope::findBarriers() {
298261 // At that time, it was checked that this block (along with all that
299262 // successor's other predecessors) had a terminator over which the borrow
300263 // scope could be shrunk. Shrink it now.
301- #ifndef NDEBUG
302- bool hoisted =
303- #endif
304- tryHoistOverInstruction (block->getTerminator ());
305- #ifndef NDEBUG
264+ bool hoisted = tryHoistOverInstruction (block->getTerminator ());
306265 assert (hoisted);
307- # endif
266+ ( void )hoisted;
308267 }
309268 SILInstruction *barrier = nullptr ;
310269 while ((instruction = instruction->getPreviousInstruction ())) {
311- if (instruction == introducer) {
312- barrier = instruction;
313- break ;
314- }
315270 if (!tryHoistOverInstruction (instruction)) {
316271 barrier = instruction;
317272 break ;
0 commit comments