Skip to content

Commit b0bb214

Browse files
committed
[NFCI][Local] removeUnreachableBlocks(): use DeleteDeadBlocks()
1 parent e5d59db commit b0bb214

File tree

1 file changed

+1
-38
lines changed

1 file changed

+1
-38
lines changed

llvm/lib/Transforms/Utils/Local.cpp

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2428,44 +2428,7 @@ bool llvm::removeUnreachableBlocks(Function &F, DomTreeUpdater *DTU,
24282428
if (MSSAU)
24292429
MSSAU->removeBlocks(BlocksToRemove);
24302430

2431-
// Loop over all of the basic blocks that are up for removal, dropping all of
2432-
// their internal references. Update DTU if available.
2433-
std::vector<DominatorTree::UpdateType> Updates;
2434-
for (auto *BB : BlocksToRemove) {
2435-
SmallSet<BasicBlock *, 8> UniqueSuccessors;
2436-
for (BasicBlock *Successor : successors(BB)) {
2437-
// Only remove references to BB in reachable successors of BB.
2438-
if (Reachable.count(Successor))
2439-
Successor->removePredecessor(BB);
2440-
if (DTU)
2441-
UniqueSuccessors.insert(Successor);
2442-
}
2443-
BB->dropAllReferences();
2444-
if (DTU) {
2445-
Instruction *TI = BB->getTerminator();
2446-
assert(TI && "Basic block should have a terminator");
2447-
// Terminators like invoke can have users. We have to replace their users,
2448-
// before removing them.
2449-
if (!TI->use_empty())
2450-
TI->replaceAllUsesWith(UndefValue::get(TI->getType()));
2451-
TI->eraseFromParent();
2452-
new UnreachableInst(BB->getContext(), BB);
2453-
assert(succ_empty(BB) && "The successor list of BB isn't empty before "
2454-
"applying corresponding DTU updates.");
2455-
Updates.reserve(Updates.size() + UniqueSuccessors.size());
2456-
for (auto *UniqueSuccessor : UniqueSuccessors)
2457-
Updates.push_back({DominatorTree::Delete, BB, UniqueSuccessor});
2458-
}
2459-
}
2460-
2461-
if (DTU) {
2462-
DTU->applyUpdates(Updates);
2463-
for (auto *BB : BlocksToRemove)
2464-
DTU->deleteBB(BB);
2465-
} else {
2466-
for (auto *BB : BlocksToRemove)
2467-
BB->eraseFromParent();
2468-
}
2431+
DeleteDeadBlocks(BlocksToRemove.takeVector(), DTU);
24692432

24702433
return Changed;
24712434
}

0 commit comments

Comments
 (0)