Skip to content

Commit 5da99d4

Browse files
committed
[OSSALifeComp] NFC: Extracted visit unreachable.
Extracted the new visitUnreachableLifetimeEnds static member of OSSALifetimeCompletion from the preexisting endLifetimeAtUnreachableBlocks which now calls through the former.
1 parent da87b8a commit 5da99d4

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

include/swift/SIL/OSSALifetimeCompletion.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ class OSSALifetimeCompletion {
8585
: LifetimeCompletion::AlreadyComplete;
8686
}
8787

88+
static void visitUnreachableLifetimeEnds(
89+
SILValue value, const SSAPrunedLiveness &liveness,
90+
llvm::function_ref<void(UnreachableInst *)> visit);
91+
8892
protected:
8993
bool analyzeAndUpdateLifetime(SILValue value, bool forceBoundaryCompletion);
9094
};

lib/SIL/Utils/OSSALifetimeCompletion.cpp

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,9 @@ static bool endLifetimeAtBoundary(SILValue value,
9999
return changed;
100100
}
101101

102-
static bool endLifetimeAtUnreachableBlocks(SILValue value,
103-
const SSAPrunedLiveness &liveness) {
102+
void OSSALifetimeCompletion::visitUnreachableLifetimeEnds(
103+
SILValue value, const SSAPrunedLiveness &liveness,
104+
llvm::function_ref<void(UnreachableInst *)> visit) {
104105
PrunedLivenessBoundary boundary;
105106
liveness.computeBoundary(boundary);
106107

@@ -119,20 +120,28 @@ static bool endLifetimeAtUnreachableBlocks(SILValue value,
119120
}
120121
// Forward CFG walk from the non-lifetime-ending boundary to the unreachable
121122
// instructions.
122-
bool changed = false;
123123
while (auto *block = deadEndBlocks.pop()) {
124124
if (block->succ_empty()) {
125125
// This assert will fail unless there are already lifetime-ending
126126
// instruction on all paths to normal function exits.
127127
auto *unreachable = cast<UnreachableInst>(block->getTerminator());
128-
SILBuilderWithScope builder(unreachable);
129-
endOSSALifetime(value, builder);
130-
changed = true;
128+
visit(unreachable);
131129
}
132130
for (auto *successor : block->getSuccessorBlocks()) {
133131
deadEndBlocks.pushIfNotVisited(successor);
134132
}
135133
}
134+
}
135+
136+
static bool endLifetimeAtUnreachableBlocks(SILValue value,
137+
const SSAPrunedLiveness &liveness) {
138+
bool changed = false;
139+
OSSALifetimeCompletion::visitUnreachableLifetimeEnds(
140+
value, liveness, [&](auto *unreachable) {
141+
SILBuilderWithScope builder(unreachable);
142+
endOSSALifetime(value, builder);
143+
changed = true;
144+
});
136145
return changed;
137146
}
138147

0 commit comments

Comments
 (0)