diff --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp index dd3c968341eb1..ffbf4e8ccc123 100644 --- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp +++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp @@ -4468,12 +4468,8 @@ static bool removeEmptyCleanup(CleanupReturnInst *RI, DomTreeUpdater *DTU) { if (UnwindDest) { // First, go through the PHI nodes in UnwindDest and update any nodes that // reference the block we are removing - for (BasicBlock::iterator I = UnwindDest->begin(), - IE = DestEHPad->getIterator(); - I != IE; ++I) { - PHINode *DestPN = cast(I); - - int Idx = DestPN->getBasicBlockIndex(BB); + for (PHINode &DestPN : UnwindDest->phis()) { + int Idx = DestPN.getBasicBlockIndex(BB); // Since BB unwinds to UnwindDest, it has to be in the PHI node. assert(Idx != -1); // This PHI node has an incoming value that corresponds to a control @@ -4487,11 +4483,11 @@ static bool removeEmptyCleanup(CleanupReturnInst *RI, DomTreeUpdater *DTU) { // predecessors must unwind to these blocks, and since no instruction // can have multiple unwind destinations, there will be no overlap in // incoming blocks between SrcPN and DestPN. - Value *SrcVal = DestPN->getIncomingValue(Idx); + Value *SrcVal = DestPN.getIncomingValue(Idx); PHINode *SrcPN = dyn_cast(SrcVal); // Remove the entry for the block we are deleting. - DestPN->removeIncomingValue(Idx, false); + DestPN.removeIncomingValue(Idx, false); if (SrcPN && SrcPN->getParent() == BB) { // If the incoming value was a PHI node in the cleanup pad we are @@ -4499,28 +4495,25 @@ static bool removeEmptyCleanup(CleanupReturnInst *RI, DomTreeUpdater *DTU) { // DestPN. for (unsigned SrcIdx = 0, SrcE = SrcPN->getNumIncomingValues(); SrcIdx != SrcE; ++SrcIdx) { - DestPN->addIncoming(SrcPN->getIncomingValue(SrcIdx), - SrcPN->getIncomingBlock(SrcIdx)); + DestPN.addIncoming(SrcPN->getIncomingValue(SrcIdx), + SrcPN->getIncomingBlock(SrcIdx)); } } else { // Otherwise, the incoming value came from above BB and // so we can just reuse it. We must associate all of BB's // predecessors with this value. for (auto *pred : predecessors(BB)) { - DestPN->addIncoming(SrcVal, pred); + DestPN.addIncoming(SrcVal, pred); } } } // Sink any remaining PHI nodes directly into UnwindDest. Instruction *InsertPt = DestEHPad; - for (BasicBlock::iterator I = BB->begin(), - IE = BB->getFirstNonPHI()->getIterator(); - I != IE;) { + for (PHINode &PN : BB->phis()) { // The iterator must be incremented here because the instructions are // being moved to another block. - PHINode *PN = cast(I++); - if (PN->use_empty() || !PN->isUsedOutsideOfBlock(BB)) + if (PN.use_empty() || !PN.isUsedOutsideOfBlock(BB)) // If the PHI node has no uses or all of its uses are in this basic // block (meaning they are debug or lifetime intrinsics), just leave // it. It will be erased when we erase BB below. @@ -4532,8 +4525,8 @@ static bool removeEmptyCleanup(CleanupReturnInst *RI, DomTreeUpdater *DTU) { // BB. In this case, the PHI value must reference itself. for (auto *pred : predecessors(UnwindDest)) if (pred != BB) - PN->addIncoming(PN, pred); - PN->moveBefore(InsertPt); + PN.addIncoming(&PN, pred); + PN.moveBefore(InsertPt); } }