@@ -4468,12 +4468,8 @@ static bool removeEmptyCleanup(CleanupReturnInst *RI, DomTreeUpdater *DTU) {
4468
4468
if (UnwindDest) {
4469
4469
// First, go through the PHI nodes in UnwindDest and update any nodes that
4470
4470
// reference the block we are removing
4471
- for (BasicBlock::iterator I = UnwindDest->begin (),
4472
- IE = DestEHPad->getIterator ();
4473
- I != IE; ++I) {
4474
- PHINode *DestPN = cast<PHINode>(I);
4475
-
4476
- int Idx = DestPN->getBasicBlockIndex (BB);
4471
+ for (PHINode &DestPN : UnwindDest->phis ()) {
4472
+ int Idx = DestPN.getBasicBlockIndex (BB);
4477
4473
// Since BB unwinds to UnwindDest, it has to be in the PHI node.
4478
4474
assert (Idx != -1 );
4479
4475
// This PHI node has an incoming value that corresponds to a control
@@ -4487,40 +4483,37 @@ static bool removeEmptyCleanup(CleanupReturnInst *RI, DomTreeUpdater *DTU) {
4487
4483
// predecessors must unwind to these blocks, and since no instruction
4488
4484
// can have multiple unwind destinations, there will be no overlap in
4489
4485
// incoming blocks between SrcPN and DestPN.
4490
- Value *SrcVal = DestPN-> getIncomingValue (Idx);
4486
+ Value *SrcVal = DestPN. getIncomingValue (Idx);
4491
4487
PHINode *SrcPN = dyn_cast<PHINode>(SrcVal);
4492
4488
4493
4489
// Remove the entry for the block we are deleting.
4494
- DestPN-> removeIncomingValue (Idx, false );
4490
+ DestPN. removeIncomingValue (Idx, false );
4495
4491
4496
4492
if (SrcPN && SrcPN->getParent () == BB) {
4497
4493
// If the incoming value was a PHI node in the cleanup pad we are
4498
4494
// removing, we need to merge that PHI node's incoming values into
4499
4495
// DestPN.
4500
4496
for (unsigned SrcIdx = 0 , SrcE = SrcPN->getNumIncomingValues ();
4501
4497
SrcIdx != SrcE; ++SrcIdx) {
4502
- DestPN-> addIncoming (SrcPN->getIncomingValue (SrcIdx),
4503
- SrcPN->getIncomingBlock (SrcIdx));
4498
+ DestPN. addIncoming (SrcPN->getIncomingValue (SrcIdx),
4499
+ SrcPN->getIncomingBlock (SrcIdx));
4504
4500
}
4505
4501
} else {
4506
4502
// Otherwise, the incoming value came from above BB and
4507
4503
// so we can just reuse it. We must associate all of BB's
4508
4504
// predecessors with this value.
4509
4505
for (auto *pred : predecessors (BB)) {
4510
- DestPN-> addIncoming (SrcVal, pred);
4506
+ DestPN. addIncoming (SrcVal, pred);
4511
4507
}
4512
4508
}
4513
4509
}
4514
4510
4515
4511
// Sink any remaining PHI nodes directly into UnwindDest.
4516
4512
Instruction *InsertPt = DestEHPad;
4517
- for (BasicBlock::iterator I = BB->begin (),
4518
- IE = BB->getFirstNonPHI ()->getIterator ();
4519
- I != IE;) {
4513
+ for (PHINode &PN : BB->phis ()) {
4520
4514
// The iterator must be incremented here because the instructions are
4521
4515
// being moved to another block.
4522
- PHINode *PN = cast<PHINode>(I++);
4523
- if (PN->use_empty () || !PN->isUsedOutsideOfBlock (BB))
4516
+ if (PN.use_empty () || !PN.isUsedOutsideOfBlock (BB))
4524
4517
// If the PHI node has no uses or all of its uses are in this basic
4525
4518
// block (meaning they are debug or lifetime intrinsics), just leave
4526
4519
// it. It will be erased when we erase BB below.
@@ -4532,8 +4525,8 @@ static bool removeEmptyCleanup(CleanupReturnInst *RI, DomTreeUpdater *DTU) {
4532
4525
// BB. In this case, the PHI value must reference itself.
4533
4526
for (auto *pred : predecessors (UnwindDest))
4534
4527
if (pred != BB)
4535
- PN-> addIncoming (PN, pred);
4536
- PN-> moveBefore (InsertPt);
4528
+ PN. addIncoming (& PN, pred);
4529
+ PN. moveBefore (InsertPt);
4537
4530
}
4538
4531
}
4539
4532
0 commit comments