Skip to content

Commit aa8ccaf

Browse files
committed
[OwnedLifetimeCan] Prune fewer debug_values.
Use the more precise areUsesWithinBoundary API (which takes dead-end blocks into account). This requires first updating liveness with the newly created destroys.
1 parent 001c417 commit aa8ccaf

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

include/swift/SILOptimizer/Utils/CanonicalizeOSSALifetime.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ class CanonicalizeOSSALifetime final {
491491
void insertDestroysOnBoundary(PrunedLivenessBoundary const &boundary,
492492
SmallVectorImpl<DestroyValueInst *> &destroys);
493493

494-
void rewriteCopies();
494+
void rewriteCopies(SmallVectorImpl<DestroyValueInst *> const &destroys);
495495
};
496496

497497
} // end namespace swift

lib/SILOptimizer/Utils/CanonicalizeOSSALifetime.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1077,7 +1077,8 @@ void swift::copyLiveUse(Operand *use, InstModCallbacks &instModCallbacks) {
10771077
/// Revisit the def-use chain of currentDef. Mark unneeded original
10781078
/// copies and destroys for deletion. Insert new copies for interior uses that
10791079
/// require ownership of the used operand.
1080-
void CanonicalizeOSSALifetime::rewriteCopies() {
1080+
void CanonicalizeOSSALifetime::rewriteCopies(
1081+
SmallVectorImpl<DestroyValueInst *> const &newDestroys) {
10811082
assert(getCurrentDef()->getOwnershipKind() == OwnershipKind::Owned);
10821083

10831084
InstructionSetVector instsToDelete(getCurrentDef()->getFunction());
@@ -1163,11 +1164,17 @@ void CanonicalizeOSSALifetime::rewriteCopies() {
11631164
assert(!consumes.hasUnclaimedConsumes());
11641165

11651166
if (pruneDebugMode) {
1167+
for (auto *destroy : newDestroys) {
1168+
liveness->updateForUse(destroy, /*lifetimeEnding=*/true);
1169+
}
11661170
for (auto *dvi : debugValues) {
1167-
if (!liveness->isWithinBoundary(dvi)) {
1168-
LLVM_DEBUG(llvm::dbgs() << " Removing debug_value: " << *dvi);
1169-
deleter.forceDelete(dvi);
1171+
if (liveness->areUsesWithinBoundary(
1172+
{&dvi->getOperandRef()},
1173+
deadEndBlocksAnalysis->get(getCurrentDef()->getFunction()))) {
1174+
continue;
11701175
}
1176+
LLVM_DEBUG(llvm::dbgs() << " Removing debug_value: " << *dvi);
1177+
deleter.forceDelete(dvi);
11711178
}
11721179
}
11731180

@@ -1243,7 +1250,7 @@ void CanonicalizeOSSALifetime::rewriteLifetimes() {
12431250
// Step 5: insert destroys and record consumes
12441251
insertDestroysOnBoundary(extendedBoundary, newDestroys);
12451252
// Step 6: rewrite copies and delete extra destroys
1246-
rewriteCopies();
1253+
rewriteCopies(newDestroys);
12471254

12481255
clear();
12491256
}

0 commit comments

Comments
 (0)