Factor some code into a new FoldSingleEntryPHINodes method.
llvm-svn: 60501
This commit is contained in:
@@ -54,6 +54,24 @@ void llvm::DeleteDeadBlock(BasicBlock *BB) {
|
||||
BB->eraseFromParent();
|
||||
}
|
||||
|
||||
/// FoldSingleEntryPHINodes - We know that BB has one predecessor. If there are
|
||||
/// any single-entry PHI nodes in it, fold them away. This handles the case
|
||||
/// when all entries to the PHI nodes in a block are guaranteed equal, such as
|
||||
/// when the block has exactly one predecessor.
|
||||
void llvm::FoldSingleEntryPHINodes(BasicBlock *BB) {
|
||||
if (!isa<PHINode>(BB->begin()))
|
||||
return;
|
||||
|
||||
while (PHINode *PN = dyn_cast<PHINode>(BB->begin())) {
|
||||
if (PN->getIncomingValue(0) != PN)
|
||||
PN->replaceAllUsesWith(PN->getIncomingValue(0));
|
||||
else
|
||||
PN->replaceAllUsesWith(UndefValue::get(PN->getType()));
|
||||
PN->eraseFromParent();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// MergeBlockIntoPredecessor - Attempts to merge a block into its predecessor,
|
||||
/// if possible. The return value indicates success or failure.
|
||||
bool llvm::MergeBlockIntoPredecessor(BasicBlock* BB, Pass* P) {
|
||||
|
||||
Reference in New Issue
Block a user