diff options
author | Diego Caballero <diego.caballero@intel.com> | 2018-07-09 17:52:49 +0000 |
---|---|---|
committer | Diego Caballero <diego.caballero@intel.com> | 2018-07-09 17:52:49 +0000 |
commit | 29a07b37bf2c6ba4f312c20e5c058826178fcf9e (patch) | |
tree | a1632a84be9e734c37d4ea594b1b65645b6e72ff /llvm/lib/Analysis/LoopInfo.cpp | |
parent | f639936748a2e5fbe5823705188c324d8cbfcaa5 (diff) | |
download | llvm-29a07b37bf2c6ba4f312c20e5c058826178fcf9e.zip llvm-29a07b37bf2c6ba4f312c20e5c058826178fcf9e.tar.gz llvm-29a07b37bf2c6ba4f312c20e5c058826178fcf9e.tar.bz2 |
[LoopInfo] Port loop exit interfaces from Loop to LoopBase
This patch ports hasDedicatedExits, getUniqueExitBlocks and
getUniqueExitBlock in Loop to LoopBase so that they can be used
from other LoopBase sub-classes.
Reviewers: chandlerc, sanjoy, hfinkel, fhahn
Reviewed By: chandlerc
Differential Revision: https://reviews.llvm.org/D48817
llvm-svn: 336572
Diffstat (limited to 'llvm/lib/Analysis/LoopInfo.cpp')
-rw-r--r-- | llvm/lib/Analysis/LoopInfo.cpp | 63 |
1 files changed, 0 insertions, 63 deletions
diff --git a/llvm/lib/Analysis/LoopInfo.cpp b/llvm/lib/Analysis/LoopInfo.cpp index fec808d..3f78456 100644 --- a/llvm/lib/Analysis/LoopInfo.cpp +++ b/llvm/lib/Analysis/LoopInfo.cpp @@ -378,69 +378,6 @@ Loop::LocRange Loop::getLocRange() const { return LocRange(); } -bool Loop::hasDedicatedExits() const { - // Each predecessor of each exit block of a normal loop is contained - // within the loop. - SmallVector<BasicBlock *, 4> ExitBlocks; - getExitBlocks(ExitBlocks); - for (BasicBlock *BB : ExitBlocks) - for (BasicBlock *Predecessor : predecessors(BB)) - if (!contains(Predecessor)) - return false; - // All the requirements are met. - return true; -} - -void Loop::getUniqueExitBlocks( - SmallVectorImpl<BasicBlock *> &ExitBlocks) const { - assert(hasDedicatedExits() && - "getUniqueExitBlocks assumes the loop has canonical form exits!"); - - SmallVector<BasicBlock *, 32> SwitchExitBlocks; - for (BasicBlock *BB : this->blocks()) { - SwitchExitBlocks.clear(); - for (BasicBlock *Successor : successors(BB)) { - // If block is inside the loop then it is not an exit block. - if (contains(Successor)) - continue; - - pred_iterator PI = pred_begin(Successor); - BasicBlock *FirstPred = *PI; - - // If current basic block is this exit block's first predecessor - // then only insert exit block in to the output ExitBlocks vector. - // This ensures that same exit block is not inserted twice into - // ExitBlocks vector. - if (BB != FirstPred) - continue; - - // If a terminator has more then two successors, for example SwitchInst, - // then it is possible that there are multiple edges from current block - // to one exit block. - if (succ_size(BB) <= 2) { - ExitBlocks.push_back(Successor); - continue; - } - - // In case of multiple edges from current block to exit block, collect - // only one edge in ExitBlocks. Use switchExitBlocks to keep track of - // duplicate edges. - if (!is_contained(SwitchExitBlocks, Successor)) { - SwitchExitBlocks.push_back(Successor); - ExitBlocks.push_back(Successor); - } - } - } -} - -BasicBlock *Loop::getUniqueExitBlock() const { - SmallVector<BasicBlock *, 8> UniqueExitBlocks; - getUniqueExitBlocks(UniqueExitBlocks); - if (UniqueExitBlocks.size() == 1) - return UniqueExitBlocks[0]; - return nullptr; -} - #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) LLVM_DUMP_METHOD void Loop::dump() const { print(dbgs()); } |