@@ -554,18 +554,37 @@ getExitingRegions(LoopRegionFunctionInfo *LRFI,
554
554
void
555
555
LoopRegionFunctionInfo::
556
556
rewriteLoopExitingBlockSuccessors (LoopTy *Loop, RegionTy *LRegion) {
557
+ // Begin by using loop info and loop region info to find all of the exiting
558
+ // regions.
559
+ //
560
+ // We do this by looking up the exiting blocks and finding the outermost
561
+ // region which the block is a subregion of. Since we initialize our data
562
+ // structure by processing the loop nest bottom up, this should always give us
563
+ // the correct region for the level of the loop we are processing.
557
564
llvm::SmallVector<RegionTy *, 8 > ExitingRegions;
558
565
getExitingRegions (this , Loop, LRegion, ExitingRegions);
559
566
567
+ // Then for each exiting region ER of the Loop L...
560
568
DEBUG (llvm::dbgs () << " Visiting Exit Blocks...\n " );
561
569
for (auto *ExitingRegion : ExitingRegions) {
562
570
DEBUG (llvm::dbgs () << " Exiting Region: "
563
571
<< ExitingRegion->getID () << " \n " );
572
+
573
+ // For each successor region S of ER...
564
574
for (auto SuccID : ExitingRegion->getSuccs ()) {
565
575
DEBUG (llvm::dbgs () << " Succ: " << SuccID.ID
566
576
<< " . IsNonLocal: "
567
577
<< (SuccID.IsNonLocal ? " true" : " false" ) << " \n " );
568
578
579
+ // If S is not contained in L, then:
580
+ //
581
+ // 1. The successor/predecessor edge in between S and ER with a new
582
+ // successor/predecessor edge in between S and L.
583
+ // 2. ER is given a non-local successor edge that points at the successor
584
+ // index in L that points at S. This will enable us to recover the
585
+ // original edge if we need to.
586
+ //
587
+ // Then we continue.
569
588
auto *SuccRegion = getRegion (SuccID.ID );
570
589
if (!LRegion->containsSubregion (SuccRegion)) {
571
590
DEBUG (llvm::dbgs () << " Is not a subregion, replacing.\n " );
@@ -581,13 +600,16 @@ rewriteLoopExitingBlockSuccessors(LoopTy *Loop, RegionTy *LRegion) {
581
600
continue ;
582
601
}
583
602
584
- // If the rpo number of the successor is less than the RPO number of the
585
- // BB, then we know that it is not a backedge.
603
+ // Otherwise, we know S is in L. If the RPO number of S is less than the
604
+ // RPO number of ER, then we know that the edge in between them is not a
605
+ // backedge and thus we do not want to clip the edge.
586
606
if (SuccRegion->getRPONumber () > ExitingRegion->getRPONumber ()) {
587
607
DEBUG (llvm::dbgs () << " Is a subregion, but not a "
588
608
" backedge, not removing.\n " );
589
609
continue ;
590
610
}
611
+
612
+ // If the edge from ER to S is a back edge, we want to clip it.
591
613
DEBUG (llvm::dbgs () << " Is a subregion and a backedge, "
592
614
" removing.\n " );
593
615
auto Iter =
@@ -679,8 +701,8 @@ propagateLivenessDownNonLocalSuccessorEdges(LoopRegion *Parent) {
679
701
if (!SuccID->IsNonLocal )
680
702
continue ;
681
703
682
- // Finally if the non-local successor edge points to a parent successor
683
- // that is not dead continue.
704
+ // If the non-local successor edge points to a parent successor that is
705
+ // not dead continue.
684
706
if (R->Succs [SuccID->ID ].hasValue ())
685
707
continue ;
686
708
0 commit comments