@@ -308,9 +308,6 @@ class FilterCandidates final {
308
308
309
309
// / Determines whether each candidate is viable for folding.
310
310
// /
311
- // / Requiring findUsers to have been called, this uses the more expensive
312
- // / isViableMatch.
313
- // /
314
311
// / returns true if any candidates were viable
315
312
// / false otherwise
316
313
bool run (Candidates &candidates);
@@ -334,8 +331,7 @@ class FilterCandidates final {
334
331
// /
335
332
// / If there are, we can't fold the apply. Specifically, we can't introduce
336
333
// / a move_value [lexical] %borrowee because that value still needs to be used
337
- // / in those locations. While updateSSA would happily rewrite those uses to
338
- // / be uses of the move, that is not a semantically valid transformation.
334
+ // / in those locations.
339
335
// /
340
336
// / For example, given the following SIL
341
337
// / %borrowee : @owned
@@ -412,10 +408,6 @@ class Rewriter final {
412
408
// / (3) delete the destroy_value
413
409
void fold (Match, SmallVectorImpl<int > const &rewritableArgumentIndices);
414
410
415
- // Update SSA to reflect that fact that %move and %borrowee are two
416
- // defs for the "same value".
417
- void updateSSA ();
418
-
419
411
// The move_value [lexical] instruction that was added during the run.
420
412
//
421
413
// Defined during createMove.
@@ -470,25 +462,31 @@ bool run(Context &context) {
470
462
void Rewriter::run () {
471
463
bool foldedAny = false ;
472
464
(void )foldedAny;
473
- for ( unsigned index = 0 , count = candidates.vector .size (); index < count ;
474
- ++index) {
465
+ auto size = candidates.vector .size ();
466
+ for ( unsigned index = 0 ; index < size; ++index) {
475
467
auto candidate = candidates.vector [index];
476
- if (!candidate.viable )
477
- continue ;
478
468
createMove ();
469
+ if (!candidate.viable ) {
470
+ // Nonviable candidates still end with the pattern
471
+ //
472
+ // end_borrow %lifetime
473
+ // ...
474
+ // destroy_value %borrowee
475
+ //
476
+ // Now that the new move_value [lexical] dominates all candidates, the
477
+ // every candidate's destroy_value %borrowee is dominated by it, so every
478
+ // one is dominated by another consuming use which is illegal. Rewrite
479
+ // each such destroy_value to be a destroy_value of the move.
480
+ candidate.match .dvi ->setOperand (mvi);
481
+ continue ;
482
+ }
479
483
480
484
fold (candidate.match , candidate.argumentIndices );
481
485
#ifndef NDEBUG
482
486
foldedAny = true ;
483
487
#endif
484
488
}
485
489
assert (foldedAny && " rewriting without anything to rewrite!?" );
486
-
487
- // There are now "two defs for %borrowee":
488
- // - %borrowee
489
- // - %move
490
- // We need to update SSA.
491
- updateSSA ();
492
490
}
493
491
494
492
bool Rewriter::createMove () {
@@ -551,26 +549,6 @@ void Rewriter::fold(Match candidate,
551
549
context.deleter .forceDelete (candidate.dvi );
552
550
}
553
551
554
- void Rewriter::updateSSA () {
555
- SILSSAUpdater updater;
556
- updater.initialize (context.borrowee ->getType (),
557
- context.borrowee .getOwnershipKind ());
558
- updater.addAvailableValue (context.borrowee ->getParentBlock (),
559
- context.borrowee );
560
- updater.addAvailableValue (mvi->getParentBlock (), mvi);
561
-
562
- SmallVector<Operand *, 16 > uses;
563
- for (auto use : context.borrowee ->getUses ()) {
564
- if (use->getUser () == mvi)
565
- continue ;
566
- uses.push_back (use);
567
- }
568
-
569
- for (auto use : uses) {
570
- updater.rewriteUse (*use);
571
- }
572
- }
573
-
574
552
// ===----------------------------------------------------------------------===//
575
553
// MARK: Lookups
576
554
// ===----------------------------------------------------------------------===//
@@ -640,6 +618,8 @@ bool FilterCandidates::run(Candidates &candidates) {
640
618
641
619
bool findBorroweeUsage (Context &context, BorroweeUsage &usage) {
642
620
auto recordUse = [&](Operand *use) {
621
+ // Ignore uses that aren't dominated by the introducer. PrunedLiveness
622
+ // relies on us doing this check.
643
623
if (!context.dominanceTree .dominates (context.introducer , use->getUser ()))
644
624
return ;
645
625
usage.uses .push_back (use);
0 commit comments