@@ -140,7 +140,7 @@ struct Context final {
140
140
};
141
141
142
142
// / Fold within the specified context.
143
- bool run (Context &);
143
+ MoveValueInst * run (Context &);
144
144
145
145
// / The consuming use pattern we are trying to match and transform.
146
146
struct Match final {
@@ -358,6 +358,11 @@ class Rewriter final {
358
358
Context &context;
359
359
Candidates const &candidates;
360
360
361
+ // The move_value [lexical] instruction that was added during the run.
362
+ //
363
+ // Defined during createMove.
364
+ MoveValueInst *mvi = nullptr ;
365
+
361
366
public:
362
367
Rewriter (Context &context, Candidates const &candidates)
363
368
: context(context), candidates(candidates){};
@@ -379,7 +384,7 @@ class Rewriter final {
379
384
// / ...
380
385
// / - update SSA now that a second def has been introduced for
381
386
// / %borrowee
382
- void run ();
387
+ MoveValueInst * run ();
383
388
384
389
private:
385
390
// / Add the new move_value [lexical] above the begin_borrow [lexical].
@@ -407,11 +412,6 @@ class Rewriter final {
407
412
// / (2) hoist the end_borrow
408
413
// / (3) delete the destroy_value
409
414
void fold (Match, ArrayRef<int > rewritableArgumentIndices);
410
-
411
- // The move_value [lexical] instruction that was added during the run.
412
- //
413
- // Defined during createMove.
414
- MoveValueInst *mvi = nullptr ;
415
415
};
416
416
417
417
// ===----------------------------------------------------------------------===//
@@ -421,45 +421,43 @@ class Rewriter final {
421
421
// / Perform any possible folding.
422
422
// /
423
423
// / Returns whether any change was made.
424
- bool run (Context &context) {
424
+ MoveValueInst * run (Context &context) {
425
425
Candidates candidates;
426
426
427
427
// Do a cheap search for scope ending instructions that could potentially be
428
428
// candidates for folding.
429
429
if (!FindCandidates (context).run (candidates))
430
- return false ;
430
+ return nullptr ;
431
431
432
432
// At least one full match was found and more expensive checks on the matches
433
433
// are in order.
434
434
435
435
BorroweeUsage borroweeUsage;
436
436
if (!findBorroweeUsage (context, borroweeUsage))
437
- return false ;
437
+ return nullptr ;
438
438
IntroducerUsage introducerUsage;
439
439
if (!findIntroducerUsage (context, introducerUsage))
440
- return false ;
440
+ return nullptr ;
441
441
442
442
// Now, filter the candidates using those values.
443
443
if (!FilterCandidates (context, introducerUsage, borroweeUsage)
444
444
.run (candidates))
445
- return false ;
445
+ return nullptr ;
446
446
447
447
// Finally, check that %borrowee has no uses within %lifetime's
448
448
// borrow scope.
449
449
if (borroweeHasUsesWithinBorrowScope (context, borroweeUsage))
450
- return false ;
450
+ return nullptr ;
451
451
452
452
// It is safe to rewrite the viable candidates. Do so.
453
- Rewriter (context, candidates).run ();
454
-
455
- return true ;
453
+ return Rewriter (context, candidates).run ();
456
454
}
457
455
458
456
// ===----------------------------------------------------------------------===//
459
457
// MARK: Rewriting
460
458
// ===----------------------------------------------------------------------===//
461
459
462
- void Rewriter::run () {
460
+ MoveValueInst * Rewriter::run () {
463
461
bool foldedAny = false ;
464
462
(void )foldedAny;
465
463
auto size = candidates.vector .size ();
@@ -487,6 +485,7 @@ void Rewriter::run() {
487
485
#endif
488
486
}
489
487
assert (foldedAny && " rewriting without anything to rewrite!?" );
488
+ return mvi;
490
489
}
491
490
492
491
bool Rewriter::createMove () {
@@ -779,15 +778,16 @@ bool FilterCandidates::rewritableArgumentIndicesForApply(
779
778
// ===----------------------------------------------------------------------===//
780
779
781
780
// / The entry point.
782
- bool swift::foldDestroysOfCopiedLexicalBorrow (BeginBorrowInst *bbi,
783
- DominanceInfo &dominanceTree,
784
- InstructionDeleter &deleter) {
781
+ MoveValueInst *
782
+ swift::foldDestroysOfCopiedLexicalBorrow (BeginBorrowInst *bbi,
783
+ DominanceInfo &dominanceTree,
784
+ InstructionDeleter &deleter) {
785
785
if (!bbi->isLexical ())
786
- return false ;
786
+ return nullptr ;
787
787
if (bbi->getOperand ()->getOwnershipKind () != OwnershipKind::Owned)
788
- return false ;
788
+ return nullptr ;
789
789
if (!dominanceTree.isReachableFromEntry (bbi->getParentBlock ()))
790
- return false ;
790
+ return nullptr ;
791
791
792
792
auto context = LexicalDestroyFolding::Context (bbi, dominanceTree, deleter);
793
793
return LexicalDestroyFolding::run (context);
0 commit comments