[NFCI][Local] removeUnreachableBlocks(): use DeleteDeadBlocks()

This commit is contained in:
Roman Lebedev 2021-05-19 18:20:25 +03:00
parent e5d59db469
commit b0bb2149b3
No known key found for this signature in database
GPG Key ID: 083C3EBB4A1689E0
1 changed files with 1 additions and 38 deletions

View File

@ -2428,44 +2428,7 @@ bool llvm::removeUnreachableBlocks(Function &F, DomTreeUpdater *DTU,
if (MSSAU)
MSSAU->removeBlocks(BlocksToRemove);
// Loop over all of the basic blocks that are up for removal, dropping all of
// their internal references. Update DTU if available.
std::vector<DominatorTree::UpdateType> Updates;
for (auto *BB : BlocksToRemove) {
SmallSet<BasicBlock *, 8> UniqueSuccessors;
for (BasicBlock *Successor : successors(BB)) {
// Only remove references to BB in reachable successors of BB.
if (Reachable.count(Successor))
Successor->removePredecessor(BB);
if (DTU)
UniqueSuccessors.insert(Successor);
}
BB->dropAllReferences();
if (DTU) {
Instruction *TI = BB->getTerminator();
assert(TI && "Basic block should have a terminator");
// Terminators like invoke can have users. We have to replace their users,
// before removing them.
if (!TI->use_empty())
TI->replaceAllUsesWith(UndefValue::get(TI->getType()));
TI->eraseFromParent();
new UnreachableInst(BB->getContext(), BB);
assert(succ_empty(BB) && "The successor list of BB isn't empty before "
"applying corresponding DTU updates.");
Updates.reserve(Updates.size() + UniqueSuccessors.size());
for (auto *UniqueSuccessor : UniqueSuccessors)
Updates.push_back({DominatorTree::Delete, BB, UniqueSuccessor});
}
}
if (DTU) {
DTU->applyUpdates(Updates);
for (auto *BB : BlocksToRemove)
DTU->deleteBB(BB);
} else {
for (auto *BB : BlocksToRemove)
BB->eraseFromParent();
}
DeleteDeadBlocks(BlocksToRemove.takeVector(), DTU);
return Changed;
}