simplify code, fit in 80 cols.

llvm-svn: 50015
This commit is contained in:
Chris Lattner 2008-04-21 00:23:14 +00:00
parent 38806c3e9c
commit aca912d793
1 changed files with 71 additions and 69 deletions

View File

@ -263,14 +263,15 @@ ReprocessLoop:
/// SplitBlockPredecessors - Split the specified block into two blocks. We want
/// to move the predecessors specified in the Preds list to point to the new
/// block, leaving the remaining predecessors pointing to BB. This method
/// updates the SSA PHINode's, but no other analyses.
/// updates the SSA PHINode's and AliasAnalysis, but no other analyses.
///
BasicBlock *LoopSimplify::SplitBlockPredecessors(BasicBlock *BB,
const char *Suffix,
const std::vector<BasicBlock*> &Preds) {
// Create new basic block, insert right before the original block...
BasicBlock *NewBB = BasicBlock::Create(BB->getName()+Suffix, BB->getParent(), BB);
BasicBlock *NewBB =
BasicBlock::Create(BB->getName()+Suffix, BB->getParent(), BB);
// The preheader first gets an unconditional branch to the loop header...
BranchInst *BI = BranchInst::Create(BB, NewBB);
@ -281,7 +282,15 @@ BasicBlock *LoopSimplify::SplitBlockPredecessors(BasicBlock *BB,
// into the PHI nodes for the new edge. If the loop is not dead, we move the
// incoming edges in BB into new PHI nodes in NewBB.
//
if (!Preds.empty()) { // Is the loop not obviously dead?
if (Preds.empty()) { // Is the loop obviously dead?
for (BasicBlock::iterator I = BB->begin(); isa<PHINode>(I); ++I) {
PHINode *PN = cast<PHINode>(I);
// Insert dummy values as the incoming value...
PN->addIncoming(Constant::getNullValue(PN->getType()), NewBB);
}
return NewBB;
}
// Check to see if the values being merged into the new block need PHI
// nodes. If so, insert them.
for (BasicBlock::iterator I = BB->begin(); isa<PHINode>(I); ) {
@ -300,7 +309,8 @@ BasicBlock *LoopSimplify::SplitBlockPredecessors(BasicBlock *BB,
// If the values coming into the block are not the same, we need a PHI.
if (InVal == 0) {
// Create the new PHI node, insert it into NewBB at the end of the block
PHINode *NewPHI = PHINode::Create(PN->getType(), PN->getName()+".ph", BI);
PHINode *NewPHI =
PHINode::Create(PN->getType(), PN->getName()+".ph", BI);
if (AA) AA->copyValue(PN, NewPHI);
// Move all of the edges from blocks outside the loop to the new PHI
@ -347,14 +357,6 @@ BasicBlock *LoopSimplify::SplitBlockPredecessors(BasicBlock *BB,
Preds[i]->setUnwindDest(NewBB);
}
} else { // Otherwise the loop is dead...
for (BasicBlock::iterator I = BB->begin(); isa<PHINode>(I); ++I) {
PHINode *PN = cast<PHINode>(I);
// Insert dummy values as the incoming value...
PN->addIncoming(Constant::getNullValue(PN->getType()), NewBB);
}
}
return NewBB;
}