@@ -57,7 +57,6 @@ STATISTIC(NumInstRemoved, "Number of Instructions removed");
57
57
58
58
static bool lexicalLifetimeEnsured (AllocStackInst *asi);
59
59
static bool isGuaranteedLexicalValue (SILValue src);
60
- static bool isOwnedLexicalValue (SILValue src);
61
60
62
61
namespace {
63
62
@@ -97,11 +96,9 @@ class LiveValues {
97
96
if (!lexicalLifetimeEnsured (asi)) {
98
97
return stored;
99
98
}
100
- auto storedIsLexical = stored && isOwnedLexicalValue (stored);
101
- // If the value was already lexical, we use it directly. Otherwise, a new
102
- // move_value [lexical] is used.
103
- assert (storedIsLexical || move);
104
- return storedIsLexical ? stored : move;
99
+ // We should have created a move of the @owned stored value.
100
+ assert (move);
101
+ return move;
105
102
}
106
103
107
104
bool canEndLexicalLifetime () {
@@ -110,8 +107,7 @@ class LiveValues {
110
107
// to end a lexical lifetime. In that case, the lifetime end will be
111
108
// added later, when we have enough information, namely the live in
112
109
// values, to end it.
113
- auto storedIsLexical = stored && isOwnedLexicalValue (stored);
114
- return storedIsLexical ? stored : move;
110
+ return move;
115
111
}
116
112
};
117
113
struct Guaranteed {
@@ -225,7 +221,6 @@ class LiveValues {
225
221
return guaranteed.stored ;
226
222
}
227
223
228
- // / Whether it's possible and appropriate to end the lifetime.
229
224
bool canEndLexicalLifetime () {
230
225
if (auto *owned = storage.dyn_cast <Owned>()) {
231
226
return owned->canEndLexicalLifetime ();
@@ -526,15 +521,16 @@ static bool lexicalLifetimeEnsured(AllocStackInst *asi) {
526
521
!asi->getElementType ().isTrivial (*asi->getFunction ());
527
522
}
528
523
529
- static bool isOwnedLexicalValue (SILValue src) {
530
- return src->getOwnershipKind () == OwnershipKind::Owned && src->isLexical ();
531
- }
532
-
533
524
static bool isGuaranteedLexicalValue (SILValue src) {
534
525
return src->getOwnershipKind () == OwnershipKind::Guaranteed &&
535
526
src->isLexical ();
536
527
}
537
528
529
+ // / Returns true if we have enough information to end the lifetime.
530
+ static bool canEndLexicalLifetime (LiveValues values) {
531
+ return values.canEndLexicalLifetime ();
532
+ }
533
+
538
534
// / Begin a lexical borrow scope for the value stored into the provided
539
535
// / StoreInst after that instruction.
540
536
// /
@@ -550,9 +546,6 @@ beginOwnedLexicalLifetimeAfterStore(AllocStackInst *asi, StoreInst *inst) {
550
546
SILValue stored = inst->getOperand (CopyLikeInstruction::Src);
551
547
SILLocation loc = RegularLocation::getAutoGeneratedLocation (inst->getLoc ());
552
548
553
- if (isOwnedLexicalValue (stored)) {
554
- return {LiveValues::forOwned (stored, {}), /* isStorageValid*/ true };
555
- }
556
549
MoveValueInst *mvi = nullptr ;
557
550
SILBuilderWithScope::insertAfter (inst, [&](SILBuilder &builder) {
558
551
mvi = builder.createMoveValue (loc, stored, /* isLexical*/ true );
@@ -832,7 +825,7 @@ SILInstruction *StackAllocationPromoter::promoteAllocationInBlock(
832
825
if (lexicalLifetimeEnsured (asi)) {
833
826
// End the lexical lifetime at a load [take]. The storage is no
834
827
// longer keeping the value alive.
835
- if (runningVals && runningVals->value . canEndLexicalLifetime ( )) {
828
+ if (runningVals && canEndLexicalLifetime ( runningVals->value )) {
836
829
// End it right now if we have enough information.
837
830
endOwnedLexicalLifetimeBeforeInst (asi, /* beforeInstruction=*/ li,
838
831
ctx,
@@ -915,7 +908,7 @@ SILInstruction *StackAllocationPromoter::promoteAllocationInBlock(
915
908
lastStoreInst = si;
916
909
if (lexicalLifetimeEnsured (asi)) {
917
910
if (oldRunningVals && oldRunningVals->isStorageValid &&
918
- oldRunningVals->value . canEndLexicalLifetime ( )) {
911
+ canEndLexicalLifetime ( oldRunningVals->value )) {
919
912
endOwnedLexicalLifetimeBeforeInst (asi, /* beforeInstruction=*/ si, ctx,
920
913
oldRunningVals->value .getOwned ());
921
914
}
@@ -972,7 +965,7 @@ SILInstruction *StackAllocationPromoter::promoteAllocationInBlock(
972
965
}
973
966
// Mark storage as invalid and mark end_borrow as a deinit point.
974
967
runningVals->isStorageValid = false ;
975
- if (!runningVals->value . canEndLexicalLifetime ( )) {
968
+ if (!canEndLexicalLifetime ( runningVals->value )) {
976
969
continue ;
977
970
}
978
971
endGuaranteedLexicalLifetimeBeforeInst (
@@ -1074,10 +1067,6 @@ StackAllocationPromoter::getLiveOutValues(BlockSetVector &phiBlocks,
1074
1067
auto values = LiveValues::forGuaranteed (stored, borrow);
1075
1068
return values;
1076
1069
}
1077
- if (isOwnedLexicalValue (stored)) {
1078
- auto values = LiveValues::forOwned (stored, {});
1079
- return values;
1080
- }
1081
1070
auto move = cast<MoveValueInst>(inst->getNextInstruction ());
1082
1071
auto values = LiveValues::forOwned (stored, move);
1083
1072
return values;
@@ -1433,7 +1422,7 @@ void StackAllocationPromoter::endLexicalLifetime(BlockSetVector &phiBlocks) {
1433
1422
if (isa<EndBorrowInst>(inst)) {
1434
1423
// Not all store_borrows will have a begin_borrow [lexical] that needs
1435
1424
// to be ended. If the source is already lexical, we don't create it.
1436
- if (!values-> canEndLexicalLifetime ()) {
1425
+ if (!canEndLexicalLifetime (*values )) {
1437
1426
continue ;
1438
1427
}
1439
1428
endGuaranteedLexicalLifetimeBeforeInst (
@@ -1456,7 +1445,7 @@ void StackAllocationPromoter::endLexicalLifetime(BlockSetVector &phiBlocks) {
1456
1445
if (terminatesInUnreachable || uniqueSuccessorLacksLiveInValues ()) {
1457
1446
auto values = getLiveOutValues (phiBlocks, bb);
1458
1447
if (values->isGuaranteed ()) {
1459
- if (!values-> canEndLexicalLifetime ()) {
1448
+ if (!canEndLexicalLifetime (*values )) {
1460
1449
continue ;
1461
1450
}
1462
1451
endGuaranteedLexicalLifetimeBeforeInst (
@@ -1982,7 +1971,7 @@ void MemoryToRegisters::removeSingleBlockAllocation(AllocStackInst *asi) {
1982
1971
continue ;
1983
1972
}
1984
1973
runningVals->isStorageValid = false ;
1985
- if (!runningVals->value . canEndLexicalLifetime ( )) {
1974
+ if (!canEndLexicalLifetime ( runningVals->value )) {
1986
1975
continue ;
1987
1976
}
1988
1977
endGuaranteedLexicalLifetimeBeforeInst (
0 commit comments