While folding unconditional return move DbgRegionEndInst into the predecessor, instea...
[oota-llvm.git] / lib / Transforms / Utils / Local.cpp
index b8077aefb1321b8450db698fc8d62f343a72d28d..38809e5e1d7e3110eabc92e4d9e51ee5a49026cb 100644 (file)
@@ -38,8 +38,8 @@ bool llvm::ConstantFoldTerminator(BasicBlock *BB) {
   // Branch - See if we are conditional jumping on constant
   if (BranchInst *BI = dyn_cast<BranchInst>(T)) {
     if (BI->isUnconditional()) return false;  // Can't optimize uncond branch
-    BasicBlock *Dest1 = cast<BasicBlock>(BI->getOperand(0));
-    BasicBlock *Dest2 = cast<BasicBlock>(BI->getOperand(1));
+    BasicBlock *Dest1 = BI->getSuccessor(0);
+    BasicBlock *Dest2 = BI->getSuccessor(1);
 
     if (ConstantInt *Cond = dyn_cast<ConstantInt>(BI->getCondition())) {
       // Are we branching on constant?
@@ -248,3 +248,25 @@ void llvm::MergeBasicBlockIntoOnlyPred(BasicBlock *DestBB) {
   // Nuke BB.
   PredBB->eraseFromParent();
 }
+
+/// OnlyUsedByDbgIntrinsics - Return true if the instruction I is only used
+/// by DbgIntrinsics. If DbgInUses is specified then the vector is filled 
+/// with the DbgInfoIntrinsic that use the instruction I.
+bool llvm::OnlyUsedByDbgInfoIntrinsics(Instruction *I, 
+                               SmallVectorImpl<DbgInfoIntrinsic *> *DbgInUses) {
+  if (DbgInUses)
+    DbgInUses->clear();
+
+  for (Value::use_iterator UI = I->use_begin(), UE = I->use_end(); UI != UE; 
+       ++UI) {
+    if (DbgInfoIntrinsic *DI = dyn_cast<DbgInfoIntrinsic>(*UI)) {
+      if (DbgInUses)
+        DbgInUses->push_back(DI);
+    } else {
+      if (DbgInUses)
+        DbgInUses->clear();
+      return false;
+    }
+  }
+  return true;
+}