diff options
author | Chris Lattner <sabre@nondot.org> | 2006-10-28 01:24:05 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2006-10-28 01:24:05 +0000 |
commit | 7466ebf045fa5097ee0d7d2728eed7fd5945c8bc (patch) | |
tree | 2450d8cd6d62efac849898ffd3dd566be314c723 | |
parent | 1b9c8e73b5d620cf2d9a8e150b179fe95ddb8c4e (diff) | |
download | external_llvm-7466ebf045fa5097ee0d7d2728eed7fd5945c8bc.tar.gz external_llvm-7466ebf045fa5097ee0d7d2728eed7fd5945c8bc.tar.bz2 external_llvm-7466ebf045fa5097ee0d7d2728eed7fd5945c8bc.zip |
add a method
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@31249 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/llvm/Analysis/LoopInfo.h | 6 | ||||
-rw-r--r-- | lib/Analysis/LoopInfo.cpp | 20 |
2 files changed, 26 insertions, 0 deletions
diff --git a/include/llvm/Analysis/LoopInfo.h b/include/llvm/Analysis/LoopInfo.h index a81b674fba..b2bdde07d5 100644 --- a/include/llvm/Analysis/LoopInfo.h +++ b/include/llvm/Analysis/LoopInfo.h @@ -107,6 +107,12 @@ public: // induction variable canonicalization pass should be used to normalize loops // for easy analysis. These methods assume canonical loops. + /// getExitingBlocks - Return all blocks inside the loop that have successors + /// outside of the loop. These are the blocks _inside of the current loop_ + /// which branch out. The returned list is always unique. + /// + void getExitingBlocks(std::vector<BasicBlock*> &Blocks) const; + /// getExitBlocks - Return all of the successor blocks of this loop. These /// are the blocks _outside of the current loop_ which are branched to. /// diff --git a/lib/Analysis/LoopInfo.cpp b/lib/Analysis/LoopInfo.cpp index 6483de4b0a..9a6b5208d8 100644 --- a/lib/Analysis/LoopInfo.cpp +++ b/lib/Analysis/LoopInfo.cpp @@ -332,6 +332,26 @@ void LoopInfo::removeBlock(BasicBlock *BB) { // APIs for simple analysis of the loop. // +/// getExitingBlocks - Return all blocks inside the loop that have successors +/// outside of the loop. These are the blocks _inside of the current loop_ +/// which branch out. The returned list is always unique. +/// +void Loop::getExitingBlocks(std::vector<BasicBlock*> &ExitingBlocks) const { + // Sort the blocks vector so that we can use binary search to do quick + // lookups. + std::vector<BasicBlock*> LoopBBs(block_begin(), block_end()); + std::sort(LoopBBs.begin(), LoopBBs.end()); + + for (std::vector<BasicBlock*>::const_iterator BI = Blocks.begin(), + BE = Blocks.end(); BI != BE; ++BI) + for (succ_iterator I = succ_begin(*BI), E = succ_end(*BI); I != E; ++I) + if (!std::binary_search(LoopBBs.begin(), LoopBBs.end(), *I)) { + // Not in current loop? It must be an exit block. + ExitingBlocks.push_back(*BI); + break; + } +} + /// getExitBlocks - Return all of the successor blocks of this loop. These /// are the blocks _outside of the current loop_ which are branched to. /// |