@@ -492,8 +492,13 @@ class AvailableValueAggregator {
492
492
// / ownership is enabled.
493
493
void addMissingDestroysForCopiedValues (LoadBorrowInst *li, SILValue newVal,
494
494
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);
497
502
};
498
503
499
504
} // end anonymous namespace
@@ -958,8 +963,10 @@ AvailableValueAggregator::addMissingDestroysForCopiedValues(LoadInst *li,
958
963
return nullptr ;
959
964
}
960
965
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
+
963
970
ValueLifetimeAnalysis::Frontier lifetimeFrontier;
964
971
SmallPtrSet<SILBasicBlock *, 8 > visitedBlocks;
965
972
SmallVector<SILBasicBlock *, 8 > leakingBlocks;
@@ -1124,14 +1131,14 @@ void AvailableValueAggregator::addHandOffCopyDestroysForPhis(LoadBorrowInst *lbi
1124
1131
auto errorKind = ownership::ErrorBehaviorKind::ReturnFalse;
1125
1132
LinearLifetimeChecker checker (visitedBlocks, deadEndBlocks);
1126
1133
auto error = checker.checkValue (
1127
- phiArg, {BranchPropagatedUser (&lbi ->getAllOperands ()[0 ])}, {},
1134
+ phiArg, {BranchPropagatedUser (&load ->getAllOperands ()[0 ])}, {},
1128
1135
errorKind, &leakingBlocks);
1129
1136
1130
1137
if (!error.getFoundError ()) {
1131
1138
// If we did not find an error, then our copy_value must be strongly
1132
1139
// control equivalent as our load_borrow. So just insert a destroy_value
1133
1140
// for the copy_value.
1134
- auto next = std::next (lbi ->getIterator ());
1141
+ auto next = std::next (load ->getIterator ());
1135
1142
SILBuilderWithScope builder (next);
1136
1143
builder.emitDestroyValueOperation (next->getLoc (), phiArg);
1137
1144
continue ;
@@ -1142,7 +1149,7 @@ void AvailableValueAggregator::addHandOffCopyDestroysForPhis(LoadBorrowInst *lbi
1142
1149
// this if we found a loop since our leaking blocks will lifetime extend the
1143
1150
// value over the loop.
1144
1151
if (!error.getFoundOverConsume ()) {
1145
- auto next = std::next (lbi ->getIterator ());
1152
+ auto next = std::next (load ->getIterator ());
1146
1153
SILBuilderWithScope builder (next);
1147
1154
builder.emitDestroyValueOperation (next->getLoc (), phiArg);
1148
1155
}
0 commit comments