forked from OSchip/llvm-project
[NFC] Factor out predecessors collection into a separate method
It may be reused in a different piece of logic. Differential Revision: https://reviews.llvm.org/D50890 Reviewed By: reames llvm-svn: 340250
This commit is contained in:
parent
09ab506798
commit
bfbd4d1fb6
|
@ -49,6 +49,13 @@ class LoopSafetyInfo {
|
||||||
// may throw.
|
// may throw.
|
||||||
bool HeaderMayThrow = false; // Same as previous, but specific to loop header
|
bool HeaderMayThrow = false; // Same as previous, but specific to loop header
|
||||||
|
|
||||||
|
/// Collect all blocks from \p CurLoop which lie on all possible paths from
|
||||||
|
/// the header of \p CurLoop (inclusive) to BB (exclusive) into the set
|
||||||
|
/// \p Predecessors. If \p BB is the header, \p Predecessors will be empty.
|
||||||
|
void collectTransitivePredecessors(
|
||||||
|
const Loop *CurLoop, const BasicBlock *BB,
|
||||||
|
SmallPtrSetImpl<const BasicBlock *> &Predecessors) const;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Used to update funclet bundle operands.
|
// Used to update funclet bundle operands.
|
||||||
DenseMap<BasicBlock *, ColorVector> BlockColors;
|
DenseMap<BasicBlock *, ColorVector> BlockColors;
|
||||||
|
|
|
@ -98,19 +98,13 @@ static bool CanProveNotTakenFirstIteration(const BasicBlock *ExitBlock,
|
||||||
return SimpleCst->isAllOnesValue();
|
return SimpleCst->isAllOnesValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LoopSafetyInfo::collectTransitivePredecessors(
|
||||||
bool LoopSafetyInfo::allLoopPathsLeadToBlock(const Loop *CurLoop,
|
const Loop *CurLoop, const BasicBlock *BB,
|
||||||
const BasicBlock *BB,
|
SmallPtrSetImpl<const BasicBlock *> &Predecessors) const {
|
||||||
const DominatorTree *DT) const {
|
assert(Predecessors.empty() && "Garbage in predecessors set?");
|
||||||
assert(CurLoop->contains(BB) && "Should only be called for loop blocks!");
|
assert(CurLoop->contains(BB) && "Should only be called for loop blocks!");
|
||||||
|
|
||||||
// Fast path: header is always reached once the loop is entered.
|
|
||||||
if (BB == CurLoop->getHeader())
|
if (BB == CurLoop->getHeader())
|
||||||
return true;
|
return;
|
||||||
|
|
||||||
// Collect all transitive predecessors of BB in the same loop. This set will
|
|
||||||
// be a subset of the blocks within the loop.
|
|
||||||
SmallPtrSet<const BasicBlock *, 4> Predecessors;
|
|
||||||
SmallVector<const BasicBlock *, 4> WorkList;
|
SmallVector<const BasicBlock *, 4> WorkList;
|
||||||
for (auto *Pred : predecessors(BB)) {
|
for (auto *Pred : predecessors(BB)) {
|
||||||
Predecessors.insert(Pred);
|
Predecessors.insert(Pred);
|
||||||
|
@ -132,6 +126,21 @@ bool LoopSafetyInfo::allLoopPathsLeadToBlock(const Loop *CurLoop,
|
||||||
if (Predecessors.insert(PredPred).second)
|
if (Predecessors.insert(PredPred).second)
|
||||||
WorkList.push_back(PredPred);
|
WorkList.push_back(PredPred);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool LoopSafetyInfo::allLoopPathsLeadToBlock(const Loop *CurLoop,
|
||||||
|
const BasicBlock *BB,
|
||||||
|
const DominatorTree *DT) const {
|
||||||
|
assert(CurLoop->contains(BB) && "Should only be called for loop blocks!");
|
||||||
|
|
||||||
|
// Fast path: header is always reached once the loop is entered.
|
||||||
|
if (BB == CurLoop->getHeader())
|
||||||
|
return true;
|
||||||
|
|
||||||
|
// Collect all transitive predecessors of BB in the same loop. This set will
|
||||||
|
// be a subset of the blocks within the loop.
|
||||||
|
SmallPtrSet<const BasicBlock *, 4> Predecessors;
|
||||||
|
collectTransitivePredecessors(CurLoop, BB, Predecessors);
|
||||||
|
|
||||||
// Make sure that all successors of all predecessors of BB are either:
|
// Make sure that all successors of all predecessors of BB are either:
|
||||||
// 1) BB,
|
// 1) BB,
|
||||||
|
|
Loading…
Reference in New Issue