Skip to content

Commit 17e2492

Browse files
committed
[NFC] LifetimeCompletion: Note boundary kind.
When visiting an availability boundary, note what kind of end is involved. For now, there's only one.
1 parent 0d67d60 commit 17e2492

File tree

3 files changed

+33
-18
lines changed

3 files changed

+33
-18
lines changed

include/swift/SIL/OSSALifetimeCompletion.h

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,15 @@ class OSSALifetimeCompletion {
120120
DoNotAllowLeaks = false,
121121
};
122122

123-
static void
124-
visitAvailabilityBoundary(SILValue value, AllowLeaks_t allowLeaks,
125-
const SSAPrunedLiveness &liveness,
126-
llvm::function_ref<void(SILInstruction *)> visit);
123+
enum class LifetimeEnd : uint8_t {
124+
/// The lifetime ends at the boundary.
125+
Boundary,
126+
};
127+
128+
static void visitAvailabilityBoundary(
129+
SILValue value, AllowLeaks_t allowLeaks,
130+
const SSAPrunedLiveness &liveness,
131+
llvm::function_ref<void(SILInstruction *, LifetimeEnd end)> visit);
127132

128133
protected:
129134
bool analyzeAndUpdateLifetime(SILValue value, Boundary boundary);

lib/SIL/Utils/OSSALifetimeCompletion.cpp

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@
5858

5959
using namespace swift;
6060

61-
static SILInstruction *endOSSALifetime(SILValue value, SILBuilder &builder) {
61+
static SILInstruction *endOSSALifetime(SILValue value,
62+
OSSALifetimeCompletion::LifetimeEnd end,
63+
SILBuilder &builder) {
6264
auto loc =
6365
RegularLocation::getAutoGeneratedLocation(builder.getInsertionPointLoc());
6466
if (value->getOwnershipKind() == OwnershipKind::Owned) {
@@ -81,14 +83,16 @@ static bool endLifetimeAtLivenessBoundary(SILValue value,
8183
!= PrunedLiveness::LifetimeEndingUse) {
8284
changed = true;
8385
SILBuilderWithScope::insertAfter(lastUser, [value](SILBuilder &builder) {
84-
endOSSALifetime(value, builder);
86+
endOSSALifetime(value, OSSALifetimeCompletion::LifetimeEnd::Boundary,
87+
builder);
8588
});
8689
}
8790
}
8891
for (SILBasicBlock *edge : boundary.boundaryEdges) {
8992
changed = true;
9093
SILBuilderWithScope builder(edge->begin());
91-
endOSSALifetime(value, builder);
94+
endOSSALifetime(value, OSSALifetimeCompletion::LifetimeEnd::Boundary,
95+
builder);
9296
}
9397
for (SILNode *deadDef : boundary.deadDefs) {
9498
SILInstruction *next = nullptr;
@@ -99,7 +103,8 @@ static bool endLifetimeAtLivenessBoundary(SILValue value,
99103
}
100104
changed = true;
101105
SILBuilderWithScope builder(next);
102-
endOSSALifetime(value, builder);
106+
endOSSALifetime(value, OSSALifetimeCompletion::LifetimeEnd::Boundary,
107+
builder);
103108
}
104109
return changed;
105110
}
@@ -151,9 +156,11 @@ class AvailabilityBoundaryVisitor {
151156
void propagateAvailablity(Result &result);
152157

153158
/// Visit the terminators of blocks on the boundary of availability.
154-
void
155-
visitAvailabilityBoundary(Result const &result,
156-
llvm::function_ref<void(SILInstruction *)> visit);
159+
void visitAvailabilityBoundary(
160+
Result const &result,
161+
llvm::function_ref<void(SILInstruction *,
162+
OSSALifetimeCompletion::LifetimeEnd)>
163+
visit);
157164

158165
struct State {
159166
enum Value : uint8_t {
@@ -300,7 +307,10 @@ void AvailabilityBoundaryVisitor::propagateAvailablity(Result &result) {
300307
}
301308

302309
void AvailabilityBoundaryVisitor::visitAvailabilityBoundary(
303-
Result const &result, llvm::function_ref<void(SILInstruction *)> visit) {
310+
Result const &result,
311+
llvm::function_ref<void(SILInstruction *,
312+
OSSALifetimeCompletion::LifetimeEnd end)>
313+
visit) {
304314
for (auto *block : region) {
305315
auto available = result.getState(block) == State::Available;
306316
if (!available) {
@@ -323,14 +333,15 @@ void AvailabilityBoundaryVisitor::visitAvailabilityBoundary(
323333
}
324334
assert(hasUnavailableSuccessor() ||
325335
isa<UnreachableInst>(block->getTerminator()));
326-
visit(block->getTerminator());
336+
visit(block->getTerminator(),
337+
OSSALifetimeCompletion::LifetimeEnd::Boundary);
327338
}
328339
}
329340
} // end anonymous namespace
330341

331342
void OSSALifetimeCompletion::visitAvailabilityBoundary(
332343
SILValue value, AllowLeaks_t allowLeaks, const SSAPrunedLiveness &liveness,
333-
llvm::function_ref<void(SILInstruction *)> visit) {
344+
llvm::function_ref<void(SILInstruction *, LifetimeEnd end)> visit) {
334345

335346
AvailabilityBoundaryVisitor visitor(value, allowLeaks);
336347

@@ -348,9 +359,9 @@ static bool endLifetimeAtAvailabilityBoundary(
348359
const SSAPrunedLiveness &liveness) {
349360
bool changed = false;
350361
OSSALifetimeCompletion::visitAvailabilityBoundary(
351-
value, allowLeaks, liveness, [&](auto *unreachable) {
362+
value, allowLeaks, liveness, [&](auto *unreachable, auto end) {
352363
SILBuilderWithScope builder(unreachable);
353-
endOSSALifetime(value, builder);
364+
endOSSALifetime(value, end, builder);
354365
changed = true;
355366
});
356367
return changed;

lib/SILOptimizer/Utils/CanonicalizeOSSALifetime.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,8 +275,7 @@ void CanonicalizeOSSALifetime::extendLivenessToDeinitBarriers() {
275275

276276
OSSALifetimeCompletion::visitAvailabilityBoundary(
277277
getCurrentDef(), OSSALifetimeCompletion::DoNotAllowLeaks,
278-
completeLiveness, [&](auto *unreachable) {
279-
recordUnreachableLifetimeEnd(unreachable);
278+
completeLiveness, [&](auto *unreachable, auto end) {
280279
unreachable->visitPriorInstructions([&](auto *inst) {
281280
liveness->extendToNonUse(inst);
282281
return true;

0 commit comments

Comments
 (0)