Skip to content

Commit 6af0b6d

Browse files
committed
Use ScopedAddressValue in PrunedLiveness
to handle scoped addresses properly
1 parent b52ccce commit 6af0b6d

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

lib/SIL/Utils/PrunedLiveness.cpp

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -136,14 +136,12 @@ InnerBorrowKind PrunedLiveness::updateForBorrowingOperand(Operand *operand) {
136136
AddressUseKind PrunedLiveness::checkAndUpdateInteriorPointer(Operand *operand) {
137137
assert(operand->getOperandOwnership() == OperandOwnership::InteriorPointer);
138138

139-
if (auto *svi = dyn_cast<SingleValueInstruction>(operand->getUser())) {
140-
if (auto scopedAddress = ScopedAddressValue(svi)) {
141-
scopedAddress.visitScopeEndingUses([this](Operand *end) {
142-
updateForUse(end->getUser(), /*lifetimeEnding*/ false);
143-
return true;
144-
});
145-
return AddressUseKind::NonEscaping;
146-
}
139+
if (auto scopedAddress = ScopedAddressValue::forUse(operand)) {
140+
scopedAddress.visitScopeEndingUses([this](Operand *end) {
141+
updateForUse(end->getUser(), /*lifetimeEnding*/ false);
142+
return true;
143+
});
144+
return AddressUseKind::NonEscaping;
147145
}
148146
// FIXME: findTransitiveUses should be a visitor so we're not recursively
149147
// allocating use vectors and potentially merging the use points.
@@ -152,6 +150,10 @@ AddressUseKind PrunedLiveness::checkAndUpdateInteriorPointer(Operand *operand) {
152150
for (auto *use : uses) {
153151
updateForUse(use->getUser(), /*lifetimeEnding*/ false);
154152
}
153+
if (uses.empty()) {
154+
// Handle a dead address
155+
updateForUse(operand->getUser(), /*lifetimeEnding*/ false);
156+
}
155157
return useKind;
156158
}
157159

@@ -303,6 +305,16 @@ SimpleLiveRangeSummary PrunedLiveRange<LivenessWithDefs>::updateForDef(SILValue
303305
});
304306
break;
305307
}
308+
case OperandOwnership::TrivialUse: {
309+
if (auto scopedAddress = ScopedAddressValue::forUse(use)) {
310+
scopedAddress.visitScopeEndingUses([this](Operand *end) {
311+
updateForUse(end->getUser(), /*lifetimeEnding*/false);
312+
return true;
313+
});
314+
}
315+
updateForUse(use->getUser(), /*lifetimeEnding*/false);
316+
break;
317+
}
306318
default:
307319
updateForUse(use->getUser(), use->isLifetimeEnding());
308320
break;

0 commit comments

Comments
 (0)