@@ -122,8 +122,6 @@ static void extendLifetimeToEndOfFunction(SILFunction &fn,
122
122
auto optionalEscapingClosureTy = SILType::getOptionalType (escapingClosureTy);
123
123
auto loc = RegularLocation::getAutoGeneratedLocation ();
124
124
125
- cvt->setLifetimeGuaranteed ();
126
-
127
125
// If our Cvt is in the initial block, we do not need to use the SSA updater
128
126
// since we know Cvt can not be in a loop and must dominate all exits
129
127
// (*). Just insert a copy of the escaping closure at the Cvt and destroys at
@@ -133,6 +131,8 @@ static void extendLifetimeToEndOfFunction(SILFunction &fn,
133
131
if (cvt->getParent () == cvt->getFunction ()->getEntryBlock ()) {
134
132
auto *innerCVI =
135
133
SILBuilderWithScope (cvt).createCopyValue (loc, escapingClosure);
134
+ cvt->setLifetimeGuaranteed ();
135
+ cvt->setOperand (innerCVI);
136
136
SmallVector<SILBasicBlock *, 4 > exitingBlocks;
137
137
fn.findExitingBlocks (exitingBlocks);
138
138
@@ -167,8 +167,11 @@ static void extendLifetimeToEndOfFunction(SILFunction &fn,
167
167
// block without extra work. So the fact that Cvt is not in the entry block
168
168
// means that we don't have to worry about overwriting the .none value.
169
169
auto *cvi = [&]() -> CopyValueInst * {
170
- SILBuilderWithScope b (cvt);
171
- auto *innerCVI = b.createCopyValue (loc, escapingClosure);
170
+ auto *innerCVI =
171
+ SILBuilderWithScope (cvt).createCopyValue (loc, escapingClosure);
172
+ cvt->setLifetimeGuaranteed ();
173
+ cvt->setOperand (innerCVI);
174
+ SILBuilderWithScope b (std::next (cvt->getIterator ()));
172
175
updater.AddAvailableValue (
173
176
cvt->getParent (),
174
177
b.createOptionalSome (loc, innerCVI, optionalEscapingClosureTy));
@@ -407,10 +410,10 @@ static bool tryExtendLifetimeToLastUse(
407
410
// Insert a copy at the convert_escape_to_noescape [not_guaranteed] and
408
411
// change the instruction to the guaranteed form.
409
412
auto escapingClosure = cvt->getOperand ();
410
- cvt->setLifetimeGuaranteed ();
411
-
412
413
auto *closureCopy =
413
414
SILBuilderWithScope (cvt).createCopyValue (loc, escapingClosure);
415
+ cvt->setLifetimeGuaranteed ();
416
+ cvt->setOperand (closureCopy);
414
417
415
418
// Insert a destroy after the apply.
416
419
if (auto *apply = dyn_cast<ApplyInst>(singleApplyUser.getInstruction ())) {
@@ -492,14 +495,17 @@ static bool trySwitchEnumPeephole(ConvertEscapeToNoEscapeInst *cvt) {
492
495
if (!onlyDestroy)
493
496
return false ;
494
497
495
- cvt->setLifetimeGuaranteed ();
496
-
497
498
// Extend the lifetime.
498
- SILBuilderWithScope b (switchEnum1);
499
499
auto loc = RegularLocation::getAutoGeneratedLocation ();
500
- auto copy = b.createCopyValue (loc, switchEnum1->getOperand ());
501
- b.setInsertionPoint (onlyDestroy);
502
- b.createDestroyValue (loc, copy);
500
+ auto *copy = SILBuilderWithScope (switchEnum1)
501
+ .createCopyValue (loc, switchEnum1->getOperand ());
502
+
503
+ cvt->setLifetimeGuaranteed ();
504
+ auto *mdi = SILBuilderWithScope (cvt).createMarkDependence (
505
+ loc, cvt->getOperand (), copy);
506
+ cvt->setOperand (mdi);
507
+
508
+ SILBuilderWithScope (onlyDestroy).createDestroyValue (loc, copy);
503
509
return true ;
504
510
}
505
511
0 commit comments