add a new method.
authorChris Lattner <sabre@nondot.org>
Thu, 24 Feb 2005 02:37:26 +0000 (02:37 +0000)
committerChris Lattner <sabre@nondot.org>
Thu, 24 Feb 2005 02:37:26 +0000 (02:37 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@20293 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/BasicBlock.h
lib/VMCore/BasicBlock.cpp

index 2b1c3e0eea708c3a61fc64920ac62979a72e444f..2b7b6301365371b805fdf42df44939a303092c83 100644 (file)
@@ -107,7 +107,12 @@ public:
   ///
   void eraseFromParent();
 
-
+  /// getSinglePredecessor - If this basic block has a single predecessor block,
+  /// return the block, otherwise return a null pointer.
+  BasicBlock *getSinglePredecessor();
+  const BasicBlock *getSinglePredecessor() const {
+    return const_cast<BasicBlock*>(this)->getSinglePredecessor();
+  }
 
   //===--------------------------------------------------------------------===//
   /// Instruction iterator methods
index b22a54162b908d9b8deddef093bcd7872cb753bc..92bdc50e7812486c3c39c733b2aa11373ea775e2 100644 (file)
@@ -129,6 +129,16 @@ void BasicBlock::dropAllReferences() {
     I->dropAllReferences();
 }
 
+/// getSinglePredecessor - If this basic block has a single predecessor block,
+/// return the block, otherwise return a null pointer.
+BasicBlock *BasicBlock::getSinglePredecessor() {
+  pred_iterator PI = pred_begin(this), E = pred_end(this);
+  if (PI == E) return 0;         // No preds.
+  BasicBlock *ThePred = *PI;
+  ++PI;
+  return (PI == E) ? ThePred : 0 /*multiple preds*/;
+}
+
 // removePredecessor - This method is used to notify a BasicBlock that the
 // specified Predecessor of the block is no longer able to reach it.  This is
 // actually not used to update the Predecessor list, but is actually used to