@@ -2428,44 +2428,7 @@ bool llvm::removeUnreachableBlocks(Function &F, DomTreeUpdater *DTU,
2428
2428
if (MSSAU)
2429
2429
MSSAU->removeBlocks (BlocksToRemove);
2430
2430
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);
2469
2432
2470
2433
return Changed;
2471
2434
}
0 commit comments