aboutsummaryrefslogtreecommitdiff
path: root/lib/Transforms
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2011-01-08 19:08:40 +0000
committerChris Lattner <sabre@nondot.org>2011-01-08 19:08:40 +0000
commitdc85f8ab808aec2f673262f5145eda58538cfb26 (patch)
treeab24fffaae8e64d3a9f1b0a06051d7dd169b5a39 /lib/Transforms
parenta1ae0c74affb3672e75c6d9984dc092886f48454 (diff)
various code cleanups, enhance MergeBlockIntoPredecessor to preserve
loop info. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@123074 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms')
-rw-r--r--lib/Transforms/Utils/BasicBlockUtils.cpp23
1 files changed, 10 insertions, 13 deletions
diff --git a/lib/Transforms/Utils/BasicBlockUtils.cpp b/lib/Transforms/Utils/BasicBlockUtils.cpp
index 6f6fd15a2e..3daa45cec3 100644
--- a/lib/Transforms/Utils/BasicBlockUtils.cpp
+++ b/lib/Transforms/Utils/BasicBlockUtils.cpp
@@ -110,7 +110,7 @@ bool llvm::MergeBlockIntoPredecessor(BasicBlock *BB, Pass *P) {
if (isa<InvokeInst>(PredBB->getTerminator())) return false;
succ_iterator SI(succ_begin(PredBB)), SE(succ_end(PredBB));
- BasicBlock* OnlySucc = BB;
+ BasicBlock *OnlySucc = BB;
for (; SI != SE; ++SI)
if (*SI != OnlySucc) {
OnlySucc = 0; // There are multiple distinct successors!
@@ -131,10 +131,8 @@ bool llvm::MergeBlockIntoPredecessor(BasicBlock *BB, Pass *P) {
}
// Begin by getting rid of unneeded PHIs.
- while (PHINode *PN = dyn_cast<PHINode>(&BB->front())) {
- PN->replaceAllUsesWith(PN->getIncomingValue(0));
- BB->getInstList().pop_front(); // Delete the phi node...
- }
+ if (isa<PHINode>(BB->front()))
+ FoldSingleEntryPHINodes(BB);
// Delete the unconditional branch from the predecessor...
PredBB->getInstList().pop_back();
@@ -152,11 +150,9 @@ bool llvm::MergeBlockIntoPredecessor(BasicBlock *BB, Pass *P) {
// Finally, erase the old block and update dominator info.
if (P) {
- if (DominatorTree* DT = P->getAnalysisIfAvailable<DominatorTree>()) {
- DomTreeNode* DTN = DT->getNode(BB);
- DomTreeNode* PredDTN = DT->getNode(PredBB);
-
- if (DTN) {
+ if (DominatorTree *DT = P->getAnalysisIfAvailable<DominatorTree>()) {
+ if (DomTreeNode *DTN = DT->getNode(BB)) {
+ DomTreeNode *PredDTN = DT->getNode(PredBB);
SmallPtrSet<DomTreeNode*, 8> Children(DTN->begin(), DTN->end());
for (SmallPtrSet<DomTreeNode*, 8>::iterator DI = Children.begin(),
DE = Children.end(); DI != DE; ++DI)
@@ -164,12 +160,13 @@ bool llvm::MergeBlockIntoPredecessor(BasicBlock *BB, Pass *P) {
DT->eraseNode(BB);
}
+
+ if (LoopInfo *LI = P->getAnalysisIfAvailable<LoopInfo>())
+ LI->removeBlock(BB);
}
}
BB->eraseFromParent();
-
-
return true;
}
@@ -276,7 +273,7 @@ BasicBlock *llvm::SplitBlock(BasicBlock *Old, Instruction *SplitPt, Pass *P) {
// The new block lives in whichever loop the old one did. This preserves
// LCSSA as well, because we force the split point to be after any PHI nodes.
- if (LoopInfo* LI = P->getAnalysisIfAvailable<LoopInfo>())
+ if (LoopInfo *LI = P->getAnalysisIfAvailable<LoopInfo>())
if (Loop *L = LI->getLoopFor(Old))
L->addBasicBlockToLoop(New, LI->getBase());