1- // ===--- OSSALifetimeCompletion .cpp ---------------------------------------===//
1+ // ===--- OSSACompleteLifetime .cpp ---------------------------------------===//
22//
33// This source file is part of the Swift.org open source project
44//
4949// /
5050// ===----------------------------------------------------------------------===//
5151
52- #include " swift/SIL/OSSALifetimeCompletion .h"
52+ #include " swift/SIL/OSSACompleteLifetime .h"
5353#include " swift/Basic/Assertions.h"
5454#include " swift/SIL/AddressWalker.h"
5555#include " swift/SIL/BasicBlockUtils.h"
@@ -64,17 +64,17 @@ using namespace swift;
6464// FIXME: remove this option after fixing:
6565// rdar://145994924 (Mem2Reg calls lifetime completion without checking for
6666// pointer escapes)
67- llvm::cl::opt<bool > VerifyLifetimeCompletion (
68- " verify-lifetime-completion " , llvm::cl::init(false ),
69- llvm::cl::desc(" ." ));
67+ llvm::cl::opt<bool > VerifyLifetimeCompletion (" verify-lifetime-completion " ,
68+ llvm::cl::init (false ),
69+ llvm::cl::desc(" ." ));
7070
7171static SILInstruction *endOSSALifetime (SILValue value,
72- OSSALifetimeCompletion ::LifetimeEnd end,
72+ OSSACompleteLifetime ::LifetimeEnd end,
7373 SILBuilder &builder,
7474 DeadEndBlocks &deb) {
7575 auto loc =
76- RegularLocation::getAutoGeneratedLocation (builder.getInsertionPointLoc ());
77- if (end == OSSALifetimeCompletion ::LifetimeEnd::Loop) {
76+ RegularLocation::getAutoGeneratedLocation (builder.getInsertionPointLoc ());
77+ if (end == OSSACompleteLifetime ::LifetimeEnd::Loop) {
7878 return builder.createExtendLifetime (loc, value);
7979 }
8080 auto isDeadEnd = IsDeadEnd_t (deb.isDeadEnd (builder.getInsertionBB ()));
@@ -101,21 +101,21 @@ static bool endLifetimeAtLivenessBoundary(SILValue value,
101101
102102 bool changed = false ;
103103 for (SILInstruction *lastUser : boundary.lastUsers ) {
104- if (liveness.isInterestingUser (lastUser)
105- != PrunedLiveness::LifetimeEndingUse) {
104+ if (liveness.isInterestingUser (lastUser) !=
105+ PrunedLiveness::LifetimeEndingUse) {
106106 changed = true ;
107- SILBuilderWithScope::insertAfter (lastUser, [value,
108- &deb](SILBuilder &builder) {
109- endOSSALifetime (value, OSSALifetimeCompletion ::LifetimeEnd::Boundary,
110- builder, deb);
111- });
107+ SILBuilderWithScope::insertAfter (
108+ lastUser, [value, &deb](SILBuilder &builder) {
109+ endOSSALifetime (value, OSSACompleteLifetime ::LifetimeEnd::Boundary,
110+ builder, deb);
111+ });
112112 }
113113 }
114114 for (SILBasicBlock *edge : boundary.boundaryEdges ) {
115115 changed = true ;
116116 SILBuilderWithScope builder (edge->begin ());
117- endOSSALifetime (value, OSSALifetimeCompletion ::LifetimeEnd::Boundary,
118- builder, deb);
117+ endOSSALifetime (value, OSSACompleteLifetime ::LifetimeEnd::Boundary, builder ,
118+ deb);
119119 }
120120 for (SILNode *deadDef : boundary.deadDefs ) {
121121 SILInstruction *next = nullptr ;
@@ -126,8 +126,8 @@ static bool endLifetimeAtLivenessBoundary(SILValue value,
126126 }
127127 changed = true ;
128128 SILBuilderWithScope builder (next);
129- endOSSALifetime (value, OSSALifetimeCompletion ::LifetimeEnd::Boundary,
130- builder, deb);
129+ endOSSALifetime (value, OSSACompleteLifetime ::LifetimeEnd::Boundary, builder ,
130+ deb);
131131 }
132132 return changed;
133133}
@@ -174,7 +174,7 @@ namespace {
174174// / Visits the latest instructions at which `value` is available.
175175// /
176176// / Together with visitUsersOutsideLinearLivenessBoundary, implements
177- // / OSSALifetimeCompletion ::visitAvailabilityBoundary.
177+ // / OSSACompleteLifetime ::visitAvailabilityBoundary.
178178// /
179179// / Finding these positions is a three step process:
180180// / 1) computeRegion: Forward CFG walk from non-lifetime-ending boundary to find
@@ -200,7 +200,7 @@ class AvailabilityBoundaryVisitor {
200200 region(value->getFunction ()) {}
201201
202202 using Visit = llvm::function_ref<void (SILInstruction *,
203- OSSALifetimeCompletion ::LifetimeEnd)>;
203+ OSSACompleteLifetime ::LifetimeEnd)>;
204204
205205 struct Result ;
206206
@@ -311,8 +311,8 @@ void AvailabilityBoundaryVisitor::computeRegion(
311311 // ScopedAddresses) are available only up to their last extend_lifetime on
312312 // non-dead-end paths. They cannot be consumed, but are only "available" up to
313313 // the end of their scope.
314- if (value->getOwnershipKind () != OwnershipKind::None
315- || ScopedAddressValue (value)) {
314+ if (value->getOwnershipKind () != OwnershipKind::None ||
315+ ScopedAddressValue (value)) {
316316 for (auto *endBlock : boundary.endBlocks ) {
317317 if (!consumingBlocks.contains (endBlock)) {
318318 collect (endBlock);
@@ -338,8 +338,8 @@ void AvailabilityBoundaryVisitor::computeRegion(
338338 ->getModule ()
339339 .getASTContext ()
340340 .SILOpts .VerifySILOwnership ) {
341- llvm::errs () << " Invalid SIL provided to OSSALifetimeCompletion ?! {{\n " ;
342- llvm::errs () << " OSSALifetimeCompletion is visiting the availability "
341+ llvm::errs () << " Invalid SIL provided to OSSACompleteLifetime ?! {{\n " ;
342+ llvm::errs () << " OSSACompleteLifetime is visiting the availability "
343343 " boundary of " ;
344344 value->print (llvm::errs ());
345345 llvm::errs ()
@@ -353,8 +353,8 @@ void AvailabilityBoundaryVisitor::computeRegion(
353353 " value was leaked. The function with the leak is as follows:\n " ;
354354 block->getFunction ()->print (llvm::errs ());
355355 llvm::errs ()
356- << " Invalid SIL provided to OSSALifetimeCompletion ?! }}\n "
357- << " Something that ran before OSSALifetimeCompletion (the current "
356+ << " Invalid SIL provided to OSSACompleteLifetime ?! }}\n "
357+ << " Something that ran before OSSACompleteLifetime (the current "
358358 " pass, an earlier pass, SILGen) has introduced a leak of this "
359359 " value.\n "
360360 << " Please rerun the crashing swift-frontend command with the "
@@ -419,7 +419,7 @@ void AvailabilityBoundaryVisitor::propagateAvailablity(Result &result) {
419419void AvailabilityBoundaryVisitor::visitAvailabilityBoundary (
420420 Result const &result,
421421 llvm::function_ref<void (SILInstruction *,
422- OSSALifetimeCompletion ::LifetimeEnd end)>
422+ OSSACompleteLifetime ::LifetimeEnd end)>
423423 visit) {
424424 for (auto *block : region) {
425425 auto available = result.getState (block) == State::Available;
@@ -441,13 +441,12 @@ void AvailabilityBoundaryVisitor::visitAvailabilityBoundary(
441441 ->getModule ()
442442 .getASTContext ()
443443 .SILOpts .VerifySILOwnership );
444- visit (block->getTerminator (),
445- OSSALifetimeCompletion::LifetimeEnd::Boundary);
444+ visit (block->getTerminator (), OSSACompleteLifetime::LifetimeEnd::Boundary);
446445 }
447446}
448447} // end anonymous namespace
449448
450- void OSSALifetimeCompletion ::visitAvailabilityBoundary (
449+ void OSSACompleteLifetime ::visitAvailabilityBoundary (
451450 SILValue value, const SSAPrunedLiveness &liveness,
452451 llvm::function_ref<void (SILInstruction *, LifetimeEnd end)> visit) {
453452
@@ -468,7 +467,7 @@ static bool endLifetimeAtAvailabilityBoundary(SILValue value,
468467 const SSAPrunedLiveness &liveness,
469468 DeadEndBlocks &deb) {
470469 bool changed = false ;
471- OSSALifetimeCompletion ::visitAvailabilityBoundary (
470+ OSSACompleteLifetime ::visitAvailabilityBoundary (
472471 value, liveness, [&](auto *unreachable, auto end) {
473472 SILBuilderWithScope builder (unreachable);
474473 endOSSALifetime (value, end, builder, deb);
@@ -479,33 +478,33 @@ static bool endLifetimeAtAvailabilityBoundary(SILValue value,
479478
480479static bool endLifetimeAtBoundary (SILValue value,
481480 SSAPrunedLiveness const &liveness,
482- OSSALifetimeCompletion ::Boundary boundary,
481+ OSSACompleteLifetime ::Boundary boundary,
483482 DeadEndBlocks &deadEndBlocks) {
484483 bool changed = false ;
485484 switch (boundary) {
486- case OSSALifetimeCompletion ::Boundary::Liveness:
485+ case OSSACompleteLifetime ::Boundary::Liveness:
487486 changed |= endLifetimeAtLivenessBoundary (value, liveness, deadEndBlocks);
488487 break ;
489- case OSSALifetimeCompletion ::Boundary::Availability:
488+ case OSSACompleteLifetime ::Boundary::Availability:
490489 changed |=
491490 endLifetimeAtAvailabilityBoundary (value, liveness, deadEndBlocks);
492491 break ;
493492 }
494493 return changed;
495494}
496495
497- bool OSSALifetimeCompletion ::analyzeAndUpdateLifetime (
496+ bool OSSACompleteLifetime ::analyzeAndUpdateLifetime (
498497 ScopedAddressValue scopedAddress, Boundary boundary) {
499498 SmallVector<SILBasicBlock *, 8 > discoveredBlocks;
500499 SSAPrunedLiveness liveness (scopedAddress->getFunction (), &discoveredBlocks);
501500 liveness.initializeDef (scopedAddress.value );
502501
503502 struct Walker : TransitiveAddressWalker<Walker> {
504- OSSALifetimeCompletion &completion;
503+ OSSACompleteLifetime &completion;
505504 ScopedAddressValue scopedAddress;
506505 Boundary boundary;
507506 SSAPrunedLiveness &liveness;
508- Walker (OSSALifetimeCompletion &completion, ScopedAddressValue scopedAddress,
507+ Walker (OSSACompleteLifetime &completion, ScopedAddressValue scopedAddress,
509508 Boundary boundary, SSAPrunedLiveness &liveness)
510509 : completion(completion), scopedAddress(scopedAddress),
511510 boundary (boundary), liveness(liveness) {}
@@ -555,8 +554,8 @@ bool OSSALifetimeCompletion::analyzeAndUpdateLifetime(
555554// / End the lifetime of \p value at unreachable instructions.
556555// /
557556// / Returns true if any new instructions were created to complete the lifetime.
558- bool OSSALifetimeCompletion ::analyzeAndUpdateLifetime (SILValue value,
559- Boundary boundary) {
557+ bool OSSACompleteLifetime ::analyzeAndUpdateLifetime (SILValue value,
558+ Boundary boundary) {
560559 if (auto scopedAddress = ScopedAddressValue (value)) {
561560 return analyzeAndUpdateLifetime (scopedAddress, boundary);
562561 }
@@ -577,8 +576,8 @@ bool OSSALifetimeCompletion::analyzeAndUpdateLifetime(SILValue value,
577576 }
578577 InteriorLiveness liveness (value);
579578 liveness.compute (domInfo, handleInnerScope);
580- if (VerifyLifetimeCompletion && boundary != Boundary::Availability
581- && liveness.getAddressUseKind () != AddressUseKind::NonEscaping) {
579+ if (VerifyLifetimeCompletion && boundary != Boundary::Availability &&
580+ liveness.getAddressUseKind () != AddressUseKind::NonEscaping) {
582581 llvm::errs () << " Incomplete liveness for: " << value;
583582 if (auto *escapingUse = liveness.escapingUse ) {
584583 llvm::errs () << " escapes at:\n " ;
@@ -596,20 +595,19 @@ namespace swift::test {
596595// - string: either "liveness" or "availability"
597596// Dumps:
598597// - function
599- static FunctionTest OSSALifetimeCompletionTest (
600- " ossa_lifetime_completion" ,
601- [](auto &function, auto &arguments, auto &test) {
598+ static FunctionTest OSSACompleteLifetimeTest (
599+ " ossa_complete_lifetime" , [](auto &function, auto &arguments, auto &test) {
602600 SILValue value = arguments.takeValue ();
603- OSSALifetimeCompletion ::Boundary kind =
604- llvm::StringSwitch<OSSALifetimeCompletion ::Boundary>(
601+ OSSACompleteLifetime ::Boundary kind =
602+ llvm::StringSwitch<OSSACompleteLifetime ::Boundary>(
605603 arguments.takeString ())
606- .Case (" liveness" , OSSALifetimeCompletion ::Boundary::Liveness)
604+ .Case (" liveness" , OSSACompleteLifetime ::Boundary::Liveness)
607605 .Case (" availability" ,
608- OSSALifetimeCompletion ::Boundary::Availability);
606+ OSSACompleteLifetime ::Boundary::Availability);
609607 auto *deb = test.getDeadEndBlocks ();
610608 llvm::outs () << " OSSA lifetime completion on " << kind
611609 << " boundary: " << value;
612- OSSALifetimeCompletion completion (&function, /* domInfo*/ nullptr , *deb);
610+ OSSACompleteLifetime completion (&function, /* domInfo*/ nullptr , *deb);
613611 completion.completeOSSALifetime (value, kind);
614612 function.print (llvm::outs ());
615613 });
@@ -686,12 +684,12 @@ bool UnreachableLifetimeCompletion::completeLifetimes() {
686684 }
687685 }
688686
689- OSSALifetimeCompletion completion (function, domInfo, deadEndBlocks);
687+ OSSACompleteLifetime completion (function, domInfo, deadEndBlocks);
690688
691689 bool changed = false ;
692690 for (auto value : incompleteValues) {
693691 if (completion.completeOSSALifetime (
694- value, OSSALifetimeCompletion ::Boundary::Availability) ==
692+ value, OSSACompleteLifetime ::Boundary::Availability) ==
695693 LifetimeCompletion::WasCompleted) {
696694 changed = true ;
697695 }
0 commit comments