diff options
author | Chris Lattner <sabre@nondot.org> | 2005-02-24 02:37:26 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2005-02-24 02:37:26 +0000 |
commit | ce046ac9c6446b8f70fab859960f65dce25e5ac4 (patch) | |
tree | eccaad9e10bf898074581e949f55ad726d5a57e3 /llvm | |
parent | ee47100d445c638e63fcee1d4a64ff4385b05fb2 (diff) | |
download | bcm5719-llvm-ce046ac9c6446b8f70fab859960f65dce25e5ac4.tar.gz bcm5719-llvm-ce046ac9c6446b8f70fab859960f65dce25e5ac4.zip |
add a new method.
llvm-svn: 20293
Diffstat (limited to 'llvm')
-rw-r--r-- | llvm/include/llvm/BasicBlock.h | 7 | ||||
-rw-r--r-- | llvm/lib/VMCore/BasicBlock.cpp | 10 |
2 files changed, 16 insertions, 1 deletions
diff --git a/llvm/include/llvm/BasicBlock.h b/llvm/include/llvm/BasicBlock.h index 2b1c3e0eea7..2b7b6301365 100644 --- a/llvm/include/llvm/BasicBlock.h +++ b/llvm/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<BasicBlock*>(this)->getSinglePredecessor(); + } //===--------------------------------------------------------------------===// /// Instruction iterator methods diff --git a/llvm/lib/VMCore/BasicBlock.cpp b/llvm/lib/VMCore/BasicBlock.cpp index b22a54162b9..92bdc50e781 100644 --- a/llvm/lib/VMCore/BasicBlock.cpp +++ b/llvm/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 |