Skip to content

Commit ab5fee2

Browse files
committed
Add some detailed comments explaining some of the code.
1 parent 96d329e commit ab5fee2

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

lib/SILOptimizer/Mandatory/TFCanonicalizeCFG.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -843,6 +843,7 @@ void SingleExitLoopTransformer::ensureSingleExitBlock() {
843843
// Update loop info if this belongs to a parent loop.
844844
SILLoop *outsideBlockLoop = LI->getLoopFor(outsideBlock);
845845
if (outsideBlockLoop == nullptr) {
846+
// outsideBlock is not part of any other loop. Simply add it to our loop.
846847
loop->addBasicBlockToLoop(outsideBlock, LI->getBase());
847848
} else {
848849
// We deal with the case where the nodes being moved in
@@ -854,13 +855,17 @@ void SingleExitLoopTransformer::ensureSingleExitBlock() {
854855
// }
855856
// }
856857
if (outsideBlockLoop->contains(loop)) {
857-
// `loop` is nested within `outsideBlockLoop`. Move the node from
858-
// `outsideBlockLoop` into our `loop`.
858+
// If our `loop` is nested within `outsideBlockLoop`. Move the node
859+
// from `outsideBlockLoop` into our `loop`.
859860
outsideBlockLoop->removeBlockFromLoop(outsideBlock);
860861
LI->changeLoopFor(outsideBlock, nullptr);
861862
loop->addBasicBlockToLoop(outsideBlock, LI->getBase());
862863
} else {
864+
// We should only nest `outsideBlockLoop` into our `loop` when we
865+
// process the very first node of the `outsideBlockLoop`. Check that we
866+
// have not already nested the `outsideBlockLoop` into our `loop`.
863867
if (!loop->contains(outsideBlockLoop)) {
868+
// Not yet nested, adjust the LoopInfo w.r.t nesting.
864869
if (outsideBlockLoop->getParentLoop() == nullptr) {
865870
// Remove from top-level loops as we are nesting it in `loop`.
866871
LI->removeLoop(llvm::find(*LI, outsideBlockLoop));
@@ -877,7 +882,6 @@ void SingleExitLoopTransformer::ensureSingleExitBlock() {
877882
// top-level loop is already correct.
878883
}
879884
}
880-
881885
if (cloner.hasCloned()) {
882886
// TODO(https://bugs.swift.org/browse/SR-8336): the transformations here are
883887
// simple that we should be able to incrementally update the DI & PDI.

0 commit comments

Comments
 (0)