@@ -195,7 +195,8 @@ cleanupDeadTrivialPhiArgs(SILValue initialValue,
195
195
// Then RAUW the phi with the entryBlockOptionalNone and erase the
196
196
// argument.
197
197
phi->replaceAllUsesWith (initialValue);
198
- erasePhiArgument (phi->getParent (), phi->getIndex ());
198
+ erasePhiArgument (phi->getParent (), phi->getIndex (),
199
+ /* cleanupDeadPhiOp*/ false );
199
200
}
200
201
}
201
202
@@ -286,17 +287,13 @@ static void extendLifetimeToEndOfFunction(SILFunction &fn,
286
287
cvtUser->setOperand (cvtUse->getOperandNumber (), mdi);
287
288
}
288
289
289
- auto fixupSILForLifetimeExtension = [&](SILValue value) {
290
+ auto fixupSILForLifetimeExtension = [&](SILValue value, SILValue entryValue ) {
290
291
// Use SSAUpdater to find insertion points for lifetime ends.
291
292
updater.initialize (optionalEscapingClosureTy, value->getOwnershipKind ());
292
293
SmallVector<SILPhiArgument *, 8 > insertedPhis;
293
294
updater.setInsertedPhis (&insertedPhis);
294
295
295
- // Create an optional none at the function entry.
296
- auto *optionalNone =
297
- SILBuilderWithScope (fn.getEntryBlock ()->begin ())
298
- .createOptionalNone (loc, optionalEscapingClosureTy);
299
- updater.addAvailableValue (fn.getEntryBlock (), optionalNone);
296
+ updater.addAvailableValue (fn.getEntryBlock (), entryValue);
300
297
updater.addAvailableValue (value->getParentBlock (), value);
301
298
{
302
299
// Since value maybe in a loop, insert an extra lifetime end. Since we
@@ -316,12 +313,17 @@ static void extendLifetimeToEndOfFunction(SILFunction &fn,
316
313
// TODO: Should we sort inserted phis before or after we initialize
317
314
// the worklist or maybe backwards? We should investigate how the
318
315
// SSA updater adds phi nodes to this list to resolve this question.
319
- cleanupDeadTrivialPhiArgs (optionalNone , insertedPhis);
316
+ cleanupDeadTrivialPhiArgs (entryValue , insertedPhis);
320
317
};
321
318
319
+ // Create an optional none at the function entry.
320
+ auto *optionalNone = SILBuilderWithScope (fn.getEntryBlock ()->begin ())
321
+ .createOptionalNone (loc, optionalEscapingClosureTy);
322
+ auto *borrowNone = SILBuilderWithScope (optionalNone->getNextInstruction ())
323
+ .createBeginBorrow (loc, optionalNone);
322
324
// Use the SSAUpdater to create lifetime ends for the copy and the borrow.
323
- fixupSILForLifetimeExtension (borrow);
324
- fixupSILForLifetimeExtension (optionalSome);
325
+ fixupSILForLifetimeExtension (borrow, borrowNone );
326
+ fixupSILForLifetimeExtension (optionalSome, optionalNone );
325
327
}
326
328
327
329
static SILInstruction *lookThroughRebastractionUsers (
0 commit comments