Skip to content

Commit a3a329f

Browse files
committed
Add some comments to LoopRegionAnalysis that explains a few methods in better detail. NFC.
1 parent 56a62b7 commit a3a329f

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

lib/SILOptimizer/Analysis/LoopRegionAnalysis.cpp

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -554,18 +554,37 @@ getExitingRegions(LoopRegionFunctionInfo *LRFI,
554554
void
555555
LoopRegionFunctionInfo::
556556
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.
557564
llvm::SmallVector<RegionTy *, 8> ExitingRegions;
558565
getExitingRegions(this, Loop, LRegion, ExitingRegions);
559566

567+
// Then for each exiting region ER of the Loop L...
560568
DEBUG(llvm::dbgs() << " Visiting Exit Blocks...\n");
561569
for (auto *ExitingRegion : ExitingRegions) {
562570
DEBUG(llvm::dbgs() << " Exiting Region: "
563571
<< ExitingRegion->getID() << "\n");
572+
573+
// For each successor region S of ER...
564574
for (auto SuccID : ExitingRegion->getSuccs()) {
565575
DEBUG(llvm::dbgs() << " Succ: " << SuccID.ID
566576
<< ". IsNonLocal: "
567577
<< (SuccID.IsNonLocal ? "true" : "false") << "\n");
568578

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.
569588
auto *SuccRegion = getRegion(SuccID.ID);
570589
if (!LRegion->containsSubregion(SuccRegion)) {
571590
DEBUG(llvm::dbgs() << " Is not a subregion, replacing.\n");
@@ -581,13 +600,16 @@ rewriteLoopExitingBlockSuccessors(LoopTy *Loop, RegionTy *LRegion) {
581600
continue;
582601
}
583602

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.
586606
if (SuccRegion->getRPONumber() > ExitingRegion->getRPONumber()) {
587607
DEBUG(llvm::dbgs() << " Is a subregion, but not a "
588608
"backedge, not removing.\n");
589609
continue;
590610
}
611+
612+
// If the edge from ER to S is a back edge, we want to clip it.
591613
DEBUG(llvm::dbgs() << " Is a subregion and a backedge, "
592614
"removing.\n");
593615
auto Iter =
@@ -679,8 +701,8 @@ propagateLivenessDownNonLocalSuccessorEdges(LoopRegion *Parent) {
679701
if (!SuccID->IsNonLocal)
680702
continue;
681703

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.
684706
if (R->Succs[SuccID->ID].hasValue())
685707
continue;
686708

0 commit comments

Comments
 (0)