diff options
author | Jakub Kuderski <kubakuderski@gmail.com> | 2017-08-02 18:17:52 +0000 |
---|---|---|
committer | Jakub Kuderski <kubakuderski@gmail.com> | 2017-08-02 18:17:52 +0000 |
commit | d869913f3bdb218fcc0e4357b01f1e5ecd8da2b4 (patch) | |
tree | c51f3e4e9e9e7cbc446f310b3154daf7f668d4cb /llvm/unittests/IR/DominatorTreeTest.cpp | |
parent | 0bd906ec8f7839ac9a802b82b48444d647bba88c (diff) | |
download | bcm5719-llvm-d869913f3bdb218fcc0e4357b01f1e5ecd8da2b4.tar.gz bcm5719-llvm-d869913f3bdb218fcc0e4357b01f1e5ecd8da2b4.zip |
[Dominators] Teach LoopDeletion to use the new incremental API
Summary:
This patch makes LoopDeletion use the incremental DominatorTree API.
We modify LoopDeletion to perform the deletion in 5 steps:
1. Create a new dummy edge from the preheader to the exit, by adding a conditional branch.
2. Inform the DomTree about the new edge.
3. Remove the conditional branch and replace it with an unconditional edge to the exit. This removes the edge to the loop header, making it unreachable.
4. Inform the DomTree about the deleted edge.
5. Remove the unreachable block from the function.
Creating the dummy conditional branch is necessary to perform incremental DomTree update.
We should consider using the batch updater when it's ready.
Reviewers: dberlin, davide, grosser, sanjoy
Reviewed By: dberlin, grosser
Subscribers: mzolotukhin, llvm-commits
Differential Revision: https://reviews.llvm.org/D35391
llvm-svn: 309850
Diffstat (limited to 'llvm/unittests/IR/DominatorTreeTest.cpp')
-rw-r--r-- | llvm/unittests/IR/DominatorTreeTest.cpp | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/llvm/unittests/IR/DominatorTreeTest.cpp b/llvm/unittests/IR/DominatorTreeTest.cpp index 5856d5539a0..da5d5025e23 100644 --- a/llvm/unittests/IR/DominatorTreeTest.cpp +++ b/llvm/unittests/IR/DominatorTreeTest.cpp @@ -797,6 +797,36 @@ TEST(DominatorTree, DeleteUnreachable) { } } +TEST(DominatorTree, DeletionsInSubtrees) { + CFGHolder Holder; + std::vector<CFGBuilder::Arc> Arcs = {{"0", "1"}, {"1", "2"}, {"1", "3"}, + {"1", "6"}, {"3", "4"}, {"2", "5"}, + {"5", "2"}}; + + // It is possible to perform multiple deletions and inform the + // DominatorTree about them at the same time, if the all of the + // deletions happen in different subtrees. + std::vector<CFGBuilder::Update> Updates = {{Delete, {"1", "2"}}, + {Delete, {"1", "3"}}}; + CFGBuilder B(Holder.F, Arcs, Updates); + DominatorTree DT(*Holder.F); + EXPECT_TRUE(DT.verify()); + + Optional<CFGBuilder::Update> LastUpdate; + while ((LastUpdate = B.applyUpdate())) + ; + + DT.deleteEdge(B.getOrAddBlock("1"), B.getOrAddBlock("2")); + DT.deleteEdge(B.getOrAddBlock("1"), B.getOrAddBlock("3")); + + EXPECT_TRUE(DT.verify()); + EXPECT_EQ(DT.getNode(B.getOrAddBlock("2")), nullptr); + EXPECT_EQ(DT.getNode(B.getOrAddBlock("3")), nullptr); + EXPECT_EQ(DT.getNode(B.getOrAddBlock("4")), nullptr); + EXPECT_EQ(DT.getNode(B.getOrAddBlock("5")), nullptr); + EXPECT_NE(DT.getNode(B.getOrAddBlock("6")), nullptr); +} + TEST(DominatorTree, InsertDelete) { std::vector<CFGBuilder::Arc> Arcs = { {"1", "2"}, {"2", "3"}, {"3", "4"}, {"4", "5"}, {"5", "6"}, {"5", "7"}, |