summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/Utils
diff options
context:
space:
mode:
authorBill Wendling <isanbard@gmail.com>2013-10-19 11:27:12 +0000
committerBill Wendling <isanbard@gmail.com>2013-10-19 11:27:12 +0000
commit4fea22c63b5300fd1499bd6e8c445a9579c0d287 (patch)
treed6d0231d70f99f13d771862c54ffdb8f43983e9e /llvm/lib/Transforms/Utils
parentc98028896ddea90e959bc79f4e9b5fca56a86c5a (diff)
downloadbcm5719-llvm-4fea22c63b5300fd1499bd6e8c445a9579c0d287.tar.gz
bcm5719-llvm-4fea22c63b5300fd1499bd6e8c445a9579c0d287.zip
Perform an intelligent splice of the predecessor with the single successor.
If the predecessor's being spliced into a landing pad, then we need the PHIs to come first and the rest of the predecessor's code to come *after* the landing pad instruction. llvm-svn: 193035
Diffstat (limited to 'llvm/lib/Transforms/Utils')
-rw-r--r--llvm/lib/Transforms/Utils/Local.cpp15
1 files changed, 14 insertions, 1 deletions
diff --git a/llvm/lib/Transforms/Utils/Local.cpp b/llvm/lib/Transforms/Utils/Local.cpp
index 82b8da3a107..78217c8efa3 100644
--- a/llvm/lib/Transforms/Utils/Local.cpp
+++ b/llvm/lib/Transforms/Utils/Local.cpp
@@ -503,7 +503,19 @@ void llvm::MergeBasicBlockIntoOnlyPred(BasicBlock *DestBB, Pass *P) {
// Splice all the instructions from PredBB to DestBB.
PredBB->getTerminator()->eraseFromParent();
- DestBB->getInstList().splice(DestBB->begin(), PredBB->getInstList());
+
+ // First splice over the PHI nodes.
+ BasicBlock::iterator PI = PredBB->begin();
+ while (isa<PHINode>(PI))
+ ++PI;
+
+ if (PI != PredBB->begin())
+ DestBB->getInstList().splice(DestBB->begin(), PredBB->getInstList(),
+ PredBB->begin(), PI);
+
+ // Now splice over the rest of the instructions.
+ DestBB->getInstList().splice(DestBB->getFirstInsertionPt(),
+ PredBB->getInstList(), PI, PredBB->end());
if (P) {
DominatorTree *DT = P->getAnalysisIfAvailable<DominatorTree>();
@@ -513,6 +525,7 @@ void llvm::MergeBasicBlockIntoOnlyPred(BasicBlock *DestBB, Pass *P) {
DT->eraseNode(PredBB);
}
}
+
// Nuke BB.
PredBB->eraseFromParent();
}
OpenPOWER on IntegriCloud