diff options
author | Torok Edwin <edwintorok@gmail.com> | 2008-12-11 10:36:07 +0000 |
---|---|---|
committer | Torok Edwin <edwintorok@gmail.com> | 2008-12-11 10:36:07 +0000 |
commit | 87f1e7796d02ea991bdbf084f312879988732a26 (patch) | |
tree | d12e5e05fcefa424417d93128bacc6cfe168ac2b /lib/VMCore/BasicBlock.cpp | |
parent | e1d44b59eea8ad574f0e9794e10b6bf3b564461b (diff) |
introduce BasicBlock::getUniquePredecessor()
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@60872 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore/BasicBlock.cpp')
-rw-r--r-- | lib/VMCore/BasicBlock.cpp | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/lib/VMCore/BasicBlock.cpp b/lib/VMCore/BasicBlock.cpp index 514aa1de23..ab2cbebb90 100644 --- a/lib/VMCore/BasicBlock.cpp +++ b/lib/VMCore/BasicBlock.cpp @@ -169,6 +169,25 @@ BasicBlock *BasicBlock::getSinglePredecessor() { return (PI == E) ? ThePred : 0 /*multiple preds*/; } +/// getUniquePredecessor - If this basic block has a unique predecessor block, +/// return the block, otherwise return a null pointer. +/// Note that unique predecessor doesn't mean single edge, there can be +/// multiple edges from the unique predecessor to this block (for example in +/// case of a switch statement with multiple cases having same destination). +BasicBlock *BasicBlock::getUniquePredecessor() { + pred_iterator PI = pred_begin(this), E = pred_end(this); + if (PI == E) return 0; // No preds. + BasicBlock *PredBB = *PI; + ++PI; + for (;PI != E; ++PI) { + if (*PI != PredBB) + return 0; + // same predecessor appears multiple times in predecessor list, + // this is ok + } + return PredBB; +} + /// 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 |