58
58
59
59
using namespace swift ;
60
60
61
- static SILInstruction *endOSSALifetime (SILValue value, SILBuilder &builder) {
61
+ static SILInstruction *endOSSALifetime (SILValue value,
62
+ OSSALifetimeCompletion::LifetimeEnd end,
63
+ SILBuilder &builder) {
62
64
auto loc =
63
65
RegularLocation::getAutoGeneratedLocation (builder.getInsertionPointLoc ());
64
66
if (value->getOwnershipKind () == OwnershipKind::Owned) {
@@ -81,14 +83,16 @@ static bool endLifetimeAtLivenessBoundary(SILValue value,
81
83
!= PrunedLiveness::LifetimeEndingUse) {
82
84
changed = true ;
83
85
SILBuilderWithScope::insertAfter (lastUser, [value](SILBuilder &builder) {
84
- endOSSALifetime (value, builder);
86
+ endOSSALifetime (value, OSSALifetimeCompletion::LifetimeEnd::Boundary,
87
+ builder);
85
88
});
86
89
}
87
90
}
88
91
for (SILBasicBlock *edge : boundary.boundaryEdges ) {
89
92
changed = true ;
90
93
SILBuilderWithScope builder (edge->begin ());
91
- endOSSALifetime (value, builder);
94
+ endOSSALifetime (value, OSSALifetimeCompletion::LifetimeEnd::Boundary,
95
+ builder);
92
96
}
93
97
for (SILNode *deadDef : boundary.deadDefs ) {
94
98
SILInstruction *next = nullptr ;
@@ -99,7 +103,8 @@ static bool endLifetimeAtLivenessBoundary(SILValue value,
99
103
}
100
104
changed = true ;
101
105
SILBuilderWithScope builder (next);
102
- endOSSALifetime (value, builder);
106
+ endOSSALifetime (value, OSSALifetimeCompletion::LifetimeEnd::Boundary,
107
+ builder);
103
108
}
104
109
return changed;
105
110
}
@@ -151,9 +156,11 @@ class AvailabilityBoundaryVisitor {
151
156
void propagateAvailablity (Result &result);
152
157
153
158
// / 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);
157
164
158
165
struct State {
159
166
enum Value : uint8_t {
@@ -300,7 +307,10 @@ void AvailabilityBoundaryVisitor::propagateAvailablity(Result &result) {
300
307
}
301
308
302
309
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) {
304
314
for (auto *block : region) {
305
315
auto available = result.getState (block) == State::Available;
306
316
if (!available) {
@@ -323,14 +333,15 @@ void AvailabilityBoundaryVisitor::visitAvailabilityBoundary(
323
333
}
324
334
assert (hasUnavailableSuccessor () ||
325
335
isa<UnreachableInst>(block->getTerminator ()));
326
- visit (block->getTerminator ());
336
+ visit (block->getTerminator (),
337
+ OSSALifetimeCompletion::LifetimeEnd::Boundary);
327
338
}
328
339
}
329
340
} // end anonymous namespace
330
341
331
342
void OSSALifetimeCompletion::visitAvailabilityBoundary (
332
343
SILValue value, AllowLeaks_t allowLeaks, const SSAPrunedLiveness &liveness,
333
- llvm::function_ref<void (SILInstruction *)> visit) {
344
+ llvm::function_ref<void (SILInstruction *, LifetimeEnd end )> visit) {
334
345
335
346
AvailabilityBoundaryVisitor visitor (value, allowLeaks);
336
347
@@ -348,9 +359,9 @@ static bool endLifetimeAtAvailabilityBoundary(
348
359
const SSAPrunedLiveness &liveness) {
349
360
bool changed = false ;
350
361
OSSALifetimeCompletion::visitAvailabilityBoundary (
351
- value, allowLeaks, liveness, [&](auto *unreachable) {
362
+ value, allowLeaks, liveness, [&](auto *unreachable, auto end ) {
352
363
SILBuilderWithScope builder (unreachable);
353
- endOSSALifetime (value, builder);
364
+ endOSSALifetime (value, end, builder);
354
365
changed = true ;
355
366
});
356
367
return changed;
0 commit comments