[llvm] r353277 - [NFC] Factor out detatchment of dead blocks from their erasing
Max Kazantsev via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 5 23:56:36 PST 2019
Author: mkazantsev
Date: Tue Feb 5 23:56:36 2019
New Revision: 353277
URL: http://llvm.org/viewvc/llvm-project?rev=353277&view=rev
Log:
[NFC] Factor out detatchment of dead blocks from their erasing
Modified:
llvm/trunk/include/llvm/Transforms/Utils/BasicBlockUtils.h
llvm/trunk/lib/Transforms/Utils/BasicBlockUtils.cpp
Modified: llvm/trunk/include/llvm/Transforms/Utils/BasicBlockUtils.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Transforms/Utils/BasicBlockUtils.h?rev=353277&r1=353276&r2=353277&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Transforms/Utils/BasicBlockUtils.h (original)
+++ llvm/trunk/include/llvm/Transforms/Utils/BasicBlockUtils.h Tue Feb 5 23:56:36 2019
@@ -39,6 +39,12 @@ class ReturnInst;
class TargetLibraryInfo;
class Value;
+/// Replace contents of every block in \p BBs with single unreachable
+/// instruction. If \p Updates is specified, collect all necessary DT updates
+/// into this vector.
+void DetatchDeadBlocks(ArrayRef <BasicBlock *> BBs,
+ SmallVectorImpl<DominatorTree::UpdateType> *Updates);
+
/// Delete the specified block, which must have no predecessors.
void DeleteDeadBlock(BasicBlock *BB, DomTreeUpdater *DTU = nullptr);
Modified: llvm/trunk/lib/Transforms/Utils/BasicBlockUtils.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/BasicBlockUtils.cpp?rev=353277&r1=353276&r2=353277&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/BasicBlockUtils.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/BasicBlockUtils.cpp Tue Feb 5 23:56:36 2019
@@ -47,29 +47,17 @@
using namespace llvm;
-void llvm::DeleteDeadBlock(BasicBlock *BB, DomTreeUpdater *DTU) {
- DeleteDeadBlocks({BB}, DTU);
-}
-
-void llvm::DeleteDeadBlocks(ArrayRef <BasicBlock *> BBs,
- DomTreeUpdater *DTU) {
-#ifndef NDEBUG
- // Make sure that all predecessors of each dead block is also dead.
- SmallPtrSet<BasicBlock *, 4> Dead(BBs.begin(), BBs.end());
- assert(Dead.size() == BBs.size() && "Duplicating blocks?");
- for (auto *BB : Dead)
- for (BasicBlock *Pred : predecessors(BB))
- assert(Dead.count(Pred) && "All predecessors must be dead!");
-#endif
-
- SmallVector<DominatorTree::UpdateType, 4> Updates;
+void llvm::DetatchDeadBlocks(
+ ArrayRef<BasicBlock *> BBs,
+ SmallVectorImpl<DominatorTree::UpdateType> *Updates) {
for (auto *BB : BBs) {
// Loop through all of our successors and make sure they know that one
// of their predecessors is going away.
+ SmallPtrSet<BasicBlock *, 4> UniqueSuccessors;
for (BasicBlock *Succ : successors(BB)) {
Succ->removePredecessor(BB);
- if (DTU)
- Updates.push_back({DominatorTree::Delete, BB, Succ});
+ if (Updates && UniqueSuccessors.insert(Succ).second)
+ Updates->push_back({DominatorTree::Delete, BB, Succ});
}
// Zap all the instructions in the block.
@@ -90,6 +78,26 @@ void llvm::DeleteDeadBlocks(ArrayRef <Ba
"The successor list of BB isn't empty before "
"applying corresponding DTU updates.");
}
+}
+
+void llvm::DeleteDeadBlock(BasicBlock *BB, DomTreeUpdater *DTU) {
+ DeleteDeadBlocks({BB}, DTU);
+}
+
+void llvm::DeleteDeadBlocks(ArrayRef <BasicBlock *> BBs,
+ DomTreeUpdater *DTU) {
+#ifndef NDEBUG
+ // Make sure that all predecessors of each dead block is also dead.
+ SmallPtrSet<BasicBlock *, 4> Dead(BBs.begin(), BBs.end());
+ assert(Dead.size() == BBs.size() && "Duplicating blocks?");
+ for (auto *BB : Dead)
+ for (BasicBlock *Pred : predecessors(BB))
+ assert(Dead.count(Pred) && "All predecessors must be dead!");
+#endif
+
+ SmallVector<DominatorTree::UpdateType, 4> Updates;
+ DetatchDeadBlocks(BBs, DTU ? &Updates : nullptr);
+
if (DTU)
DTU->applyUpdates(Updates, /*ForceRemoveDuplicates*/ true);
More information about the llvm-commits
mailing list