Simplify this code; it can use the regular CFG utlities rather than

the BlockTraits abstractions.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@109268 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Dan Gohman 2010-07-23 21:25:16 +00:00
parent 304a7a6242
commit 63137d5681

View File

@ -123,14 +123,13 @@ PHINode *Loop::getCanonicalInductionVariable() const {
BasicBlock *H = getHeader(); BasicBlock *H = getHeader();
BasicBlock *Incoming = 0, *Backedge = 0; BasicBlock *Incoming = 0, *Backedge = 0;
typedef GraphTraits<Inverse<BasicBlock*> > InvBlockTraits; pred_iterator PI = pred_begin(H);
InvBlockTraits::ChildIteratorType PI = InvBlockTraits::child_begin(H); assert(PI != pred_end(H) &&
assert(PI != InvBlockTraits::child_end(H) &&
"Loop must have at least one backedge!"); "Loop must have at least one backedge!");
Backedge = *PI++; Backedge = *PI++;
if (PI == InvBlockTraits::child_end(H)) return 0; // dead loop if (PI == pred_end(H)) return 0; // dead loop
Incoming = *PI++; Incoming = *PI++;
if (PI != InvBlockTraits::child_end(H)) return 0; // multiple backedges? if (PI != pred_end(H)) return 0; // multiple backedges?
if (contains(Incoming)) { if (contains(Incoming)) {
if (contains(Backedge)) if (contains(Backedge))
@ -340,16 +339,12 @@ Loop::getUniqueExitBlocks(SmallVectorImpl<BasicBlock *> &ExitBlocks) const {
BasicBlock *current = *BI; BasicBlock *current = *BI;
switchExitBlocks.clear(); switchExitBlocks.clear();
typedef GraphTraits<BasicBlock *> BlockTraits; for (succ_iterator I = succ_begin(*BI), E = succ_end(*BI); I != E; ++I) {
typedef GraphTraits<Inverse<BasicBlock *> > InvBlockTraits;
for (BlockTraits::ChildIteratorType I =
BlockTraits::child_begin(*BI), E = BlockTraits::child_end(*BI);
I != E; ++I) {
// If block is inside the loop then it is not a exit block. // If block is inside the loop then it is not a exit block.
if (std::binary_search(LoopBBs.begin(), LoopBBs.end(), *I)) if (std::binary_search(LoopBBs.begin(), LoopBBs.end(), *I))
continue; continue;
InvBlockTraits::ChildIteratorType PI = InvBlockTraits::child_begin(*I); pred_iterator PI = pred_begin(*I);
BasicBlock *firstPred = *PI; BasicBlock *firstPred = *PI;
// If current basic block is this exit block's first predecessor // If current basic block is this exit block's first predecessor
@ -362,8 +357,7 @@ Loop::getUniqueExitBlocks(SmallVectorImpl<BasicBlock *> &ExitBlocks) const {
// If a terminator has more then two successors, for example SwitchInst, // If a terminator has more then two successors, for example SwitchInst,
// then it is possible that there are multiple edges from current block // then it is possible that there are multiple edges from current block
// to one exit block. // to one exit block.
if (std::distance(BlockTraits::child_begin(current), if (std::distance(succ_begin(current), succ_end(current)) <= 2) {
BlockTraits::child_end(current)) <= 2) {
ExitBlocks.push_back(*I); ExitBlocks.push_back(*I);
continue; continue;
} }