Code clean up.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@100467 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Evan Cheng 2010-04-05 21:16:25 +00:00
parent b6290a170f
commit 0f1666b480
2 changed files with 17 additions and 19 deletions

View File

@ -619,15 +619,15 @@ void LoopUnswitch::UnswitchNontrivialCondition(Value *LIC, Constant *Val,
NewBlocks.reserve(LoopBlocks.size()); NewBlocks.reserve(LoopBlocks.size());
DenseMap<const Value*, Value*> ValueMap; DenseMap<const Value*, Value*> ValueMap;
for (unsigned i = 0, e = LoopBlocks.size(); i != e; ++i) { for (unsigned i = 0, e = LoopBlocks.size(); i != e; ++i) {
BasicBlock *New = CloneBasicBlock(LoopBlocks[i], ValueMap, ".us", F); BasicBlock *NewBB = CloneBasicBlock(LoopBlocks[i], ValueMap, ".us", F);
NewBlocks.push_back(New); NewBlocks.push_back(NewBB);
ValueMap[LoopBlocks[i]] = New; // Keep the BB mapping. ValueMap[LoopBlocks[i]] = NewBB; // Keep the BB mapping.
LPM->cloneBasicBlockSimpleAnalysis(LoopBlocks[i], New, L); LPM->cloneBasicBlockSimpleAnalysis(LoopBlocks[i], NewBB, L);
} }
// Splice the newly inserted blocks into the function right before the // Splice the newly inserted blocks into the function right before the
// original preheader. // original preheader.
F->getBasicBlockList().splice(LoopBlocks[0], F->getBasicBlockList(), F->getBasicBlockList().splice(NewPreheader, F->getBasicBlockList(),
NewBlocks[0], F->end()); NewBlocks[0], F->end());
// Now we create the new Loop object for the versioned loop. // Now we create the new Loop object for the versioned loop.
@ -652,8 +652,8 @@ void LoopUnswitch::UnswitchNontrivialCondition(Value *LIC, Constant *Val,
// If the successor of the exit block had PHI nodes, add an entry for // If the successor of the exit block had PHI nodes, add an entry for
// NewExit. // NewExit.
PHINode *PN; PHINode *PN;
for (BasicBlock::iterator I = ExitSucc->begin(); for (BasicBlock::iterator I = ExitSucc->begin(); isa<PHINode>(I); ++I) {
(PN = dyn_cast<PHINode>(I)); ++I) { PN = cast<PHINode>(I);
Value *V = PN->getIncomingValueForBlock(ExitBlocks[i]); Value *V = PN->getIncomingValueForBlock(ExitBlocks[i]);
DenseMap<const Value *, Value*>::iterator It = ValueMap.find(V); DenseMap<const Value *, Value*>::iterator It = ValueMap.find(V);
if (It != ValueMap.end()) V = It->second; if (It != ValueMap.end()) V = It->second;
@ -682,7 +682,7 @@ void LoopUnswitch::UnswitchNontrivialCondition(Value *LIC, Constant *Val,
// Now we rewrite the original code to know that the condition is true and the // Now we rewrite the original code to know that the condition is true and the
// new code to know that the condition is false. // new code to know that the condition is false.
RewriteLoopBodyWithConditionConstant(L , LIC, Val, false); RewriteLoopBodyWithConditionConstant(L, LIC, Val, false);
// It's possible that simplifying one loop could cause the other to be // It's possible that simplifying one loop could cause the other to be
// deleted. If so, don't simplify it. // deleted. If so, don't simplify it.

View File

@ -336,21 +336,19 @@ BasicBlock *llvm::SplitBlock(BasicBlock *Old, Instruction *SplitPt, Pass *P) {
if (Loop *L = LI->getLoopFor(Old)) if (Loop *L = LI->getLoopFor(Old))
L->addBasicBlockToLoop(New, LI->getBase()); L->addBasicBlockToLoop(New, LI->getBase());
if (DominatorTree *DT = P->getAnalysisIfAvailable<DominatorTree>()) if (DominatorTree *DT = P->getAnalysisIfAvailable<DominatorTree>()) {
{ // Old dominates New. New node domiantes all other nodes dominated by Old.
// Old dominates New. New node domiantes all other nodes dominated by Old. DomTreeNode *OldNode = DT->getNode(Old);
DomTreeNode *OldNode = DT->getNode(Old); std::vector<DomTreeNode *> Children;
std::vector<DomTreeNode *> Children; for (DomTreeNode::iterator I = OldNode->begin(), E = OldNode->end();
for (DomTreeNode::iterator I = OldNode->begin(), E = OldNode->end(); I != E; ++I)
I != E; ++I) Children.push_back(*I);
Children.push_back(*I);
DomTreeNode *NewNode = DT->addNewBlock(New,Old);
DomTreeNode *NewNode = DT->addNewBlock(New,Old);
for (std::vector<DomTreeNode *>::iterator I = Children.begin(), for (std::vector<DomTreeNode *>::iterator I = Children.begin(),
E = Children.end(); I != E; ++I) E = Children.end(); I != E; ++I)
DT->changeImmediateDominator(*I, NewNode); DT->changeImmediateDominator(*I, NewNode);
} }
if (DominanceFrontier *DF = P->getAnalysisIfAvailable<DominanceFrontier>()) if (DominanceFrontier *DF = P->getAnalysisIfAvailable<DominanceFrontier>())
DF->splitBlock(Old); DF->splitBlock(Old);