@@ -172,7 +172,8 @@ static bool getFinalReleases(SILValue Box,
172172
173173 // If we have a copy value or a mark_uninitialized, add its uses to the work
174174 // list and continue.
175- if (isa<MarkUninitializedInst>(User) || isa<CopyValueInst>(User)) {
175+ if (isa<MarkUninitializedInst>(User) || isa<CopyValueInst>(User) ||
176+ isa<BeginBorrowInst>(User)) {
176177 llvm::copy (cast<SingleValueInstruction>(User)->getUses (),
177178 std::back_inserter (Worklist));
178179 continue ;
@@ -385,12 +386,14 @@ static SILInstruction *recursivelyFindBoxOperandsPromotableToAddress(
385386 // Projections are fine as well.
386387 if (isa<StrongRetainInst>(User) || isa<StrongReleaseInst>(User) ||
387388 isa<ProjectBoxInst>(User) || isa<DestroyValueInst>(User) ||
388- (!inAppliedFunction && isa<DeallocBoxInst>(User)))
389+ (!inAppliedFunction && isa<DeallocBoxInst>(User)) ||
390+ isa<EndBorrowInst>(User))
389391 continue ;
390392
391393 // If our user instruction is a copy_value or a mark_uninitialized, visit
392394 // the users recursively.
393- if (isa<MarkUninitializedInst>(User) || isa<CopyValueInst>(User)) {
395+ if (isa<MarkUninitializedInst>(User) || isa<CopyValueInst>(User) ||
396+ isa<BeginBorrowInst>(User)) {
394397 llvm::copy (cast<SingleValueInstruction>(User)->getUses (),
395398 std::back_inserter (Worklist));
396399 continue ;
@@ -502,10 +505,12 @@ static void replaceProjectBoxUsers(SILValue HeapBox, SILValue StackBox) {
502505 continue ;
503506 }
504507
505- auto *CVI = dyn_cast<CopyValueInst>(Op->getUser ());
506- if (!CVI)
507- continue ;
508- llvm::copy (CVI->getUses (), std::back_inserter (Worklist));
508+ auto *User = Op->getUser ();
509+ if (isa<MarkUninitializedInst>(User) || isa<CopyValueInst>(User) ||
510+ isa<BeginBorrowInst>(User)) {
511+ llvm::copy (cast<SingleValueInstruction>(User)->getUses (),
512+ std::back_inserter (Worklist));
513+ }
509514 }
510515}
511516
@@ -578,8 +583,9 @@ static bool rewriteAllocBoxAsAllocStack(AllocBoxInst *ABI) {
578583 while (!Worklist.empty ()) {
579584 auto *User = Worklist.pop_back_val ();
580585
581- // Look through any mark_uninitialized, copy_values.
582- if (isa<MarkUninitializedInst>(User) || isa<CopyValueInst>(User)) {
586+ // Look through any mark_uninitialized, copy_values, begin_borrow.
587+ if (isa<MarkUninitializedInst>(User) || isa<CopyValueInst>(User) ||
588+ isa<BeginBorrowInst>(User)) {
583589 auto Inst = cast<SingleValueInstruction>(User);
584590 llvm::transform (Inst->getUses (), std::back_inserter (Worklist),
585591 [](Operand *Op) -> SILInstruction * {
@@ -592,7 +598,7 @@ static bool rewriteAllocBoxAsAllocStack(AllocBoxInst *ABI) {
592598
593599 assert (isa<StrongReleaseInst>(User) || isa<StrongRetainInst>(User) ||
594600 isa<DeallocBoxInst>(User) || isa<ProjectBoxInst>(User) ||
595- isa<DestroyValueInst>(User));
601+ isa<DestroyValueInst>(User) || isa<EndBorrowInst>(User) );
596602
597603 User->eraseFromParent ();
598604 }
@@ -934,6 +940,7 @@ specializeApplySite(SILOptFunctionBuilder &FuncBuilder, ApplySite Apply,
934940 assert ((isa<SingleValueInstruction>(Box) && isa<AllocBoxInst>(Box) ||
935941 isa<CopyValueInst>(Box) ||
936942 isa<MarkUninitializedInst>(Box) ||
943+ isa<BeginBorrowInst>(Box) ||
937944 isa<SILFunctionArgument>(Box)) &&
938945 " Expected either an alloc box or a copy of an alloc box or a "
939946 " function argument" );
0 commit comments