diff options
author | Misha Brukman <brukman+llvm@gmail.com> | 2002-10-11 05:31:10 +0000 |
---|---|---|
committer | Misha Brukman <brukman+llvm@gmail.com> | 2002-10-11 05:31:10 +0000 |
commit | 6b290a54409f6bb6a0cc1c0446cd2b170a4b7add (patch) | |
tree | ce542321b04185827bbf9e68fbfd536a5a37a742 /lib/Analysis/LoopInfo.cpp | |
parent | f77b57097d00b301c164e10a034860fdbbcbe932 (diff) |
Added helper functions in LoopInfo: isLoopExit and numBackEdges.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@4112 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis/LoopInfo.cpp')
-rw-r--r-- | lib/Analysis/LoopInfo.cpp | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/lib/Analysis/LoopInfo.cpp b/lib/Analysis/LoopInfo.cpp index 1f8e34ca7e..002e553624 100644 --- a/lib/Analysis/LoopInfo.cpp +++ b/lib/Analysis/LoopInfo.cpp @@ -24,6 +24,30 @@ bool Loop::contains(const BasicBlock *BB) const { return find(Blocks.begin(), Blocks.end(), BB) != Blocks.end(); } +bool Loop::isLoopExit(const BasicBlock *BB) const { + for (BasicBlock::succ_const_iterator SI = succ_begin(BB), SE = succ_end(BB); + SI != SE; ++SI) { + if (! contains(*SI)) + return true; + } + return false; +} + +unsigned Loop::getNumBackEdges() const { + unsigned numBackEdges = 0; + BasicBlock *header = Blocks.front(); + + for (std::vector<BasicBlock*>::const_iterator i = Blocks.begin(), e = Blocks.end(); + i != e; ++i) { + for (BasicBlock::succ_iterator Successor = succ_begin(*i), SEnd = succ_end(*i); + Successor != SEnd; ++Successor) { + if (header == *Successor) + ++numBackEdges; + } + } + return numBackEdges; +} + void Loop::print(std::ostream &OS) const { OS << std::string(getLoopDepth()*2, ' ') << "Loop Containing: "; |