mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-09-28 07:17:32 +00:00
Make getPredecessorWithUniqueSuccessorForBB return the unique successor
in addition to the predecessor. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@101374 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -351,7 +351,8 @@ namespace llvm {
|
|||||||
/// (which may not be an immediate predecessor) which has exactly one
|
/// (which may not be an immediate predecessor) which has exactly one
|
||||||
/// successor from which BB is reachable, or null if no such block is
|
/// successor from which BB is reachable, or null if no such block is
|
||||||
/// found.
|
/// found.
|
||||||
BasicBlock* getPredecessorWithUniqueSuccessorForBB(BasicBlock *BB);
|
std::pair<BasicBlock *, BasicBlock *>
|
||||||
|
getPredecessorWithUniqueSuccessorForBB(BasicBlock *BB);
|
||||||
|
|
||||||
/// isImpliedCond - Test whether the condition described by Pred, LHS,
|
/// isImpliedCond - Test whether the condition described by Pred, LHS,
|
||||||
/// and RHS is true whenever the given Cond value evaluates to true.
|
/// and RHS is true whenever the given Cond value evaluates to true.
|
||||||
|
@@ -4654,21 +4654,21 @@ BasicBlock *ScalarEvolution::getLoopPredecessor(const Loop *L) {
|
|||||||
/// successor from which BB is reachable, or null if no such block is
|
/// successor from which BB is reachable, or null if no such block is
|
||||||
/// found.
|
/// found.
|
||||||
///
|
///
|
||||||
BasicBlock *
|
std::pair<BasicBlock *, BasicBlock *>
|
||||||
ScalarEvolution::getPredecessorWithUniqueSuccessorForBB(BasicBlock *BB) {
|
ScalarEvolution::getPredecessorWithUniqueSuccessorForBB(BasicBlock *BB) {
|
||||||
// If the block has a unique predecessor, then there is no path from the
|
// If the block has a unique predecessor, then there is no path from the
|
||||||
// predecessor to the block that does not go through the direct edge
|
// predecessor to the block that does not go through the direct edge
|
||||||
// from the predecessor to the block.
|
// from the predecessor to the block.
|
||||||
if (BasicBlock *Pred = BB->getSinglePredecessor())
|
if (BasicBlock *Pred = BB->getSinglePredecessor())
|
||||||
return Pred;
|
return std::make_pair(Pred, BB);
|
||||||
|
|
||||||
// A loop's header is defined to be a block that dominates the loop.
|
// A loop's header is defined to be a block that dominates the loop.
|
||||||
// If the header has a unique predecessor outside the loop, it must be
|
// If the header has a unique predecessor outside the loop, it must be
|
||||||
// a block that has exactly one successor that can reach the loop.
|
// a block that has exactly one successor that can reach the loop.
|
||||||
if (Loop *L = LI->getLoopFor(BB))
|
if (Loop *L = LI->getLoopFor(BB))
|
||||||
return getLoopPredecessor(L);
|
return std::make_pair(getLoopPredecessor(L), L->getHeader());
|
||||||
|
|
||||||
return 0;
|
return std::pair<BasicBlock *, BasicBlock *>();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// HasSameValue - SCEV structural equivalence is usually sufficient for
|
/// HasSameValue - SCEV structural equivalence is usually sufficient for
|
||||||
@@ -4852,24 +4852,22 @@ ScalarEvolution::isLoopEntryGuardedByCond(const Loop *L,
|
|||||||
// (interprocedural conditions notwithstanding).
|
// (interprocedural conditions notwithstanding).
|
||||||
if (!L) return false;
|
if (!L) return false;
|
||||||
|
|
||||||
BasicBlock *Predecessor = getLoopPredecessor(L);
|
|
||||||
BasicBlock *PredecessorDest = L->getHeader();
|
|
||||||
|
|
||||||
// Starting at the loop predecessor, climb up the predecessor chain, as long
|
// Starting at the loop predecessor, climb up the predecessor chain, as long
|
||||||
// as there are predecessors that can be found that have unique successors
|
// as there are predecessors that can be found that have unique successors
|
||||||
// leading to the original header.
|
// leading to the original header.
|
||||||
for (; Predecessor;
|
for (std::pair<BasicBlock *, BasicBlock *>
|
||||||
PredecessorDest = Predecessor,
|
Pair(getLoopPredecessor(L), L->getHeader());
|
||||||
Predecessor = getPredecessorWithUniqueSuccessorForBB(Predecessor)) {
|
Pair.first;
|
||||||
|
Pair = getPredecessorWithUniqueSuccessorForBB(Pair.first)) {
|
||||||
|
|
||||||
BranchInst *LoopEntryPredicate =
|
BranchInst *LoopEntryPredicate =
|
||||||
dyn_cast<BranchInst>(Predecessor->getTerminator());
|
dyn_cast<BranchInst>(Pair.first->getTerminator());
|
||||||
if (!LoopEntryPredicate ||
|
if (!LoopEntryPredicate ||
|
||||||
LoopEntryPredicate->isUnconditional())
|
LoopEntryPredicate->isUnconditional())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (isImpliedCond(LoopEntryPredicate->getCondition(), Pred, LHS, RHS,
|
if (isImpliedCond(LoopEntryPredicate->getCondition(), Pred, LHS, RHS,
|
||||||
LoopEntryPredicate->getSuccessor(0) != PredecessorDest))
|
LoopEntryPredicate->getSuccessor(0) != Pair.second))
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user