@@ -172,7 +172,8 @@ static bool getFinalReleases(SILValue Box,
172
172
173
173
// If we have a copy value or a mark_uninitialized, add its uses to the work
174
174
// list and continue.
175
- if (isa<MarkUninitializedInst>(User) || isa<CopyValueInst>(User)) {
175
+ if (isa<MarkUninitializedInst>(User) || isa<CopyValueInst>(User) ||
176
+ isa<BeginBorrowInst>(User)) {
176
177
llvm::copy (cast<SingleValueInstruction>(User)->getUses (),
177
178
std::back_inserter (Worklist));
178
179
continue ;
@@ -385,12 +386,14 @@ static SILInstruction *recursivelyFindBoxOperandsPromotableToAddress(
385
386
// Projections are fine as well.
386
387
if (isa<StrongRetainInst>(User) || isa<StrongReleaseInst>(User) ||
387
388
isa<ProjectBoxInst>(User) || isa<DestroyValueInst>(User) ||
388
- (!inAppliedFunction && isa<DeallocBoxInst>(User)))
389
+ (!inAppliedFunction && isa<DeallocBoxInst>(User)) ||
390
+ isa<EndBorrowInst>(User))
389
391
continue ;
390
392
391
393
// If our user instruction is a copy_value or a mark_uninitialized, visit
392
394
// the users recursively.
393
- if (isa<MarkUninitializedInst>(User) || isa<CopyValueInst>(User)) {
395
+ if (isa<MarkUninitializedInst>(User) || isa<CopyValueInst>(User) ||
396
+ isa<BeginBorrowInst>(User)) {
394
397
llvm::copy (cast<SingleValueInstruction>(User)->getUses (),
395
398
std::back_inserter (Worklist));
396
399
continue ;
@@ -502,10 +505,12 @@ static void replaceProjectBoxUsers(SILValue HeapBox, SILValue StackBox) {
502
505
continue ;
503
506
}
504
507
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
+ }
509
514
}
510
515
}
511
516
@@ -578,8 +583,9 @@ static bool rewriteAllocBoxAsAllocStack(AllocBoxInst *ABI) {
578
583
while (!Worklist.empty ()) {
579
584
auto *User = Worklist.pop_back_val ();
580
585
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)) {
583
589
auto Inst = cast<SingleValueInstruction>(User);
584
590
llvm::transform (Inst->getUses (), std::back_inserter (Worklist),
585
591
[](Operand *Op) -> SILInstruction * {
@@ -592,7 +598,7 @@ static bool rewriteAllocBoxAsAllocStack(AllocBoxInst *ABI) {
592
598
593
599
assert (isa<StrongReleaseInst>(User) || isa<StrongRetainInst>(User) ||
594
600
isa<DeallocBoxInst>(User) || isa<ProjectBoxInst>(User) ||
595
- isa<DestroyValueInst>(User));
601
+ isa<DestroyValueInst>(User) || isa<EndBorrowInst>(User) );
596
602
597
603
User->eraseFromParent ();
598
604
}
@@ -934,6 +940,7 @@ specializeApplySite(SILOptFunctionBuilder &FuncBuilder, ApplySite Apply,
934
940
assert ((isa<SingleValueInstruction>(Box) && isa<AllocBoxInst>(Box) ||
935
941
isa<CopyValueInst>(Box) ||
936
942
isa<MarkUninitializedInst>(Box) ||
943
+ isa<BeginBorrowInst>(Box) ||
937
944
isa<SILFunctionArgument>(Box)) &&
938
945
" Expected either an alloc box or a copy of an alloc box or a "
939
946
" function argument" );
0 commit comments