@@ -55,7 +55,16 @@ class ShrinkBorrowScope {
5555 llvm::SmallVector<std::pair<SILBasicBlock *, SILInstruction *>>
5656 barrierInstructions;
5757
58- SmallPtrSet<SILBasicBlock *, 8 > blocksToEndAtTop;
58+ // / Blocks above which the borrow scope cannot be hoisted.
59+ // /
60+ // / Consequently, these blocks must begin with end_borrow %borrow.
61+ // /
62+ // / Note: These blocks aren't barrier blocks. Rather the borrow scope is
63+ // / barred from being hoisted out of them. That could happen because
64+ // / one of its predecessors is a barrier block (i.e. has a successor
65+ // / which is live) or because one of its predecessors has a terminator
66+ // / which is itself a deinit barrier.
67+ SmallPtrSet<SILBasicBlock *, 8 > barredBlocks;
5968
6069 llvm::SmallDenseMap<ApplySite, size_t > transitiveUsesPerApplySite;
6170
@@ -268,7 +277,7 @@ void ShrinkBorrowScope::findBarriers() {
268277 continue ;
269278 }
270279 for (auto *successor : block->getSuccessorBlocks ()) {
271- blocksToEndAtTop .erase (successor);
280+ barredBlocks .erase (successor);
272281 }
273282
274283 // We either have processed all successors of block or else it is a block
@@ -294,7 +303,7 @@ void ShrinkBorrowScope::findBarriers() {
294303 barrierInstructions.push_back ({block, barrier});
295304 } else {
296305 deadBlocks.insert (block);
297- blocksToEndAtTop .insert (block);
306+ barredBlocks .insert (block);
298307 for (auto *predecessor : block->getPredecessorBlocks ()) {
299308 worklist.push_back (predecessor);
300309 }
@@ -316,7 +325,7 @@ void ShrinkBorrowScope::rewrite() {
316325
317326 // Insert the new end_borrow instructions that occur at the beginning of
318327 // blocks which we couldn't hoist out of.
319- for (auto *block : blocksToEndAtTop ) {
328+ for (auto *block : barredBlocks ) {
320329 auto *insertionPoint = &*block->begin ();
321330 createEndBorrow (insertionPoint);
322331 }
0 commit comments