[PATCH] D35391: [Dominators] Teach LoopDeletion to use the new incremental API

Jakub Kuderski via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 13 16:25:02 PDT 2017


kuhar created this revision.
Herald added a subscriber: mzolotukhin.

This patch makes LoopDeletion use the incremental DominatorTree API.

This is actually a special usecase of the incremental API -- we know that all of the loop nodes are dominated by the loop preheader, so we can first update the CFG by removing the body and creating an edge from the preaheader to the exit. Instead of deleting and inserting edges as we go, we defer it. Then we can tell the DT that we delete the edge from the preaheader to the header header and the incremental algorithm will automatically disconnect the rest of the loop. When we tell the DT to insert an edge from the preheader to the exit, we are back in sync with the changes that happened to the CFG.


https://reviews.llvm.org/D35391

Files:
  lib/Transforms/Scalar/LoopDeletion.cpp


Index: lib/Transforms/Scalar/LoopDeletion.cpp
===================================================================
--- lib/Transforms/Scalar/LoopDeletion.cpp
+++ lib/Transforms/Scalar/LoopDeletion.cpp
@@ -276,21 +276,12 @@
     ++BI;
   }
 
-  // Update the dominator tree and remove the instructions and blocks that will
-  // be deleted from the reference counting scheme.
-  SmallVector<DomTreeNode*, 8> ChildNodes;
+  // Update the dominator tree. Disconnect the loop by bypassing the loop body.
+  DT.deleteEdge(Preheader, L->getHeader());
+  DT.insertEdge(Preheader, ExitBlock);
+
   for (Loop::block_iterator LI = L->block_begin(), LE = L->block_end();
        LI != LE; ++LI) {
-    // Move all of the block's children to be children of the Preheader, which
-    // allows us to remove the domtree entry for the block.
-    ChildNodes.insert(ChildNodes.begin(), DT[*LI]->begin(), DT[*LI]->end());
-    for (DomTreeNode *ChildNode : ChildNodes) {
-      DT.changeImmediateDominator(ChildNode, DT[Preheader]);
-    }
-
-    ChildNodes.clear();
-    DT.eraseNode(*LI);
-
     // Remove the block from the reference counting scheme, so that we can
     // delete it freely later.
     (*LI)->dropAllReferences();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D35391.106552.patch
Type: text/x-patch
Size: 1216 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170713/b5503397/attachment.bin>


More information about the llvm-commits mailing list