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 | 3845be203dc8afe14e141a45aef4ff5ee76a5dcc (patch) | |
tree | 160663da784862b8ec340c6fa2e828ca7cbb51cd | |
parent | d484dd8da437441a369cb7c56585c2c23a04ca97 (diff) | |
download | bcm5719-llvm-3845be203dc8afe14e141a45aef4ff5ee76a5dcc.tar.gz bcm5719-llvm-3845be203dc8afe14e141a45aef4ff5ee76a5dcc.zip |
Added helper functions in LoopInfo: isLoopExit and numBackEdges.
llvm-svn: 4112
-rw-r--r-- | llvm/include/llvm/Analysis/LoopInfo.h | 5 | ||||
-rw-r--r-- | llvm/lib/Analysis/LoopInfo.cpp | 24 |
2 files changed, 28 insertions, 1 deletions
diff --git a/llvm/include/llvm/Analysis/LoopInfo.h b/llvm/include/llvm/Analysis/LoopInfo.h index 6c531ac03d3..dd7029551ad 100644 --- a/llvm/include/llvm/Analysis/LoopInfo.h +++ b/llvm/include/llvm/Analysis/LoopInfo.h @@ -44,7 +44,10 @@ public: /// isLoopExit - True if terminator in the block can branch to another block /// that is outside of the current loop. - bool isLoopExit(BasicBlock *BB) const; + bool isLoopExit(const BasicBlock *BB) const; + + /// Find number of back edges + unsigned getNumBackEdges() const; /// getLoopPreheader - If there is a preheader for this loop, return it. A /// loop has a preheader if there is only one edge to the header of the loop diff --git a/llvm/lib/Analysis/LoopInfo.cpp b/llvm/lib/Analysis/LoopInfo.cpp index 1f8e34ca7e6..002e5536245 100644 --- a/llvm/lib/Analysis/LoopInfo.cpp +++ b/llvm/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: "; |