Skip to content

Commit a0be081

Browse files
committed
[NFC][SimplifyCFG] removeEmptyCleanup(): use BasicBlock::phis()
1 parent c1eaa11 commit a0be081

File tree

1 file changed

+11
-18
lines changed

1 file changed

+11
-18
lines changed

llvm/lib/Transforms/Utils/SimplifyCFG.cpp

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4468,12 +4468,8 @@ static bool removeEmptyCleanup(CleanupReturnInst *RI, DomTreeUpdater *DTU) {
44684468
if (UnwindDest) {
44694469
// First, go through the PHI nodes in UnwindDest and update any nodes that
44704470
// 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);
44774473
// Since BB unwinds to UnwindDest, it has to be in the PHI node.
44784474
assert(Idx != -1);
44794475
// This PHI node has an incoming value that corresponds to a control
@@ -4487,40 +4483,37 @@ static bool removeEmptyCleanup(CleanupReturnInst *RI, DomTreeUpdater *DTU) {
44874483
// predecessors must unwind to these blocks, and since no instruction
44884484
// can have multiple unwind destinations, there will be no overlap in
44894485
// incoming blocks between SrcPN and DestPN.
4490-
Value *SrcVal = DestPN->getIncomingValue(Idx);
4486+
Value *SrcVal = DestPN.getIncomingValue(Idx);
44914487
PHINode *SrcPN = dyn_cast<PHINode>(SrcVal);
44924488

44934489
// Remove the entry for the block we are deleting.
4494-
DestPN->removeIncomingValue(Idx, false);
4490+
DestPN.removeIncomingValue(Idx, false);
44954491

44964492
if (SrcPN && SrcPN->getParent() == BB) {
44974493
// If the incoming value was a PHI node in the cleanup pad we are
44984494
// removing, we need to merge that PHI node's incoming values into
44994495
// DestPN.
45004496
for (unsigned SrcIdx = 0, SrcE = SrcPN->getNumIncomingValues();
45014497
SrcIdx != SrcE; ++SrcIdx) {
4502-
DestPN->addIncoming(SrcPN->getIncomingValue(SrcIdx),
4503-
SrcPN->getIncomingBlock(SrcIdx));
4498+
DestPN.addIncoming(SrcPN->getIncomingValue(SrcIdx),
4499+
SrcPN->getIncomingBlock(SrcIdx));
45044500
}
45054501
} else {
45064502
// Otherwise, the incoming value came from above BB and
45074503
// so we can just reuse it. We must associate all of BB's
45084504
// predecessors with this value.
45094505
for (auto *pred : predecessors(BB)) {
4510-
DestPN->addIncoming(SrcVal, pred);
4506+
DestPN.addIncoming(SrcVal, pred);
45114507
}
45124508
}
45134509
}
45144510

45154511
// Sink any remaining PHI nodes directly into UnwindDest.
45164512
Instruction *InsertPt = DestEHPad;
4517-
for (BasicBlock::iterator I = BB->begin(),
4518-
IE = BB->getFirstNonPHI()->getIterator();
4519-
I != IE;) {
4513+
for (PHINode &PN : BB->phis()) {
45204514
// The iterator must be incremented here because the instructions are
45214515
// 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))
45244517
// If the PHI node has no uses or all of its uses are in this basic
45254518
// block (meaning they are debug or lifetime intrinsics), just leave
45264519
// it. It will be erased when we erase BB below.
@@ -4532,8 +4525,8 @@ static bool removeEmptyCleanup(CleanupReturnInst *RI, DomTreeUpdater *DTU) {
45324525
// BB. In this case, the PHI value must reference itself.
45334526
for (auto *pred : predecessors(UnwindDest))
45344527
if (pred != BB)
4535-
PN->addIncoming(PN, pred);
4536-
PN->moveBefore(InsertPt);
4528+
PN.addIncoming(&PN, pred);
4529+
PN.moveBefore(InsertPt);
45374530
}
45384531
}
45394532

0 commit comments

Comments
 (0)