Fix warning
[oota-llvm.git] / lib / VMCore / BasicBlock.cpp
index bf7191c659328fa5435731abd9cf756c277f0e4a..6ddcc08c8287a3f876a6b06e69851c7cc114c44c 100644 (file)
@@ -19,7 +19,7 @@
 // instruction list.  This is not a real instruction.
 //
 struct DummyInst : public Instruction {
-  DummyInst() : Instruction(Type::VoidTy, NumOtherOps) {
+  DummyInst() : Instruction(Type::VoidTy, OtherOpsEnd) {
     // This should not be garbage monitored.
     LeakDetector::removeGarbageObject(this);
   }
@@ -33,7 +33,7 @@ struct DummyInst : public Instruction {
   // Methods for support type inquiry through isa, cast, and dyn_cast...
   static inline bool classof(const DummyInst *) { return true; }
   static inline bool classof(const Instruction *I) {
-    return I->getOpcode() == NumOtherOps;
+    return I->getOpcode() == OtherOpsEnd;
   }
   static inline bool classof(const Value *V) {
     return isa<Instruction>(V) && classof(cast<Instruction>(V));
@@ -67,6 +67,26 @@ BasicBlock::BasicBlock(const std::string &name, Function *Parent)
     Parent->getBasicBlockList().push_back(this);
 }
 
+/// BasicBlock ctor - If the InsertBefore parameter is specified, the basic
+/// block is automatically inserted right before the specified block.
+///
+BasicBlock::BasicBlock(const std::string &Name, BasicBlock *InsertBefore)
+  : Value(Type::LabelTy, Value::BasicBlockVal, Name) {
+  // Initialize the instlist...
+  InstList.setItemParent(this);
+
+  // Make sure that we get added to a function
+  LeakDetector::addGarbageObject(this);
+
+  if (InsertBefore) {
+    assert(InsertBefore->getParent() &&
+           "Cannot insert block before another block that is not embedded into"
+           " a function yet!");
+    InsertBefore->getParent()->getBasicBlockList().insert(InsertBefore, this);
+  }
+}
+
+
 BasicBlock::~BasicBlock() {
   dropAllReferences();
   InstList.clear();
@@ -163,16 +183,15 @@ void BasicBlock::removePredecessor(BasicBlock *Pred) {
     // Yup, loop through and nuke the PHI nodes
     while (PHINode *PN = dyn_cast<PHINode>(&front())) {
       PN->removeIncomingValue(Pred); // Remove the predecessor first...
-      
-      assert(PN->getNumIncomingValues() == max_idx-1 && 
-            "PHI node shouldn't have this many values!!!");
 
       // If the PHI _HAD_ two uses, replace PHI node with its now *single* value
-      if (max_idx == 2)
+      if (max_idx == 2) {
        PN->replaceAllUsesWith(PN->getOperand(0));
-      else // Otherwise there are no incoming values/edges, replace with dummy
-        PN->replaceAllUsesWith(Constant::getNullValue(PN->getType()));
-      getInstList().pop_front();    // Remove the PHI node
+        getInstList().pop_front();    // Remove the PHI node
+      }
+
+      // If the PHI node already only had one entry, it got deleted by
+      // removeIncomingValue.
     }
   } else {
     // Okay, now we know that we need to remove predecessor #pred_idx from all