Skip to content

Commit 6861b31

Browse files
committed
Make PrunedLiveness::computeSimple one-level transitive
Computing simple liveness is distinct from computing transitive liveness. But for safety and consistency, always handle the first level of liveness transitively. This way, computeSimple can be used on guaranteed values that need OSSA lifetime fixup. Simple liveness just means that *inner* borrow and address scopes are assumed to be complete. This utility is still only used conservatively because OSSA lifetime completion is not yet enabled. But, in the future, computeSimple can be used in the common case.
1 parent 6346bf5 commit 6861b31

File tree

3 files changed

+23
-6
lines changed

3 files changed

+23
-6
lines changed

include/swift/SIL/PrunedLiveness.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ class PrunedLiveness {
457457
/// like an instantaneous use. But if \p operand "borrows" a value for the
458458
/// duration of a scoped address (store_borrow), then update liveness for the
459459
/// entire scope. This assumes that nested OSSA lifetimes are complete.
460-
void checkAndUpdateInteriorPointer(Operand *operand);
460+
AddressUseKind checkAndUpdateInteriorPointer(Operand *operand);
461461

462462
/// Update this liveness to extend across the given liveness.
463463
void extendAcrossLiveness(PrunedLiveness &otherLiveness);

lib/SIL/Utils/OwnershipUtils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1087,7 +1087,7 @@ bool AddressOwnership::areUsesWithinLifetime(
10871087
SILValue root = base.getOwnershipReferenceRoot();
10881088
BorrowedValue borrow(root);
10891089
if (borrow)
1090-
return borrow.areUsesWithinExtendedTransitiveScope(uses, &deadEndBlocks);
1090+
return borrow.areUsesWithinExtendedScope(uses, &deadEndBlocks);
10911091

10921092
// --- A reference with no borrow scope! Currently happens for project_box.
10931093

lib/SIL/Utils/PrunedLiveness.cpp

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ InnerBorrowKind PrunedLiveness::updateForBorrowingOperand(Operand *operand) {
133133
return InnerBorrowKind::Contained;
134134
}
135135

136-
void PrunedLiveness::checkAndUpdateInteriorPointer(Operand *operand) {
136+
AddressUseKind PrunedLiveness::checkAndUpdateInteriorPointer(Operand *operand) {
137137
assert(operand->getOperandOwnership() == OperandOwnership::InteriorPointer);
138138

139139
if (auto *svi = dyn_cast<SingleValueInstruction>(operand->getUser())) {
@@ -142,10 +142,17 @@ void PrunedLiveness::checkAndUpdateInteriorPointer(Operand *operand) {
142142
updateForUse(end->getUser(), /*lifetimeEnding*/ false);
143143
return true;
144144
});
145-
return;
145+
return AddressUseKind::NonEscaping;
146146
}
147147
}
148-
updateForUse(operand->getUser(), /*lifetimeEnding*/ false);
148+
// FIXME: findTransitiveUses should be a visitor so we're not recursively
149+
// allocating use vectors and potentially merging the use points.
150+
SmallVector<Operand *, 8> uses;
151+
auto useKind = InteriorPointerOperand(operand).findTransitiveUses(&uses);
152+
for (auto *use : uses) {
153+
updateForUse(use->getUser(), /*lifetimeEnding*/ false);
154+
}
155+
return useKind;
149156
}
150157

151158
void PrunedLiveness::extendAcrossLiveness(PrunedLiveness &otherLivesness) {
@@ -276,8 +283,18 @@ SimpleLiveRangeSummary PrunedLiveRange<LivenessWithDefs>::updateForDef(SILValue
276283
summary.meet(AddressUseKind::PointerEscape);
277284
break;
278285
case OperandOwnership::InteriorPointer:
279-
checkAndUpdateInteriorPointer(use);
286+
summary.meet(checkAndUpdateInteriorPointer(use));
280287
break;
288+
case OperandOwnership::ForwardingBorrow: {
289+
ForwardingOperand(use).visitForwardedValues([&](SILValue result) {
290+
// Do not include transitive uses with 'none' ownership
291+
if (result->getOwnershipKind() != OwnershipKind::None) {
292+
updateForDef(result);
293+
}
294+
return true;
295+
});
296+
break;
297+
}
281298
default:
282299
updateForUse(use->getUser(), use->isLifetimeEnding());
283300
break;

0 commit comments

Comments
 (0)