mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-15 05:24:01 +00:00
move MergeBasicBlockIntoOnlyPred to Transforms/Utils.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@60162 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@ -200,3 +200,36 @@ bool llvm::dceInstruction(BasicBlock::iterator &BBI) {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// Control Flow Graph Restructuring...
|
||||
//
|
||||
|
||||
/// MergeBasicBlockIntoOnlyPred - DestBB is a block with one predecessor and its
|
||||
/// predecessor is known to have one successor (DestBB!). Eliminate the edge
|
||||
/// between them, moving the instructions in the predecessor into DestBB and
|
||||
/// deleting the predecessor block.
|
||||
///
|
||||
void llvm::MergeBasicBlockIntoOnlyPred(BasicBlock *DestBB) {
|
||||
// If BB has single-entry PHI nodes, fold them.
|
||||
while (PHINode *PN = dyn_cast<PHINode>(DestBB->begin())) {
|
||||
Value *NewVal = PN->getIncomingValue(0);
|
||||
// Replace self referencing PHI with undef, it must be dead.
|
||||
if (NewVal == PN) NewVal = UndefValue::get(PN->getType());
|
||||
PN->replaceAllUsesWith(NewVal);
|
||||
PN->eraseFromParent();
|
||||
}
|
||||
|
||||
BasicBlock *PredBB = DestBB->getSinglePredecessor();
|
||||
assert(PredBB && "Block doesn't have a single predecessor!");
|
||||
|
||||
// Splice all the instructions from PredBB to DestBB.
|
||||
PredBB->getTerminator()->eraseFromParent();
|
||||
DestBB->getInstList().splice(DestBB->begin(), PredBB->getInstList());
|
||||
|
||||
// Anything that branched to PredBB now branches to DestBB.
|
||||
PredBB->replaceAllUsesWith(DestBB);
|
||||
|
||||
// Nuke BB.
|
||||
PredBB->eraseFromParent();
|
||||
}
|
||||
|
Reference in New Issue
Block a user