Skip to content

Commit aa85694

Browse files
committed
[NFC] OSSACompleteLifetime: Renamed.
1 parent d8710fc commit aa85694

17 files changed

+178
-181
lines changed

docs/SIL/Instructions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1032,7 +1032,7 @@ extend_lifetime %0 : $X
10321032
```
10331033

10341034
Indicates that a value's linear lifetime extends to this point.
1035-
Inserted by OSSALifetimeCompletion(AvailabilityBoundary) in order to
1035+
Inserted by OSSACompleteLifetime(AvailabilityBoundary) in order to
10361036
provide the invariant that a value is either consumed OR has an
10371037
`extend_lifetime` user on all paths and furthermore that all
10381038
uses are within the boundary defined by that set of instructions (the

include/swift/SIL/OSSALifetimeCompletion.h renamed to include/swift/SIL/OSSACompleteLifetime.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class DeadEndBlocks;
3838

3939
enum class LifetimeCompletion { NoLifetime, AlreadyComplete, WasCompleted };
4040

41-
class OSSALifetimeCompletion {
41+
class OSSACompleteLifetime {
4242
public:
4343
enum HandleTrivialVariable_t { IgnoreTrivialVariable, ExtendTrivialVariable };
4444

@@ -63,7 +63,7 @@ class OSSALifetimeCompletion {
6363
bool ForceLivenessVerification;
6464

6565
public:
66-
OSSALifetimeCompletion(
66+
OSSACompleteLifetime(
6767
SILFunction *function, const DominanceInfo *domInfo,
6868
DeadEndBlocks &deadEndBlocks,
6969
HandleTrivialVariable_t handleTrivialVariable = IgnoreTrivialVariable,
@@ -113,8 +113,8 @@ class OSSALifetimeCompletion {
113113
break;
114114
}
115115
// During SILGenCleanup, extend move_value [var_decl].
116-
if (handleTrivialVariable == ExtendTrivialVariable
117-
&& value->isFromVarDecl()) {
116+
if (handleTrivialVariable == ExtendTrivialVariable &&
117+
value->isFromVarDecl()) {
118118
break;
119119
}
120120
return LifetimeCompletion::NoLifetime;
@@ -203,13 +203,13 @@ class UnreachableLifetimeCompletion {
203203
bool completeLifetimes();
204204
};
205205

206-
inline llvm::raw_ostream &
207-
operator<<(llvm::raw_ostream &OS, OSSALifetimeCompletion::Boundary boundary) {
206+
inline llvm::raw_ostream &operator<<(llvm::raw_ostream &OS,
207+
OSSACompleteLifetime::Boundary boundary) {
208208
switch (boundary) {
209-
case OSSALifetimeCompletion::Boundary::Liveness:
209+
case OSSACompleteLifetime::Boundary::Liveness:
210210
OS << "liveness";
211211
break;
212-
case OSSALifetimeCompletion::Boundary::Availability:
212+
case OSSACompleteLifetime::Boundary::Availability:
213213
OS << "availability";
214214
break;
215215
}

include/swift/SILOptimizer/Utils/CanonicalizeOSSALifetime.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ class CanonicalizeOSSALifetime final {
470470
}
471471

472472
bool respectsDeadEnds() const {
473-
// TODO: OSSALifetimeCompletion: Once lifetimes are always complete, delete
473+
// TODO: OSSACompleteLifetime: Once lifetimes are always complete, delete
474474
// this method.
475475
return !endingLifetimeAtExplicitEnds();
476476
}

lib/SIL/Utils/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ target_sources(swiftSIL PRIVATE
1313
MemAccessUtils.cpp
1414
MemoryLocations.cpp
1515
OptimizationRemark.cpp
16-
OSSALifetimeCompletion.cpp
16+
OSSACompleteLifetime.cpp
1717
OwnershipLiveness.cpp
1818
OwnershipUtils.cpp
1919
PrettyStackTrace.cpp

lib/SIL/Utils/OSSALifetimeCompletion.cpp renamed to lib/SIL/Utils/OSSACompleteLifetime.cpp

Lines changed: 50 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===--- OSSALifetimeCompletion.cpp ---------------------------------------===//
1+
//===--- OSSACompleteLifetime.cpp ---------------------------------------===//
22
//
33
// This source file is part of the Swift.org open source project
44
//
@@ -49,7 +49,7 @@
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

7171
static 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) {
419419
void 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

480479
static 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
}

lib/SILOptimizer/Mandatory/MoveOnlyAddressCheckerUtils.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@
243243
#include "swift/SIL/FieldSensitivePrunedLiveness.h"
244244
#include "swift/SIL/InstructionUtils.h"
245245
#include "swift/SIL/MemAccessUtils.h"
246-
#include "swift/SIL/OSSALifetimeCompletion.h"
246+
#include "swift/SIL/OSSACompleteLifetime.h"
247247
#include "swift/SIL/OwnershipUtils.h"
248248
#include "swift/SIL/PrunedLiveness.h"
249249
#include "swift/SIL/SILArgument.h"
@@ -4071,13 +4071,12 @@ bool MoveOnlyAddressChecker::check(
40714071
return pimpl.changed;
40724072
}
40734073
bool MoveOnlyAddressChecker::completeLifetimes() {
4074-
// TODO: Delete once OSSALifetimeCompletion is run as part of SILGenCleanup
4074+
// TODO: Delete once OSSACompleteLifetime is run as part of SILGenCleanup
40754075
bool changed = false;
40764076

40774077
// Lifetimes must be completed inside out (bottom-up in the CFG).
40784078
PostOrderFunctionInfo *postOrder = poa->get(fn);
4079-
OSSALifetimeCompletion completion(fn, domTree,
4080-
*deadEndBlocksAnalysis->get(fn));
4079+
OSSACompleteLifetime completion(fn, domTree, *deadEndBlocksAnalysis->get(fn));
40814080
for (auto *block : postOrder->getPostOrder()) {
40824081
for (SILInstruction &inst : reverse(*block)) {
40834082
for (auto result : inst.getResults()) {
@@ -4086,7 +4085,7 @@ bool MoveOnlyAddressChecker::completeLifetimes() {
40864085
continue;
40874086
}
40884087
if (completion.completeOSSALifetime(
4089-
result, OSSALifetimeCompletion::Boundary::Availability) ==
4088+
result, OSSACompleteLifetime::Boundary::Availability) ==
40904089
LifetimeCompletion::WasCompleted) {
40914090
changed = true;
40924091
}
@@ -4097,7 +4096,7 @@ bool MoveOnlyAddressChecker::completeLifetimes() {
40974096
continue;
40984097
}
40994098
if (completion.completeOSSALifetime(
4100-
arg, OSSALifetimeCompletion::Boundary::Availability) ==
4099+
arg, OSSACompleteLifetime::Boundary::Availability) ==
41014100
LifetimeCompletion::WasCompleted) {
41024101
changed = true;
41034102
}

0 commit comments

Comments
 (0)