Remove dead code.
[oota-llvm.git] / lib / VMCore / BasicBlock.cpp
index bdcfb365c6ede372c37280f95ae4d5e0f3c988fe..18a90d6b443d10396aa88024e4fdda150ea74ed7 100644 (file)
@@ -102,6 +102,14 @@ void BasicBlock::eraseFromParent() {
   getParent()->getBasicBlockList().erase(this);
 }
 
+/// moveBefore - Unlink this instruction from its current function and
+/// insert it into the function that MovePos lives in, right before
+/// MovePos.
+void BasicBlock::moveBefore(BasicBlock *MovePos) {
+  MovePos->getParent()->getBasicBlockList().splice(MovePos,
+                       getParent()->getBasicBlockList(), this);
+}
+
 
 TerminatorInst *BasicBlock::getTerminator() {
   if (InstList.empty()) return 0;
@@ -113,6 +121,17 @@ const TerminatorInst *const BasicBlock::getTerminator() const {
   return dyn_cast<TerminatorInst>(&InstList.back());
 }
 
+Instruction* BasicBlock::getFirstNonPHI()
+{
+    BasicBlock::iterator i = begin();
+    // All valid basic blocks should have a terminator,
+    // which is not a PHINode. If we have invalid basic
+    // block we'll get assert when dereferencing past-the-end
+    // iterator.
+    while (isa<PHINode>(i)) ++i;
+    return &*i;
+}
+
 void BasicBlock::dropAllReferences() {
   for(iterator I = begin(), E = end(); I != E; ++I)
     I->dropAllReferences();
@@ -189,7 +208,8 @@ void BasicBlock::removePredecessor(BasicBlock *Pred,
     // Okay, now we know that we need to remove predecessor #pred_idx from all
     // PHI nodes.  Iterate over each PHI node fixing them up
     PHINode *PN;
-    for (iterator II = begin(); (PN = dyn_cast<PHINode>(II)); ++II) {
+    for (iterator II = begin(); (PN = dyn_cast<PHINode>(II)); ) {
+      ++II;
       PN->removeIncomingValue(Pred, false);
       // If all incoming values to the Phi are the same, we can replace the Phi
       // with that value.