From ad993cbb77b26b36cee938686b3377c0d92abd5e Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Thu, 24 Feb 2005 02:37:26 +0000 Subject: [PATCH] add a new method. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@20293 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/BasicBlock.h | 7 ++++++- lib/VMCore/BasicBlock.cpp | 10 ++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/include/llvm/BasicBlock.h b/include/llvm/BasicBlock.h index 2b1c3e0eea7..2b7b6301365 100644 --- a/include/llvm/BasicBlock.h +++ b/include/llvm/BasicBlock.h @@ -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(this)->getSinglePredecessor(); + } //===--------------------------------------------------------------------===// /// Instruction iterator methods diff --git a/lib/VMCore/BasicBlock.cpp b/lib/VMCore/BasicBlock.cpp index b22a54162b9..92bdc50e781 100644 --- a/lib/VMCore/BasicBlock.cpp +++ b/lib/VMCore/BasicBlock.cpp @@ -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