diff options
author | Roman Lebedev <lebedev.ri@gmail.com> | 2021-04-11 23:08:19 +0300 |
---|---|---|
committer | Roman Lebedev <lebedev.ri@gmail.com> | 2021-04-11 23:56:23 +0300 |
commit | e5692a564a73ef63b7baaf80c2b7a62ad74e9e66 (patch) | |
tree | 56400b1d869eee29412d27e9661503f9f1b921de /llvm/lib/Transforms/Utils/BasicBlockUtils.cpp | |
parent | 2def9c3d8ed9df5a5dc737343c891ac17de1afc1 (diff) | |
download | llvm-e5692a564a73ef63b7baaf80c2b7a62ad74e9e66.zip llvm-e5692a564a73ef63b7baaf80c2b7a62ad74e9e66.tar.gz llvm-e5692a564a73ef63b7baaf80c2b7a62ad74e9e66.tar.bz2 |
[NFCI][BasicBlockUtils] MergeBlockIntoPredecessor(): improve Dominator Tree updating
Same as with TryToSimplifyUncondBranchFromEmptyBlock() patch.
Diffstat (limited to 'llvm/lib/Transforms/Utils/BasicBlockUtils.cpp')
-rw-r--r-- | llvm/lib/Transforms/Utils/BasicBlockUtils.cpp | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp b/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp index 5364dd9..5690200 100644 --- a/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp +++ b/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp @@ -228,20 +228,22 @@ bool llvm::MergeBlockIntoPredecessor(BasicBlock *BB, DomTreeUpdater *DTU, // These dominator edges will be redirected from Pred. std::vector<DominatorTree::UpdateType> Updates; if (DTU) { - SmallPtrSet<BasicBlock *, 2> UniqueSuccessors(succ_begin(BB), succ_end(BB)); - Updates.reserve(1 + (2 * UniqueSuccessors.size())); + SmallPtrSet<BasicBlock *, 2> SuccsOfBB(succ_begin(BB), succ_end(BB)); + SmallPtrSet<BasicBlock *, 2> SuccsOfPredBB(succ_begin(PredBB), + succ_begin(PredBB)); + Updates.reserve(Updates.size() + 2 * SuccsOfBB.size() + 1); // Add insert edges first. Experimentally, for the particular case of two // blocks that can be merged, with a single successor and single predecessor // respectively, it is beneficial to have all insert updates first. Deleting // edges first may lead to unreachable blocks, followed by inserting edges // making the blocks reachable again. Such DT updates lead to high compile // times. We add inserts before deletes here to reduce compile time. - for (BasicBlock *UniqueSuccessor : UniqueSuccessors) - // This successor of BB may already have PredBB as a predecessor. - if (!llvm::is_contained(successors(PredBB), UniqueSuccessor)) - Updates.push_back({DominatorTree::Insert, PredBB, UniqueSuccessor}); - for (BasicBlock *UniqueSuccessor : UniqueSuccessors) - Updates.push_back({DominatorTree::Delete, BB, UniqueSuccessor}); + for (BasicBlock *SuccOfBB : SuccsOfBB) + // This successor of BB may already be a PredBB's successor. + if (!SuccsOfPredBB.contains(SuccOfBB)) + Updates.push_back({DominatorTree::Insert, PredBB, SuccOfBB}); + for (BasicBlock *SuccOfBB : SuccsOfBB) + Updates.push_back({DominatorTree::Delete, BB, SuccOfBB}); Updates.push_back({DominatorTree::Delete, PredBB, BB}); } |