forked from OSchip/llvm-project
[NFC][SimplifyCFG] removeEmptyCleanup(): use BasicBlock::phis()
This commit is contained in:
parent
c1eaa1168a
commit
a0be081646
|
@ -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<PHINode>(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<PHINode>(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,7 +4495,7 @@ static bool removeEmptyCleanup(CleanupReturnInst *RI, DomTreeUpdater *DTU) {
|
|||
// DestPN.
|
||||
for (unsigned SrcIdx = 0, SrcE = SrcPN->getNumIncomingValues();
|
||||
SrcIdx != SrcE; ++SrcIdx) {
|
||||
DestPN->addIncoming(SrcPN->getIncomingValue(SrcIdx),
|
||||
DestPN.addIncoming(SrcPN->getIncomingValue(SrcIdx),
|
||||
SrcPN->getIncomingBlock(SrcIdx));
|
||||
}
|
||||
} else {
|
||||
|
@ -4507,20 +4503,17 @@ static bool removeEmptyCleanup(CleanupReturnInst *RI, DomTreeUpdater *DTU) {
|
|||
// 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<PHINode>(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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue