forked from OSchip/llvm-project
[NFC] Factor out detatchment of dead blocks from their erasing
llvm-svn: 353277
This commit is contained in:
parent
a4ccfc1841
commit
36b392cbe4
|
@ -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);
|
||||
|
||||
|
|
|
@ -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 <BasicBlock *> BBs,
|
|||
"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);
|
||||
|
||||
|
|
Loading…
Reference in New Issue