5858
5959using 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
302309void 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
331342void 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;
0 commit comments