Pretty print large struct constants.
[oota-llvm.git] / lib / VMCore / BasicBlock.cpp
index 98d12d8f1381368a497887dec4fe6037a4942545..ab7798c3866e91a82b673516ce7ea2af587114d6 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;
@@ -189,8 +197,16 @@ 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.
+      if (Value *PNV = PN->hasConstantValue()) {
+        PN->replaceAllUsesWith(PNV);
+        PN->eraseFromParent();
+      }
+    }
   }
 }