s/isReturnStruct()/hasStructRetAttr()/g
[oota-llvm.git] / lib / VMCore / BasicBlock.cpp
index d45a1c41aa76f5400413ff4723cfb4a504c12ba3..f9bead74d25d9ab05680d08b0d43b1a9ddf48403 100644 (file)
@@ -2,8 +2,8 @@
 //
 //                     The LLVM Compiler Infrastructure
 //
-// This file was developed by the LLVM research group and is distributed under
-// the University of Illinois Open Source License. See LICENSE.TXT for details.
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
 //
 //===----------------------------------------------------------------------===//
 //
@@ -70,8 +70,8 @@ template class SymbolTableListTraits<Instruction, BasicBlock>;
 
 
 BasicBlock::BasicBlock(const std::string &Name, Function *NewParent,
-                       BasicBlock *InsertBefore)
-  : Value(Type::LabelTy, Value::BasicBlockVal), Parent(0) {
+                       BasicBlock *InsertBefore, BasicBlock *Dest)
+  : User(Type::LabelTy, Value::BasicBlockVal, &unwindDest, 0), Parent(0) {
 
   // Make sure that we get added to a function
   LeakDetector::addGarbageObject(this);
@@ -85,6 +85,8 @@ BasicBlock::BasicBlock(const std::string &Name, Function *NewParent,
   }
   
   setName(Name);
+  unwindDest.init(NULL, this);
+  setUnwindDest(Dest);
 }
 
 
@@ -113,6 +115,19 @@ void BasicBlock::eraseFromParent() {
   getParent()->getBasicBlockList().erase(this);
 }
 
+const BasicBlock *BasicBlock::getUnwindDest() const {
+  return cast_or_null<const BasicBlock>(unwindDest.get());
+}
+
+BasicBlock *BasicBlock::getUnwindDest() {
+  return cast_or_null<BasicBlock>(unwindDest.get());
+}
+
+void BasicBlock::setUnwindDest(BasicBlock *dest) {
+  NumOperands = unwindDest ? 1 : 0;
+  unwindDest.set(dest);
+}
+
 /// moveBefore - Unlink this basic block from its current function and
 /// insert it into the function that MovePos lives in, right before MovePos.
 void BasicBlock::moveBefore(BasicBlock *MovePos) {
@@ -151,6 +166,7 @@ Instruction* BasicBlock::getFirstNonPHI()
 }
 
 void BasicBlock::dropAllReferences() {
+  setUnwindDest(NULL);
   for(iterator I = begin(), E = end(); I != E; ++I)
     I->dropAllReferences();
 }
@@ -177,6 +193,9 @@ void BasicBlock::removePredecessor(BasicBlock *Pred,
           find(pred_begin(this), pred_end(this), Pred) != pred_end(this)) &&
          "removePredecessor: BB is not a predecessor!");
 
+  if (Pred == getUnwindDest())
+    setUnwindDest(NULL);
+
   if (InstList.empty()) return;
   PHINode *APN = dyn_cast<PHINode>(&front());
   if (!APN) return;   // Quick exit.