Skip to content

Commit 001c417

Browse files
committed
[NFC] OwnedLifetimeCan: Record new destroys.
Add them to a small vector. For now, do nothing with them.
1 parent 4a397cc commit 001c417

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

include/swift/SILOptimizer/Utils/CanonicalizeOSSALifetime.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,8 @@ class CanonicalizeOSSALifetime final {
488488
llvm::function_ref<void(SILInstruction *, PrunedLiveness::LifetimeEnding)>
489489
visitor);
490490

491-
void insertDestroysOnBoundary(PrunedLivenessBoundary const &boundary);
491+
void insertDestroysOnBoundary(PrunedLivenessBoundary const &boundary,
492+
SmallVectorImpl<DestroyValueInst *> &destroys);
492493

493494
void rewriteCopies();
494495
};

lib/SILOptimizer/Utils/CanonicalizeOSSALifetime.cpp

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -941,10 +941,12 @@ void CanonicalizeOSSALifetime::findExtendedBoundary(
941941

942942
/// Create a new destroy_value instruction before the specified instruction and
943943
/// record it as a final consume.
944-
static void insertDestroyBeforeInstruction(SILInstruction *nextInstruction,
945-
SILValue currentDef,
946-
CanonicalOSSAConsumeInfo &consumes,
947-
InstModCallbacks &callbacks) {
944+
static void
945+
insertDestroyBeforeInstruction(SILInstruction *nextInstruction,
946+
SILValue currentDef,
947+
CanonicalOSSAConsumeInfo &consumes,
948+
SmallVectorImpl<DestroyValueInst *> &destroys,
949+
InstModCallbacks &callbacks) {
948950
// OSSALifetimeCompletion: This conditional clause can be deleted with
949951
// complete lifetimes.
950952
if (consumes.isUnreachableLifetimeEnd(nextInstruction)) {
@@ -976,6 +978,7 @@ static void insertDestroyBeforeInstruction(SILInstruction *nextInstruction,
976978
callbacks.createdNewInst(dvi);
977979
consumes.recordFinalConsume(dvi);
978980
++NumDestroysGenerated;
981+
destroys.push_back(dvi);
979982
}
980983

981984
/// Inserts destroys along the boundary where needed and records all final
@@ -987,7 +990,8 @@ static void insertDestroyBeforeInstruction(SILInstruction *nextInstruction,
987990
/// - The postdominating consumes cannot be within nested loops.
988991
/// - Any blocks in nested loops are now marked LiveOut.
989992
void CanonicalizeOSSALifetime::insertDestroysOnBoundary(
990-
PrunedLivenessBoundary const &boundary) {
993+
PrunedLivenessBoundary const &boundary,
994+
SmallVectorImpl<DestroyValueInst *> &newDestroys) {
991995
BasicBlockSet seenMergePoints(getCurrentDef()->getFunction());
992996
for (auto *instruction : boundary.lastUsers) {
993997
if (destroys.contains(instruction)) {
@@ -1009,7 +1013,7 @@ void CanonicalizeOSSALifetime::insertDestroysOnBoundary(
10091013
}
10101014
auto *insertionPoint = &*successor->begin();
10111015
insertDestroyBeforeInstruction(insertionPoint, getCurrentDef(),
1012-
consumes, getCallbacks());
1016+
consumes, newDestroys, getCallbacks());
10131017
LLVM_DEBUG(llvm::dbgs() << " Destroy after terminator "
10141018
<< *instruction << " at beginning of ";
10151019
successor->printID(llvm::dbgs(), false);
@@ -1019,7 +1023,7 @@ void CanonicalizeOSSALifetime::insertDestroysOnBoundary(
10191023
}
10201024
auto *insertionPoint = instruction->getNextInstruction();
10211025
insertDestroyBeforeInstruction(insertionPoint, getCurrentDef(), consumes,
1022-
getCallbacks());
1026+
newDestroys, getCallbacks());
10231027
LLVM_DEBUG(llvm::dbgs()
10241028
<< " Destroy at last use " << insertionPoint << "\n");
10251029
continue;
@@ -1028,22 +1032,22 @@ void CanonicalizeOSSALifetime::insertDestroysOnBoundary(
10281032
for (auto *edgeDestination : boundary.boundaryEdges) {
10291033
auto *insertionPoint = &*edgeDestination->begin();
10301034
insertDestroyBeforeInstruction(insertionPoint, getCurrentDef(), consumes,
1031-
getCallbacks());
1035+
newDestroys, getCallbacks());
10321036
LLVM_DEBUG(llvm::dbgs() << " Destroy on edge " << edgeDestination << "\n");
10331037
}
10341038
for (auto *def : boundary.deadDefs) {
10351039
if (auto *arg = dyn_cast<SILArgument>(def)) {
10361040
auto *insertionPoint = &*arg->getParent()->begin();
10371041
insertDestroyBeforeInstruction(insertionPoint, getCurrentDef(), consumes,
1038-
getCallbacks());
1042+
newDestroys, getCallbacks());
10391043
LLVM_DEBUG(llvm::dbgs()
10401044
<< " Destroy after dead def arg " << arg << "\n");
10411045
} else {
10421046
auto *instruction = cast<SILInstruction>(def);
10431047
auto *insertionPoint = instruction->getNextInstruction();
10441048
assert(insertionPoint && "def instruction was a terminator?!");
10451049
insertDestroyBeforeInstruction(insertionPoint, getCurrentDef(), consumes,
1046-
getCallbacks());
1050+
newDestroys, getCallbacks());
10471051
LLVM_DEBUG(llvm::dbgs()
10481052
<< " Destroy after dead def inst " << instruction << "\n");
10491053
}
@@ -1235,8 +1239,9 @@ void CanonicalizeOSSALifetime::rewriteLifetimes() {
12351239
findExtendedBoundary(originalBoundary, extendedBoundary);
12361240
}
12371241

1242+
SmallVector<DestroyValueInst *> newDestroys;
12381243
// Step 5: insert destroys and record consumes
1239-
insertDestroysOnBoundary(extendedBoundary);
1244+
insertDestroysOnBoundary(extendedBoundary, newDestroys);
12401245
// Step 6: rewrite copies and delete extra destroys
12411246
rewriteCopies();
12421247

0 commit comments

Comments
 (0)