[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:42:39 PDT 2017
kuhar updated this revision to Diff 106555.
kuhar added a comment.
Make the edited for loop more concise.
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,25 +276,23 @@
++BI;
}
- // Update the dominator tree and remove the instructions and blocks that will
- // be deleted from the reference counting scheme.
- SmallVector<DomTreeNode*, 8> ChildNodes;
- 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();
- }
+ // Update the dominator tree. Disconnect the loop by bypassing the loop body.
+ //
+ // This is a special use of the incremental API.
+ // We know that all of the loop nodes are dominated by the loop preheader.
+ // Instead of telling the DT of deleting and inserting edges as we go, we
+ // defer it until here. We tell the DT that we delete the edge from the
+ // preaheader to the 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.
+ DT.deleteEdge(Preheader, L->getHeader());
+ DT.insertEdge(Preheader, ExitBlock);
+
+ // Remove the block from the reference counting scheme, so that we can
+ // delete it freely later.
+ for (auto *Block : L->blocks())
+ Block->dropAllReferences();
// Erase the instructions and the blocks without having to worry
// about ordering because we already dropped the references.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D35391.106555.patch
Type: text/x-patch
Size: 2079 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170713/8629870f/attachment.bin>
More information about the llvm-commits
mailing list