Skip to content

Commit 16ea9fa

Browse files
authored
Merge pull request #28277 from gottesmm/pr-fe75266370825e5d95381c70f6bf20f16b738542
2 parents bf78d4a + b30efa7 commit 16ea9fa

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

lib/SILOptimizer/Mandatory/PredictableMemOpt.cpp

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -492,8 +492,13 @@ class AvailableValueAggregator {
492492
/// ownership is enabled.
493493
void addMissingDestroysForCopiedValues(LoadBorrowInst *li, SILValue newVal,
494494
const SmallBitVector &instsToSkip);
495-
void addHandOffCopyDestroysForPhis(LoadBorrowInst *li, SILValue newVal,
496-
SmallBitVector &instsToSkipOut);
495+
496+
/// As a result of us using the SSA updater, insert hand off copy/destroys at
497+
/// each phi and make sure that intermediate phis do not leak by inserting
498+
/// destroys along paths that go through the intermediate phi that do not also
499+
/// go through the
500+
void addHandOffCopyDestroysForPhis(SILInstruction *load, SILValue newVal,
501+
SmallBitVector &instsToSkipOut);
497502
};
498503

499504
} // end anonymous namespace
@@ -958,8 +963,10 @@ AvailableValueAggregator::addMissingDestroysForCopiedValues(LoadInst *li,
958963
return nullptr;
959964
}
960965

961-
void AvailableValueAggregator::addHandOffCopyDestroysForPhis(LoadBorrowInst *lbi, SILValue newVal,
962-
SmallBitVector &instsToSkip) {
966+
void AvailableValueAggregator::addHandOffCopyDestroysForPhis(
967+
SILInstruction *load, SILValue newVal, SmallBitVector &instsToSkip) {
968+
assert(isa<LoadBorrowInst>(load) || isa<LoadInst>(load));
969+
963970
ValueLifetimeAnalysis::Frontier lifetimeFrontier;
964971
SmallPtrSet<SILBasicBlock *, 8> visitedBlocks;
965972
SmallVector<SILBasicBlock *, 8> leakingBlocks;
@@ -1124,14 +1131,14 @@ void AvailableValueAggregator::addHandOffCopyDestroysForPhis(LoadBorrowInst *lbi
11241131
auto errorKind = ownership::ErrorBehaviorKind::ReturnFalse;
11251132
LinearLifetimeChecker checker(visitedBlocks, deadEndBlocks);
11261133
auto error = checker.checkValue(
1127-
phiArg, {BranchPropagatedUser(&lbi->getAllOperands()[0])}, {},
1134+
phiArg, {BranchPropagatedUser(&load->getAllOperands()[0])}, {},
11281135
errorKind, &leakingBlocks);
11291136

11301137
if (!error.getFoundError()) {
11311138
// If we did not find an error, then our copy_value must be strongly
11321139
// control equivalent as our load_borrow. So just insert a destroy_value
11331140
// for the copy_value.
1134-
auto next = std::next(lbi->getIterator());
1141+
auto next = std::next(load->getIterator());
11351142
SILBuilderWithScope builder(next);
11361143
builder.emitDestroyValueOperation(next->getLoc(), phiArg);
11371144
continue;
@@ -1142,7 +1149,7 @@ void AvailableValueAggregator::addHandOffCopyDestroysForPhis(LoadBorrowInst *lbi
11421149
// this if we found a loop since our leaking blocks will lifetime extend the
11431150
// value over the loop.
11441151
if (!error.getFoundOverConsume()) {
1145-
auto next = std::next(lbi->getIterator());
1152+
auto next = std::next(load->getIterator());
11461153
SILBuilderWithScope builder(next);
11471154
builder.emitDestroyValueOperation(next->getLoc(), phiArg);
11481155
}

0 commit comments

Comments
 (0)