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) {
|
if (UnwindDest) {
|
||||||
// First, go through the PHI nodes in UnwindDest and update any nodes that
|
// First, go through the PHI nodes in UnwindDest and update any nodes that
|
||||||
// reference the block we are removing
|
// reference the block we are removing
|
||||||
for (BasicBlock::iterator I = UnwindDest->begin(),
|
for (PHINode &DestPN : UnwindDest->phis()) {
|
||||||
IE = DestEHPad->getIterator();
|
int Idx = DestPN.getBasicBlockIndex(BB);
|
||||||
I != IE; ++I) {
|
|
||||||
PHINode *DestPN = cast<PHINode>(I);
|
|
||||||
|
|
||||||
int Idx = DestPN->getBasicBlockIndex(BB);
|
|
||||||
// Since BB unwinds to UnwindDest, it has to be in the PHI node.
|
// Since BB unwinds to UnwindDest, it has to be in the PHI node.
|
||||||
assert(Idx != -1);
|
assert(Idx != -1);
|
||||||
// This PHI node has an incoming value that corresponds to a control
|
// 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
|
// predecessors must unwind to these blocks, and since no instruction
|
||||||
// can have multiple unwind destinations, there will be no overlap in
|
// can have multiple unwind destinations, there will be no overlap in
|
||||||
// incoming blocks between SrcPN and DestPN.
|
// incoming blocks between SrcPN and DestPN.
|
||||||
Value *SrcVal = DestPN->getIncomingValue(Idx);
|
Value *SrcVal = DestPN.getIncomingValue(Idx);
|
||||||
PHINode *SrcPN = dyn_cast<PHINode>(SrcVal);
|
PHINode *SrcPN = dyn_cast<PHINode>(SrcVal);
|
||||||
|
|
||||||
// Remove the entry for the block we are deleting.
|
// Remove the entry for the block we are deleting.
|
||||||
DestPN->removeIncomingValue(Idx, false);
|
DestPN.removeIncomingValue(Idx, false);
|
||||||
|
|
||||||
if (SrcPN && SrcPN->getParent() == BB) {
|
if (SrcPN && SrcPN->getParent() == BB) {
|
||||||
// If the incoming value was a PHI node in the cleanup pad we are
|
// 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.
|
// DestPN.
|
||||||
for (unsigned SrcIdx = 0, SrcE = SrcPN->getNumIncomingValues();
|
for (unsigned SrcIdx = 0, SrcE = SrcPN->getNumIncomingValues();
|
||||||
SrcIdx != SrcE; ++SrcIdx) {
|
SrcIdx != SrcE; ++SrcIdx) {
|
||||||
DestPN->addIncoming(SrcPN->getIncomingValue(SrcIdx),
|
DestPN.addIncoming(SrcPN->getIncomingValue(SrcIdx),
|
||||||
SrcPN->getIncomingBlock(SrcIdx));
|
SrcPN->getIncomingBlock(SrcIdx));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Otherwise, the incoming value came from above BB and
|
// Otherwise, the incoming value came from above BB and
|
||||||
// so we can just reuse it. We must associate all of BB's
|
// so we can just reuse it. We must associate all of BB's
|
||||||
// predecessors with this value.
|
// predecessors with this value.
|
||||||
for (auto *pred : predecessors(BB)) {
|
for (auto *pred : predecessors(BB)) {
|
||||||
DestPN->addIncoming(SrcVal, pred);
|
DestPN.addIncoming(SrcVal, pred);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sink any remaining PHI nodes directly into UnwindDest.
|
// Sink any remaining PHI nodes directly into UnwindDest.
|
||||||
Instruction *InsertPt = DestEHPad;
|
Instruction *InsertPt = DestEHPad;
|
||||||
for (BasicBlock::iterator I = BB->begin(),
|
for (PHINode &PN : BB->phis()) {
|
||||||
IE = BB->getFirstNonPHI()->getIterator();
|
|
||||||
I != IE;) {
|
|
||||||
// The iterator must be incremented here because the instructions are
|
// The iterator must be incremented here because the instructions are
|
||||||
// being moved to another block.
|
// 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
|
// 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
|
// block (meaning they are debug or lifetime intrinsics), just leave
|
||||||
// it. It will be erased when we erase BB below.
|
// 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.
|
// BB. In this case, the PHI value must reference itself.
|
||||||
for (auto *pred : predecessors(UnwindDest))
|
for (auto *pred : predecessors(UnwindDest))
|
||||||
if (pred != BB)
|
if (pred != BB)
|
||||||
PN->addIncoming(PN, pred);
|
PN.addIncoming(&PN, pred);
|
||||||
PN->moveBefore(InsertPt);
|
PN.moveBefore(InsertPt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue