forked from OSchip/llvm-project
[C++11] Add predecessors(BasicBlock *) / successors(BasicBlock *) iterator ranges.
Summary: This patch introduces two new iterator ranges and updates existing code to use it. No functional change intended. Test Plan: All tests (make check-all) still pass. Reviewers: dblaikie Reviewed By: dblaikie Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D4481 llvm-svn: 213474
This commit is contained in:
parent
4100ebd67b
commit
d11beffef4
|
@ -1854,12 +1854,11 @@ iterate over all predecessors of BB:
|
||||||
#include "llvm/Support/CFG.h"
|
#include "llvm/Support/CFG.h"
|
||||||
BasicBlock *BB = ...;
|
BasicBlock *BB = ...;
|
||||||
|
|
||||||
for (pred_iterator PI = pred_begin(BB), E = pred_end(BB); PI != E; ++PI) {
|
for (BasicBlock *Pred : predecessors(BB)) {
|
||||||
BasicBlock *Pred = *PI;
|
|
||||||
// ...
|
// ...
|
||||||
}
|
}
|
||||||
|
|
||||||
Similarly, to iterate over successors use ``succ_iterator/succ_begin/succ_end``.
|
Similarly, to iterate over successors use ``successors``.
|
||||||
|
|
||||||
.. _simplechanges:
|
.. _simplechanges:
|
||||||
|
|
||||||
|
|
|
@ -93,6 +93,12 @@ inline pred_iterator pred_end(BasicBlock *BB) { return pred_iterator(BB, true);}
|
||||||
inline const_pred_iterator pred_end(const BasicBlock *BB) {
|
inline const_pred_iterator pred_end(const BasicBlock *BB) {
|
||||||
return const_pred_iterator(BB, true);
|
return const_pred_iterator(BB, true);
|
||||||
}
|
}
|
||||||
|
inline iterator_range<pred_iterator> predecessors(BasicBlock *BB) {
|
||||||
|
return make_range(pred_begin(BB), pred_end(BB));
|
||||||
|
}
|
||||||
|
inline iterator_range<const_pred_iterator> predecessors(const BasicBlock *BB) {
|
||||||
|
return make_range(pred_begin(BB), pred_end(BB));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -257,6 +263,12 @@ inline succ_iterator succ_end(BasicBlock *BB) {
|
||||||
inline succ_const_iterator succ_end(const BasicBlock *BB) {
|
inline succ_const_iterator succ_end(const BasicBlock *BB) {
|
||||||
return succ_const_iterator(BB->getTerminator(), true);
|
return succ_const_iterator(BB->getTerminator(), true);
|
||||||
}
|
}
|
||||||
|
inline iterator_range<succ_iterator> successors(BasicBlock *BB) {
|
||||||
|
return make_range(succ_begin(BB), succ_end(BB));
|
||||||
|
}
|
||||||
|
inline iterator_range<succ_const_iterator> successors(const BasicBlock *BB) {
|
||||||
|
return make_range(succ_begin(BB), succ_end(BB));
|
||||||
|
}
|
||||||
|
|
||||||
template <typename T, typename U> struct isPodLike<SuccIterator<T, U> > {
|
template <typename T, typename U> struct isPodLike<SuccIterator<T, U> > {
|
||||||
static const bool value = isPodLike<T>::value;
|
static const bool value = isPodLike<T>::value;
|
||||||
|
|
|
@ -530,9 +530,8 @@ void BranchProbabilityInfo::print(raw_ostream &OS, const Module *) const {
|
||||||
assert(LastF && "Cannot print prior to running over a function");
|
assert(LastF && "Cannot print prior to running over a function");
|
||||||
for (Function::const_iterator BI = LastF->begin(), BE = LastF->end();
|
for (Function::const_iterator BI = LastF->begin(), BE = LastF->end();
|
||||||
BI != BE; ++BI) {
|
BI != BE; ++BI) {
|
||||||
for (succ_const_iterator SI = succ_begin(BI), SE = succ_end(BI);
|
for (const BasicBlock *Succ : successors(BI)) {
|
||||||
SI != SE; ++SI) {
|
printEdgeProbability(OS << " ", BI, Succ);
|
||||||
printEdgeProbability(OS << " ", BI, *SI);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -563,8 +562,7 @@ BasicBlock *BranchProbabilityInfo::getHotSucc(BasicBlock *BB) const {
|
||||||
uint32_t MaxWeight = 0;
|
uint32_t MaxWeight = 0;
|
||||||
BasicBlock *MaxSucc = nullptr;
|
BasicBlock *MaxSucc = nullptr;
|
||||||
|
|
||||||
for (succ_iterator I = succ_begin(BB), E = succ_end(BB); I != E; ++I) {
|
for (BasicBlock *Succ : successors(BB)) {
|
||||||
BasicBlock *Succ = *I;
|
|
||||||
uint32_t Weight = getEdgeWeight(BB, Succ);
|
uint32_t Weight = getEdgeWeight(BB, Succ);
|
||||||
uint32_t PrevSum = Sum;
|
uint32_t PrevSum = Sum;
|
||||||
|
|
||||||
|
|
|
@ -29,9 +29,8 @@ using namespace llvm;
|
||||||
bool Interval::isLoop() const {
|
bool Interval::isLoop() const {
|
||||||
// There is a loop in this interval iff one of the predecessors of the header
|
// There is a loop in this interval iff one of the predecessors of the header
|
||||||
// node lives in the interval.
|
// node lives in the interval.
|
||||||
for (::pred_iterator I = ::pred_begin(HeaderNode), E = ::pred_end(HeaderNode);
|
for (BasicBlock *Pred : predecessors(HeaderNode))
|
||||||
I != E; ++I)
|
if (contains(Pred))
|
||||||
if (contains(*I))
|
|
||||||
return true;
|
return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -625,9 +625,9 @@ bool LazyValueInfoCache::solveBlockValueNonLocal(LVILatticeVal &BBLV,
|
||||||
// Loop over all of our predecessors, merging what we know from them into
|
// Loop over all of our predecessors, merging what we know from them into
|
||||||
// result.
|
// result.
|
||||||
bool EdgesMissing = false;
|
bool EdgesMissing = false;
|
||||||
for (pred_iterator PI = pred_begin(BB), E = pred_end(BB); PI != E; ++PI) {
|
for (BasicBlock *Pred : predecessors(BB)) {
|
||||||
LVILatticeVal EdgeResult;
|
LVILatticeVal EdgeResult;
|
||||||
EdgesMissing |= !getEdgeValue(Val, *PI, BB, EdgeResult);
|
EdgesMissing |= !getEdgeValue(Val, Pred, BB, EdgeResult);
|
||||||
if (EdgesMissing)
|
if (EdgesMissing)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
|
|
@ -336,9 +336,8 @@ bool Loop::hasDedicatedExits() const {
|
||||||
SmallVector<BasicBlock *, 4> ExitBlocks;
|
SmallVector<BasicBlock *, 4> ExitBlocks;
|
||||||
getExitBlocks(ExitBlocks);
|
getExitBlocks(ExitBlocks);
|
||||||
for (unsigned i = 0, e = ExitBlocks.size(); i != e; ++i)
|
for (unsigned i = 0, e = ExitBlocks.size(); i != e; ++i)
|
||||||
for (pred_iterator PI = pred_begin(ExitBlocks[i]),
|
for (BasicBlock *Pred : predecessors(ExitBlocks[i]))
|
||||||
PE = pred_end(ExitBlocks[i]); PI != PE; ++PI)
|
if (!contains(Pred))
|
||||||
if (!contains(*PI))
|
|
||||||
return false;
|
return false;
|
||||||
// All the requirements are met.
|
// All the requirements are met.
|
||||||
return true;
|
return true;
|
||||||
|
@ -360,12 +359,12 @@ Loop::getUniqueExitBlocks(SmallVectorImpl<BasicBlock *> &ExitBlocks) const {
|
||||||
BasicBlock *current = *BI;
|
BasicBlock *current = *BI;
|
||||||
switchExitBlocks.clear();
|
switchExitBlocks.clear();
|
||||||
|
|
||||||
for (succ_iterator I = succ_begin(*BI), E = succ_end(*BI); I != E; ++I) {
|
for (BasicBlock *Succ : successors(*BI)) {
|
||||||
// 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 (contains(*I))
|
if (contains(Succ))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
pred_iterator PI = pred_begin(*I);
|
pred_iterator PI = pred_begin(Succ);
|
||||||
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
|
||||||
|
@ -379,17 +378,17 @@ Loop::getUniqueExitBlocks(SmallVectorImpl<BasicBlock *> &ExitBlocks) const {
|
||||||
// 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(succ_begin(current), succ_end(current)) <= 2) {
|
if (std::distance(succ_begin(current), succ_end(current)) <= 2) {
|
||||||
ExitBlocks.push_back(*I);
|
ExitBlocks.push_back(Succ);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// In case of multiple edges from current block to exit block, collect
|
// In case of multiple edges from current block to exit block, collect
|
||||||
// only one edge in ExitBlocks. Use switchExitBlocks to keep track of
|
// only one edge in ExitBlocks. Use switchExitBlocks to keep track of
|
||||||
// duplicate edges.
|
// duplicate edges.
|
||||||
if (std::find(switchExitBlocks.begin(), switchExitBlocks.end(), *I)
|
if (std::find(switchExitBlocks.begin(), switchExitBlocks.end(), Succ)
|
||||||
== switchExitBlocks.end()) {
|
== switchExitBlocks.end()) {
|
||||||
switchExitBlocks.push_back(*I);
|
switchExitBlocks.push_back(Succ);
|
||||||
ExitBlocks.push_back(*I);
|
ExitBlocks.push_back(Succ);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4512,13 +4512,12 @@ ScalarEvolution::ComputeExitLimit(const Loop *L, BasicBlock *ExitingBlock) {
|
||||||
// lead to the loop header.
|
// lead to the loop header.
|
||||||
bool MustExecuteLoopHeader = true;
|
bool MustExecuteLoopHeader = true;
|
||||||
BasicBlock *Exit = nullptr;
|
BasicBlock *Exit = nullptr;
|
||||||
for (succ_iterator SI = succ_begin(ExitingBlock), SE = succ_end(ExitingBlock);
|
for (BasicBlock *Succ : successors(ExitingBlock))
|
||||||
SI != SE; ++SI)
|
if (!L->contains(Succ)) {
|
||||||
if (!L->contains(*SI)) {
|
|
||||||
if (Exit) // Multiple exit successors.
|
if (Exit) // Multiple exit successors.
|
||||||
return getCouldNotCompute();
|
return getCouldNotCompute();
|
||||||
Exit = *SI;
|
Exit = Succ;
|
||||||
} else if (*SI != L->getHeader()) {
|
} else if (Succ != L->getHeader()) {
|
||||||
MustExecuteLoopHeader = false;
|
MustExecuteLoopHeader = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -453,8 +453,8 @@ void CodeGenPrepare::EliminateMostlyEmptyBlock(BasicBlock *BB) {
|
||||||
for (unsigned i = 0, e = BBPN->getNumIncomingValues(); i != e; ++i)
|
for (unsigned i = 0, e = BBPN->getNumIncomingValues(); i != e; ++i)
|
||||||
PN->addIncoming(InVal, BBPN->getIncomingBlock(i));
|
PN->addIncoming(InVal, BBPN->getIncomingBlock(i));
|
||||||
} else {
|
} else {
|
||||||
for (pred_iterator PI = pred_begin(BB), E = pred_end(BB); PI != E; ++PI)
|
for (BasicBlock *Pred : predecessors(BB))
|
||||||
PN->addIncoming(InVal, *PI);
|
PN->addIncoming(InVal, Pred);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -977,11 +977,11 @@ bool CodeGenPrepare::DupRetToEnableTailCallOpts(BasicBlock *BB) {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
SmallPtrSet<BasicBlock*, 4> VisitedBBs;
|
SmallPtrSet<BasicBlock*, 4> VisitedBBs;
|
||||||
for (pred_iterator PI = pred_begin(BB), PE = pred_end(BB); PI != PE; ++PI) {
|
for (BasicBlock *Pred : predecessors(BB)) {
|
||||||
if (!VisitedBBs.insert(*PI))
|
if (!VisitedBBs.insert(Pred))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
BasicBlock::InstListType &InstList = (*PI)->getInstList();
|
BasicBlock::InstListType &InstList = Pred->getInstList();
|
||||||
BasicBlock::InstListType::reverse_iterator RI = InstList.rbegin();
|
BasicBlock::InstListType::reverse_iterator RI = InstList.rbegin();
|
||||||
BasicBlock::InstListType::reverse_iterator RE = InstList.rend();
|
BasicBlock::InstListType::reverse_iterator RE = InstList.rend();
|
||||||
do { ++RI; } while (RI != RE && isa<DbgInfoIntrinsic>(&*RI));
|
do { ++RI; } while (RI != RE && isa<DbgInfoIntrinsic>(&*RI));
|
||||||
|
|
|
@ -1052,9 +1052,8 @@ void SelectionDAGISel::SelectAllBasicBlocks(const Function &Fn) {
|
||||||
|
|
||||||
if (OptLevel != CodeGenOpt::None) {
|
if (OptLevel != CodeGenOpt::None) {
|
||||||
bool AllPredsVisited = true;
|
bool AllPredsVisited = true;
|
||||||
for (const_pred_iterator PI = pred_begin(LLVMBB), PE = pred_end(LLVMBB);
|
for (const BasicBlock *Pred : predecessors(LLVMBB)) {
|
||||||
PI != PE; ++PI) {
|
if (!FuncInfo->VisitedBBs.count(Pred)) {
|
||||||
if (!FuncInfo->VisitedBBs.count(*PI)) {
|
|
||||||
AllPredsVisited = false;
|
AllPredsVisited = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -142,8 +142,8 @@ static void MarkBlocksLiveIn(BasicBlock *BB,
|
||||||
if (!LiveBBs.insert(BB))
|
if (!LiveBBs.insert(BB))
|
||||||
return; // already been here.
|
return; // already been here.
|
||||||
|
|
||||||
for (pred_iterator PI = pred_begin(BB), E = pred_end(BB); PI != E; ++PI)
|
for (BasicBlock *Pred : predecessors(BB))
|
||||||
MarkBlocksLiveIn(*PI, LiveBBs);
|
MarkBlocksLiveIn(Pred, LiveBBs);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// substituteLPadValues - Substitute the values returned by the landingpad
|
/// substituteLPadValues - Substitute the values returned by the landingpad
|
||||||
|
|
|
@ -79,8 +79,8 @@ bool UnreachableBlockElim::runOnFunction(Function &F) {
|
||||||
PN->replaceAllUsesWith(Constant::getNullValue(PN->getType()));
|
PN->replaceAllUsesWith(Constant::getNullValue(PN->getType()));
|
||||||
BB->getInstList().pop_front();
|
BB->getInstList().pop_front();
|
||||||
}
|
}
|
||||||
for (succ_iterator SI = succ_begin(BB), E = succ_end(BB); SI != E; ++SI)
|
for (BasicBlock *S : successors(BB))
|
||||||
(*SI)->removePredecessor(BB);
|
S->removePredecessor(BB);
|
||||||
BB->dropAllReferences();
|
BB->dropAllReferences();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -321,10 +321,9 @@ BasicBlock *BasicBlock::splitBasicBlock(iterator I, const Twine &BBName) {
|
||||||
// successors. If there were PHI nodes in the successors, then they need to
|
// successors. If there were PHI nodes in the successors, then they need to
|
||||||
// know that incoming branches will be from New, not from Old.
|
// know that incoming branches will be from New, not from Old.
|
||||||
//
|
//
|
||||||
for (succ_iterator I = succ_begin(New), E = succ_end(New); I != E; ++I) {
|
for (BasicBlock *Successor : successors(New)) {
|
||||||
// Loop over any phi nodes in the basic block, updating the BB field of
|
// Loop over any phi nodes in the basic block, updating the BB field of
|
||||||
// incoming values...
|
// incoming values...
|
||||||
BasicBlock *Successor = *I;
|
|
||||||
PHINode *PN;
|
PHINode *PN;
|
||||||
for (BasicBlock::iterator II = Successor->begin();
|
for (BasicBlock::iterator II = Successor->begin();
|
||||||
(PN = dyn_cast<PHINode>(II)); ++II) {
|
(PN = dyn_cast<PHINode>(II)); ++II) {
|
||||||
|
|
|
@ -179,9 +179,7 @@ bool DominatorTree::dominates(const BasicBlockEdge &BBE,
|
||||||
// trivially dominates itself, so we only have to find if it dominates the
|
// trivially dominates itself, so we only have to find if it dominates the
|
||||||
// other predecessors. Since the only way out of X is via NormalDest, X can
|
// other predecessors. Since the only way out of X is via NormalDest, X can
|
||||||
// only properly dominate a node if NormalDest dominates that node too.
|
// only properly dominate a node if NormalDest dominates that node too.
|
||||||
for (const_pred_iterator PI = pred_begin(End), E = pred_end(End);
|
for (const BasicBlock *BB : predecessors(End)) {
|
||||||
PI != E; ++PI) {
|
|
||||||
const BasicBlock *BB = *PI;
|
|
||||||
if (BB == Start)
|
if (BB == Start)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
|
|
@ -2107,8 +2107,8 @@ void Verifier::visitLandingPadInst(LandingPadInst &LPI) {
|
||||||
|
|
||||||
// The landingpad instruction defines its parent as a landing pad block. The
|
// The landingpad instruction defines its parent as a landing pad block. The
|
||||||
// landing pad block may be branched to only by the unwind edge of an invoke.
|
// landing pad block may be branched to only by the unwind edge of an invoke.
|
||||||
for (pred_iterator I = pred_begin(BB), E = pred_end(BB); I != E; ++I) {
|
for (BasicBlock *Pred : predecessors(BB)) {
|
||||||
const InvokeInst *II = dyn_cast<InvokeInst>((*I)->getTerminator());
|
const InvokeInst *II = dyn_cast<InvokeInst>(Pred->getTerminator());
|
||||||
Assert1(II && II->getUnwindDest() == BB && II->getNormalDest() != BB,
|
Assert1(II && II->getUnwindDest() == BB && II->getNormalDest() != BB,
|
||||||
"Block containing LandingPadInst must be jumped to "
|
"Block containing LandingPadInst must be jumped to "
|
||||||
"only by the unwind edge of an invoke.", &LPI);
|
"only by the unwind edge of an invoke.", &LPI);
|
||||||
|
|
|
@ -473,8 +473,7 @@ bool ArgPromotion::isSafeToPromoteArgument(Argument *Arg,
|
||||||
// Now check every path from the entry block to the load for transparency.
|
// Now check every path from the entry block to the load for transparency.
|
||||||
// To do this, we perform a depth first search on the inverse CFG from the
|
// To do this, we perform a depth first search on the inverse CFG from the
|
||||||
// loading block.
|
// loading block.
|
||||||
for (pred_iterator PI = pred_begin(BB), E = pred_end(BB); PI != E; ++PI) {
|
for (BasicBlock *P : predecessors(BB)) {
|
||||||
BasicBlock *P = *PI;
|
|
||||||
for (idf_ext_iterator<BasicBlock*, SmallPtrSet<BasicBlock*, 16> >
|
for (idf_ext_iterator<BasicBlock*, SmallPtrSet<BasicBlock*, 16> >
|
||||||
I = idf_ext_begin(P, TranspBlocks),
|
I = idf_ext_begin(P, TranspBlocks),
|
||||||
E = idf_ext_end(P, TranspBlocks); I != E; ++I)
|
E = idf_ext_end(P, TranspBlocks); I != E; ++I)
|
||||||
|
|
|
@ -229,9 +229,7 @@ void BlockExtractorPass::SplitLandingPadPreds(Function *F) {
|
||||||
// Look through the landing pad's predecessors. If one of them ends in an
|
// Look through the landing pad's predecessors. If one of them ends in an
|
||||||
// 'invoke', then we want to split the landing pad.
|
// 'invoke', then we want to split the landing pad.
|
||||||
bool Split = false;
|
bool Split = false;
|
||||||
for (pred_iterator
|
for (BasicBlock *BB : predecessors(LPad)) {
|
||||||
PI = pred_begin(LPad), PE = pred_end(LPad); PI != PE; ++PI) {
|
|
||||||
BasicBlock *BB = *PI;
|
|
||||||
if (BB->isLandingPad() && BB != Parent &&
|
if (BB->isLandingPad() && BB != Parent &&
|
||||||
isa<InvokeInst>(Parent->getTerminator())) {
|
isa<InvokeInst>(Parent->getTerminator())) {
|
||||||
Split = true;
|
Split = true;
|
||||||
|
|
|
@ -58,13 +58,12 @@ Function* PartialInliner::unswitchFunction(Function* F) {
|
||||||
BasicBlock* returnBlock = nullptr;
|
BasicBlock* returnBlock = nullptr;
|
||||||
BasicBlock* nonReturnBlock = nullptr;
|
BasicBlock* nonReturnBlock = nullptr;
|
||||||
unsigned returnCount = 0;
|
unsigned returnCount = 0;
|
||||||
for (succ_iterator SI = succ_begin(entryBlock), SE = succ_end(entryBlock);
|
for (BasicBlock *Succ : successors(entryBlock))
|
||||||
SI != SE; ++SI)
|
if (isa<ReturnInst>(Succ->getTerminator())) {
|
||||||
if (isa<ReturnInst>((*SI)->getTerminator())) {
|
returnBlock = Succ;
|
||||||
returnBlock = *SI;
|
|
||||||
returnCount++;
|
returnCount++;
|
||||||
} else
|
} else
|
||||||
nonReturnBlock = *SI;
|
nonReturnBlock = Succ;
|
||||||
|
|
||||||
if (returnCount != 1)
|
if (returnCount != 1)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
|
@ -2718,8 +2718,8 @@ bool InstCombiner::DoOneIteration(Function &F, unsigned Iteration) {
|
||||||
if (UserParent != BB) {
|
if (UserParent != BB) {
|
||||||
bool UserIsSuccessor = false;
|
bool UserIsSuccessor = false;
|
||||||
// See if the user is one of our successors.
|
// See if the user is one of our successors.
|
||||||
for (succ_iterator SI = succ_begin(BB), E = succ_end(BB); SI != E; ++SI)
|
for (BasicBlock *Succ : successors(BB))
|
||||||
if (*SI == UserParent) {
|
if (Succ == UserParent) {
|
||||||
UserIsSuccessor = true;
|
UserIsSuccessor = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -642,8 +642,7 @@ bool DSE::runOnBasicBlock(BasicBlock &BB) {
|
||||||
/// them to F.
|
/// them to F.
|
||||||
static void FindUnconditionalPreds(SmallVectorImpl<BasicBlock *> &Blocks,
|
static void FindUnconditionalPreds(SmallVectorImpl<BasicBlock *> &Blocks,
|
||||||
BasicBlock *BB, DominatorTree *DT) {
|
BasicBlock *BB, DominatorTree *DT) {
|
||||||
for (pred_iterator I = pred_begin(BB), E = pred_end(BB); I != E; ++I) {
|
for (BasicBlock *Pred : predecessors(BB)) {
|
||||||
BasicBlock *Pred = *I;
|
|
||||||
if (Pred == BB) continue;
|
if (Pred == BB) continue;
|
||||||
TerminatorInst *PredTI = Pred->getTerminator();
|
TerminatorInst *PredTI = Pred->getTerminator();
|
||||||
if (PredTI->getNumSuccessors() != 1)
|
if (PredTI->getNumSuccessors() != 1)
|
||||||
|
|
|
@ -1555,9 +1555,7 @@ bool GVN::PerformLoadPRE(LoadInst *LI, AvailValInBlkVect &ValuesPerBlock,
|
||||||
FullyAvailableBlocks[UnavailableBlocks[i]] = false;
|
FullyAvailableBlocks[UnavailableBlocks[i]] = false;
|
||||||
|
|
||||||
SmallVector<BasicBlock *, 4> CriticalEdgePred;
|
SmallVector<BasicBlock *, 4> CriticalEdgePred;
|
||||||
for (pred_iterator PI = pred_begin(LoadBB), E = pred_end(LoadBB);
|
for (BasicBlock *Pred : predecessors(LoadBB)) {
|
||||||
PI != E; ++PI) {
|
|
||||||
BasicBlock *Pred = *PI;
|
|
||||||
if (IsValueFullyAvailableInBlock(Pred, FullyAvailableBlocks, 0)) {
|
if (IsValueFullyAvailableInBlock(Pred, FullyAvailableBlocks, 0)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -2483,9 +2481,7 @@ bool GVN::performPRE(Function &F) {
|
||||||
BasicBlock *PREPred = nullptr;
|
BasicBlock *PREPred = nullptr;
|
||||||
predMap.clear();
|
predMap.clear();
|
||||||
|
|
||||||
for (pred_iterator PI = pred_begin(CurrentBlock),
|
for (BasicBlock *P : predecessors(CurrentBlock)) {
|
||||||
PE = pred_end(CurrentBlock); PI != PE; ++PI) {
|
|
||||||
BasicBlock *P = *PI;
|
|
||||||
// We're not interested in PRE where the block is its
|
// We're not interested in PRE where the block is its
|
||||||
// own predecessor, or in blocks with predecessors
|
// own predecessor, or in blocks with predecessors
|
||||||
// that are not reachable.
|
// that are not reachable.
|
||||||
|
@ -2713,14 +2709,13 @@ void GVN::addDeadBlock(BasicBlock *BB) {
|
||||||
for (SmallVectorImpl<BasicBlock *>::iterator I = Dom.begin(),
|
for (SmallVectorImpl<BasicBlock *>::iterator I = Dom.begin(),
|
||||||
E = Dom.end(); I != E; I++) {
|
E = Dom.end(); I != E; I++) {
|
||||||
BasicBlock *B = *I;
|
BasicBlock *B = *I;
|
||||||
for (succ_iterator SI = succ_begin(B), SE = succ_end(B); SI != SE; SI++) {
|
for (BasicBlock *S : successors(B)) {
|
||||||
BasicBlock *S = *SI;
|
|
||||||
if (DeadBlocks.count(S))
|
if (DeadBlocks.count(S))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
bool AllPredDead = true;
|
bool AllPredDead = true;
|
||||||
for (pred_iterator PI = pred_begin(S), PE = pred_end(S); PI != PE; PI++)
|
for (BasicBlock *Pred : predecessors(S))
|
||||||
if (!DeadBlocks.count(*PI)) {
|
if (!DeadBlocks.count(Pred)) {
|
||||||
AllPredDead = false;
|
AllPredDead = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -353,8 +353,8 @@ ComputeValueKnownInPredecessors(Value *V, BasicBlock *BB, PredValueInfo &Result,
|
||||||
|
|
||||||
// If V is a constant, then it is known in all predecessors.
|
// If V is a constant, then it is known in all predecessors.
|
||||||
if (Constant *KC = getKnownConstant(V, Preference)) {
|
if (Constant *KC = getKnownConstant(V, Preference)) {
|
||||||
for (pred_iterator PI = pred_begin(BB), E = pred_end(BB); PI != E; ++PI)
|
for (BasicBlock *Pred : predecessors(BB))
|
||||||
Result.push_back(std::make_pair(KC, *PI));
|
Result.push_back(std::make_pair(KC, Pred));
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -377,8 +377,7 @@ ComputeValueKnownInPredecessors(Value *V, BasicBlock *BB, PredValueInfo &Result,
|
||||||
// "X < 4" and "X < 3" is known true but "X < 4" itself is not available.
|
// "X < 4" and "X < 3" is known true but "X < 4" itself is not available.
|
||||||
// Perhaps getConstantOnEdge should be smart enough to do this?
|
// Perhaps getConstantOnEdge should be smart enough to do this?
|
||||||
|
|
||||||
for (pred_iterator PI = pred_begin(BB), E = pred_end(BB); PI != E; ++PI) {
|
for (BasicBlock *P : predecessors(BB)) {
|
||||||
BasicBlock *P = *PI;
|
|
||||||
// If the value is known by LazyValueInfo to be a constant in a
|
// If the value is known by LazyValueInfo to be a constant in a
|
||||||
// predecessor, use that information to try to thread this block.
|
// predecessor, use that information to try to thread this block.
|
||||||
Constant *PredCst = LVI->getConstantOnEdge(V, P, BB);
|
Constant *PredCst = LVI->getConstantOnEdge(V, P, BB);
|
||||||
|
@ -532,8 +531,7 @@ ComputeValueKnownInPredecessors(Value *V, BasicBlock *BB, PredValueInfo &Result,
|
||||||
cast<Instruction>(Cmp->getOperand(0))->getParent() != BB) {
|
cast<Instruction>(Cmp->getOperand(0))->getParent() != BB) {
|
||||||
Constant *RHSCst = cast<Constant>(Cmp->getOperand(1));
|
Constant *RHSCst = cast<Constant>(Cmp->getOperand(1));
|
||||||
|
|
||||||
for (pred_iterator PI = pred_begin(BB), E = pred_end(BB);PI != E; ++PI){
|
for (BasicBlock *P : predecessors(BB)) {
|
||||||
BasicBlock *P = *PI;
|
|
||||||
// If the value is known by LazyValueInfo to be a constant in a
|
// If the value is known by LazyValueInfo to be a constant in a
|
||||||
// predecessor, use that information to try to thread this block.
|
// predecessor, use that information to try to thread this block.
|
||||||
LazyValueInfo::Tristate Res =
|
LazyValueInfo::Tristate Res =
|
||||||
|
@ -606,8 +604,8 @@ ComputeValueKnownInPredecessors(Value *V, BasicBlock *BB, PredValueInfo &Result,
|
||||||
// If all else fails, see if LVI can figure out a constant value for us.
|
// If all else fails, see if LVI can figure out a constant value for us.
|
||||||
Constant *CI = LVI->getConstant(V, BB);
|
Constant *CI = LVI->getConstant(V, BB);
|
||||||
if (Constant *KC = getKnownConstant(CI, Preference)) {
|
if (Constant *KC = getKnownConstant(CI, Preference)) {
|
||||||
for (pred_iterator PI = pred_begin(BB), E = pred_end(BB); PI != E; ++PI)
|
for (BasicBlock *Pred : predecessors(BB))
|
||||||
Result.push_back(std::make_pair(KC, *PI));
|
Result.push_back(std::make_pair(KC, Pred));
|
||||||
}
|
}
|
||||||
|
|
||||||
return !Result.empty();
|
return !Result.empty();
|
||||||
|
@ -899,10 +897,7 @@ bool JumpThreading::SimplifyPartiallyRedundantLoad(LoadInst *LI) {
|
||||||
|
|
||||||
// If we got here, the loaded value is transparent through to the start of the
|
// If we got here, the loaded value is transparent through to the start of the
|
||||||
// block. Check to see if it is available in any of the predecessor blocks.
|
// block. Check to see if it is available in any of the predecessor blocks.
|
||||||
for (pred_iterator PI = pred_begin(LoadBB), PE = pred_end(LoadBB);
|
for (BasicBlock *PredBB : predecessors(LoadBB)) {
|
||||||
PI != PE; ++PI) {
|
|
||||||
BasicBlock *PredBB = *PI;
|
|
||||||
|
|
||||||
// If we already scanned this predecessor, skip it.
|
// If we already scanned this predecessor, skip it.
|
||||||
if (!PredsScanned.insert(PredBB))
|
if (!PredsScanned.insert(PredBB))
|
||||||
continue;
|
continue;
|
||||||
|
@ -952,9 +947,7 @@ bool JumpThreading::SimplifyPartiallyRedundantLoad(LoadInst *LI) {
|
||||||
AvailablePredSet.insert(AvailablePreds[i].first);
|
AvailablePredSet.insert(AvailablePreds[i].first);
|
||||||
|
|
||||||
// Add all the unavailable predecessors to the PredsToSplit list.
|
// Add all the unavailable predecessors to the PredsToSplit list.
|
||||||
for (pred_iterator PI = pred_begin(LoadBB), PE = pred_end(LoadBB);
|
for (BasicBlock *P : predecessors(LoadBB)) {
|
||||||
PI != PE; ++PI) {
|
|
||||||
BasicBlock *P = *PI;
|
|
||||||
// If the predecessor is an indirect goto, we can't split the edge.
|
// If the predecessor is an indirect goto, we can't split the edge.
|
||||||
if (isa<IndirectBrInst>(P->getTerminator()))
|
if (isa<IndirectBrInst>(P->getTerminator()))
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -145,9 +145,7 @@ bool LoopInstSimplify::runOnLoop(Loop *L, LPPassManager &LPM) {
|
||||||
// bodies of subloops. We visit the headers of loops so that we can process
|
// bodies of subloops. We visit the headers of loops so that we can process
|
||||||
// their phis, but we contract the rest of the subloop body and only follow
|
// their phis, but we contract the rest of the subloop body and only follow
|
||||||
// edges leading back to the original loop.
|
// edges leading back to the original loop.
|
||||||
for (succ_iterator SI = succ_begin(BB), SE = succ_end(BB); SI != SE;
|
for (BasicBlock *SuccBB : successors(BB)) {
|
||||||
++SI) {
|
|
||||||
BasicBlock *SuccBB = *SI;
|
|
||||||
if (!Visited.insert(SuccBB))
|
if (!Visited.insert(SuccBB))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
|
|
@ -515,9 +515,9 @@ static bool isTrivialLoopExitBlockHelper(Loop *L, BasicBlock *BB,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Otherwise, this is an unvisited intra-loop node. Check all successors.
|
// Otherwise, this is an unvisited intra-loop node. Check all successors.
|
||||||
for (succ_iterator SI = succ_begin(BB), E = succ_end(BB); SI != E; ++SI) {
|
for (BasicBlock *Succ : successors(BB)) {
|
||||||
// Check to see if the successor is a trivial loop exit.
|
// Check to see if the successor is a trivial loop exit.
|
||||||
if (!isTrivialLoopExitBlockHelper(L, *SI, ExitBB, Visited))
|
if (!isTrivialLoopExitBlockHelper(L, Succ, ExitBB, Visited))
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -861,9 +861,7 @@ void LoopUnswitch::UnswitchNontrivialCondition(Value *LIC, Constant *Val,
|
||||||
PHINode *PN = PHINode::Create(LPad->getType(), 0, "",
|
PHINode *PN = PHINode::Create(LPad->getType(), 0, "",
|
||||||
ExitSucc->getFirstInsertionPt());
|
ExitSucc->getFirstInsertionPt());
|
||||||
|
|
||||||
for (pred_iterator I = pred_begin(ExitSucc), E = pred_end(ExitSucc);
|
for (BasicBlock *BB : predecessors(ExitSucc)) {
|
||||||
I != E; ++I) {
|
|
||||||
BasicBlock *BB = *I;
|
|
||||||
LandingPadInst *LPI = BB->getLandingPadInst();
|
LandingPadInst *LPI = BB->getLandingPadInst();
|
||||||
LPI->replaceAllUsesWith(PN);
|
LPI->replaceAllUsesWith(PN);
|
||||||
PN->addIncoming(LPI, BB);
|
PN->addIncoming(LPI, BB);
|
||||||
|
|
|
@ -865,8 +865,7 @@ void SampleFunctionProfile::buildEdges(Function &F) {
|
||||||
SmallPtrSet<BasicBlock *, 16> Visited;
|
SmallPtrSet<BasicBlock *, 16> Visited;
|
||||||
if (!Predecessors[B1].empty())
|
if (!Predecessors[B1].empty())
|
||||||
llvm_unreachable("Found a stale predecessors list in a basic block.");
|
llvm_unreachable("Found a stale predecessors list in a basic block.");
|
||||||
for (pred_iterator PI = pred_begin(B1), PE = pred_end(B1); PI != PE; ++PI) {
|
for (BasicBlock *B2 : predecessors(B1)) {
|
||||||
BasicBlock *B2 = *PI;
|
|
||||||
if (Visited.insert(B2))
|
if (Visited.insert(B2))
|
||||||
Predecessors[B1].push_back(B2);
|
Predecessors[B1].push_back(B2);
|
||||||
}
|
}
|
||||||
|
@ -875,8 +874,7 @@ void SampleFunctionProfile::buildEdges(Function &F) {
|
||||||
Visited.clear();
|
Visited.clear();
|
||||||
if (!Successors[B1].empty())
|
if (!Successors[B1].empty())
|
||||||
llvm_unreachable("Found a stale successors list in a basic block.");
|
llvm_unreachable("Found a stale successors list in a basic block.");
|
||||||
for (succ_iterator SI = succ_begin(B1), SE = succ_end(B1); SI != SE; ++SI) {
|
for (BasicBlock *B2 : successors(B1)) {
|
||||||
BasicBlock *B2 = *SI;
|
|
||||||
if (Visited.insert(B2))
|
if (Visited.insert(B2))
|
||||||
Successors[B1].push_back(B2);
|
Successors[B1].push_back(B2);
|
||||||
}
|
}
|
||||||
|
|
|
@ -258,10 +258,11 @@ bool Sinking::SinkInstruction(Instruction *Inst,
|
||||||
|
|
||||||
// If no suitable postdominator was found, look at all the successors and
|
// If no suitable postdominator was found, look at all the successors and
|
||||||
// decide which one we should sink to, if any.
|
// decide which one we should sink to, if any.
|
||||||
for (succ_iterator I = succ_begin(Inst->getParent()),
|
for (BasicBlock *Succ : successors(Inst->getParent())) {
|
||||||
E = succ_end(Inst->getParent()); I != E && !SuccToSinkTo; ++I) {
|
if (SuccToSinkTo)
|
||||||
if (IsAcceptableTarget(Inst, *I))
|
break;
|
||||||
SuccToSinkTo = *I;
|
if (IsAcceptableTarget(Inst, Succ))
|
||||||
|
SuccToSinkTo = Succ;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we couldn't find a block to sink to, ignore this instruction.
|
// If we couldn't find a block to sink to, ignore this instruction.
|
||||||
|
|
|
@ -365,41 +365,39 @@ void StructurizeCFG::gatherPredicates(RegionNode *N) {
|
||||||
BBPredicates &Pred = Predicates[BB];
|
BBPredicates &Pred = Predicates[BB];
|
||||||
BBPredicates &LPred = LoopPreds[BB];
|
BBPredicates &LPred = LoopPreds[BB];
|
||||||
|
|
||||||
for (pred_iterator PI = pred_begin(BB), PE = pred_end(BB);
|
for (BasicBlock *Predecessor : predecessors(BB)) {
|
||||||
PI != PE; ++PI) {
|
|
||||||
|
|
||||||
// Ignore it if it's a branch from outside into our region entry
|
// Ignore it if it's a branch from outside into our region entry
|
||||||
if (!ParentRegion->contains(*PI))
|
if (!ParentRegion->contains(Predecessor))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
Region *R = RI->getRegionFor(*PI);
|
Region *R = RI->getRegionFor(Predecessor);
|
||||||
if (R == ParentRegion) {
|
if (R == ParentRegion) {
|
||||||
|
|
||||||
// It's a top level block in our region
|
// It's a top level block in our region
|
||||||
BranchInst *Term = cast<BranchInst>((*PI)->getTerminator());
|
BranchInst *Term = cast<BranchInst>(Predecessor->getTerminator());
|
||||||
for (unsigned i = 0, e = Term->getNumSuccessors(); i != e; ++i) {
|
for (unsigned i = 0, e = Term->getNumSuccessors(); i != e; ++i) {
|
||||||
BasicBlock *Succ = Term->getSuccessor(i);
|
BasicBlock *Succ = Term->getSuccessor(i);
|
||||||
if (Succ != BB)
|
if (Succ != BB)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (Visited.count(*PI)) {
|
if (Visited.count(Predecessor)) {
|
||||||
// Normal forward edge
|
// Normal forward edge
|
||||||
if (Term->isConditional()) {
|
if (Term->isConditional()) {
|
||||||
// Try to treat it like an ELSE block
|
// Try to treat it like an ELSE block
|
||||||
BasicBlock *Other = Term->getSuccessor(!i);
|
BasicBlock *Other = Term->getSuccessor(!i);
|
||||||
if (Visited.count(Other) && !Loops.count(Other) &&
|
if (Visited.count(Other) && !Loops.count(Other) &&
|
||||||
!Pred.count(Other) && !Pred.count(*PI)) {
|
!Pred.count(Other) && !Pred.count(Predecessor)) {
|
||||||
|
|
||||||
Pred[Other] = BoolFalse;
|
Pred[Other] = BoolFalse;
|
||||||
Pred[*PI] = BoolTrue;
|
Pred[Predecessor] = BoolTrue;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Pred[*PI] = buildCondition(Term, i, false);
|
Pred[Predecessor] = buildCondition(Term, i, false);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// Back edge
|
// Back edge
|
||||||
LPred[*PI] = buildCondition(Term, i, true);
|
LPred[Predecessor] = buildCondition(Term, i, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -574,11 +572,8 @@ void StructurizeCFG::killTerminator(BasicBlock *BB) {
|
||||||
if (!Term)
|
if (!Term)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for (succ_iterator SI = succ_begin(BB), SE = succ_end(BB);
|
for (BasicBlock *Succ : successors(BB))
|
||||||
SI != SE; ++SI) {
|
delPhiValues(BB, Succ);
|
||||||
|
|
||||||
delPhiValues(BB, *SI);
|
|
||||||
}
|
|
||||||
|
|
||||||
Term->eraseFromParent();
|
Term->eraseFromParent();
|
||||||
}
|
}
|
||||||
|
@ -592,10 +587,7 @@ void StructurizeCFG::changeExit(RegionNode *Node, BasicBlock *NewExit,
|
||||||
BasicBlock *Dominator = nullptr;
|
BasicBlock *Dominator = nullptr;
|
||||||
|
|
||||||
// Find all the edges from the sub region to the exit
|
// Find all the edges from the sub region to the exit
|
||||||
for (pred_iterator I = pred_begin(OldExit), E = pred_end(OldExit);
|
for (BasicBlock *BB : predecessors(OldExit)) {
|
||||||
I != E;) {
|
|
||||||
|
|
||||||
BasicBlock *BB = *I++;
|
|
||||||
if (!SubRegion->contains(BB))
|
if (!SubRegion->contains(BB))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
|
|
@ -335,7 +335,7 @@ bool TailCallElim::markTails(Function &F, bool &AllCallsAreTailCalls) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto *SuccBB : make_range(succ_begin(BB), succ_end(BB))) {
|
for (auto *SuccBB : successors(BB)) {
|
||||||
auto &State = Visited[SuccBB];
|
auto &State = Visited[SuccBB];
|
||||||
if (State < Escaped) {
|
if (State < Escaped) {
|
||||||
State = Escaped;
|
State = Escaped;
|
||||||
|
@ -807,8 +807,7 @@ bool TailCallElim::FoldReturnAndProcessPred(BasicBlock *BB,
|
||||||
// predecessors and perform TRC there. Look for predecessors that end
|
// predecessors and perform TRC there. Look for predecessors that end
|
||||||
// in unconditional branch and recursive call(s).
|
// in unconditional branch and recursive call(s).
|
||||||
SmallVector<BranchInst*, 8> UncondBranchPreds;
|
SmallVector<BranchInst*, 8> UncondBranchPreds;
|
||||||
for (pred_iterator PI = pred_begin(BB), E = pred_end(BB); PI != E; ++PI) {
|
for (BasicBlock *Pred : predecessors(BB)) {
|
||||||
BasicBlock *Pred = *PI;
|
|
||||||
TerminatorInst *PTI = Pred->getTerminator();
|
TerminatorInst *PTI = Pred->getTerminator();
|
||||||
if (BranchInst *BI = dyn_cast<BranchInst>(PTI))
|
if (BranchInst *BI = dyn_cast<BranchInst>(PTI))
|
||||||
if (BI->isUnconditional())
|
if (BI->isUnconditional())
|
||||||
|
|
|
@ -549,14 +549,11 @@ void llvm::SplitLandingPadPredecessors(BasicBlock *OrigBB,
|
||||||
|
|
||||||
// Move the remaining edges from OrigBB to point to NewBB2.
|
// Move the remaining edges from OrigBB to point to NewBB2.
|
||||||
SmallVector<BasicBlock*, 8> NewBB2Preds;
|
SmallVector<BasicBlock*, 8> NewBB2Preds;
|
||||||
for (pred_iterator i = pred_begin(OrigBB), e = pred_end(OrigBB);
|
for (BasicBlock *Pred : predecessors(OrigBB)) {
|
||||||
i != e; ) {
|
|
||||||
BasicBlock *Pred = *i++;
|
|
||||||
if (Pred == NewBB1) continue;
|
if (Pred == NewBB1) continue;
|
||||||
assert(!isa<IndirectBrInst>(Pred->getTerminator()) &&
|
assert(!isa<IndirectBrInst>(Pred->getTerminator()) &&
|
||||||
"Cannot split an edge from an IndirectBrInst");
|
"Cannot split an edge from an IndirectBrInst");
|
||||||
NewBB2Preds.push_back(Pred);
|
NewBB2Preds.push_back(Pred);
|
||||||
e = pred_end(OrigBB);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BasicBlock *NewBB2 = nullptr;
|
BasicBlock *NewBB2 = nullptr;
|
||||||
|
|
|
@ -233,9 +233,7 @@ BasicBlock *llvm::SplitCriticalEdge(TerminatorInst *TI, unsigned SuccNum,
|
||||||
if (PN->getIncomingBlock(i) != NewBB)
|
if (PN->getIncomingBlock(i) != NewBB)
|
||||||
OtherPreds.push_back(PN->getIncomingBlock(i));
|
OtherPreds.push_back(PN->getIncomingBlock(i));
|
||||||
} else {
|
} else {
|
||||||
for (pred_iterator I = pred_begin(DestBB), E = pred_end(DestBB);
|
for (BasicBlock *P : predecessors(DestBB)) {
|
||||||
I != E; ++I) {
|
|
||||||
BasicBlock *P = *I;
|
|
||||||
if (P != NewBB)
|
if (P != NewBB)
|
||||||
OtherPreds.push_back(P);
|
OtherPreds.push_back(P);
|
||||||
}
|
}
|
||||||
|
@ -321,9 +319,7 @@ BasicBlock *llvm::SplitCriticalEdge(TerminatorInst *TI, unsigned SuccNum,
|
||||||
// the predecessor must be directly in TIL, not in a subloop, or again
|
// the predecessor must be directly in TIL, not in a subloop, or again
|
||||||
// LoopSimplify doesn't hold.
|
// LoopSimplify doesn't hold.
|
||||||
SmallVector<BasicBlock *, 4> LoopPreds;
|
SmallVector<BasicBlock *, 4> LoopPreds;
|
||||||
for (pred_iterator I = pred_begin(DestBB), E = pred_end(DestBB); I != E;
|
for (BasicBlock *P : predecessors(DestBB)) {
|
||||||
++I) {
|
|
||||||
BasicBlock *P = *I;
|
|
||||||
if (P == NewBB)
|
if (P == NewBB)
|
||||||
continue; // The new block is known.
|
continue; // The new block is known.
|
||||||
if (LI->getLoopFor(P) != TIL) {
|
if (LI->getLoopFor(P) != TIL) {
|
||||||
|
|
|
@ -514,9 +514,8 @@ void llvm::CloneAndPruneFunctionInto(Function *NewFunc, const Function *OldFunc,
|
||||||
assert(NumPreds < PN->getNumIncomingValues());
|
assert(NumPreds < PN->getNumIncomingValues());
|
||||||
// Count how many times each predecessor comes to this block.
|
// Count how many times each predecessor comes to this block.
|
||||||
std::map<BasicBlock*, unsigned> PredCount;
|
std::map<BasicBlock*, unsigned> PredCount;
|
||||||
for (pred_iterator PI = pred_begin(NewBB), E = pred_end(NewBB);
|
for (BasicBlock *Pred : predecessors(NewBB))
|
||||||
PI != E; ++PI)
|
--PredCount[Pred];
|
||||||
--PredCount[*PI];
|
|
||||||
|
|
||||||
// Figure out how many entries to remove from each PHI.
|
// Figure out how many entries to remove from each PHI.
|
||||||
for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i)
|
for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i)
|
||||||
|
|
|
@ -91,9 +91,8 @@ static SetVector<BasicBlock *> buildExtractionBlockSet(IteratorT BBBegin,
|
||||||
for (SetVector<BasicBlock *>::iterator I = std::next(Result.begin()),
|
for (SetVector<BasicBlock *>::iterator I = std::next(Result.begin()),
|
||||||
E = Result.end();
|
E = Result.end();
|
||||||
I != E; ++I)
|
I != E; ++I)
|
||||||
for (pred_iterator PI = pred_begin(*I), PE = pred_end(*I);
|
for (BasicBlock *Pred : predecessors(*I))
|
||||||
PI != PE; ++PI)
|
assert(Result.count(Pred) &&
|
||||||
assert(Result.count(*PI) &&
|
|
||||||
"No blocks in this region may have entries from outside the region"
|
"No blocks in this region may have entries from outside the region"
|
||||||
" except for the first block!");
|
" except for the first block!");
|
||||||
#endif
|
#endif
|
||||||
|
@ -721,9 +720,9 @@ Function *CodeExtractor::extractCodeRegion() {
|
||||||
SmallPtrSet<BasicBlock *, 1> ExitBlocks;
|
SmallPtrSet<BasicBlock *, 1> ExitBlocks;
|
||||||
for (SetVector<BasicBlock *>::iterator I = Blocks.begin(), E = Blocks.end();
|
for (SetVector<BasicBlock *>::iterator I = Blocks.begin(), E = Blocks.end();
|
||||||
I != E; ++I)
|
I != E; ++I)
|
||||||
for (succ_iterator SI = succ_begin(*I), SE = succ_end(*I); SI != SE; ++SI)
|
for (BasicBlock *Succ : successors(*I))
|
||||||
if (!Blocks.count(*SI))
|
if (!Blocks.count(Succ))
|
||||||
ExitBlocks.insert(*SI);
|
ExitBlocks.insert(Succ);
|
||||||
NumExitBlocks = ExitBlocks.size();
|
NumExitBlocks = ExitBlocks.size();
|
||||||
|
|
||||||
// Construct new function based on inputs/outputs & add allocas for all defs.
|
// Construct new function based on inputs/outputs & add allocas for all defs.
|
||||||
|
|
|
@ -1129,8 +1129,8 @@ static void changeToUnreachable(Instruction *I, bool UseLLVMTrap) {
|
||||||
BasicBlock *BB = I->getParent();
|
BasicBlock *BB = I->getParent();
|
||||||
// Loop over all of the successors, removing BB's entry from any PHI
|
// Loop over all of the successors, removing BB's entry from any PHI
|
||||||
// nodes.
|
// nodes.
|
||||||
for (succ_iterator SI = succ_begin(BB), SE = succ_end(BB); SI != SE; ++SI)
|
for (BasicBlock *Succ : successors(BB))
|
||||||
(*SI)->removePredecessor(BB);
|
Succ->removePredecessor(BB);
|
||||||
|
|
||||||
// Insert a call to llvm.trap right before this. This turns the undefined
|
// Insert a call to llvm.trap right before this. This turns the undefined
|
||||||
// behavior into a hard fail instead of falling through into random code.
|
// behavior into a hard fail instead of falling through into random code.
|
||||||
|
@ -1236,9 +1236,9 @@ static bool markAliveBlocks(BasicBlock *BB,
|
||||||
}
|
}
|
||||||
|
|
||||||
Changed |= ConstantFoldTerminator(BB, true);
|
Changed |= ConstantFoldTerminator(BB, true);
|
||||||
for (succ_iterator SI = succ_begin(BB), SE = succ_end(BB); SI != SE; ++SI)
|
for (BasicBlock *Succ : successors(BB))
|
||||||
if (Reachable.insert(*SI))
|
if (Reachable.insert(Succ))
|
||||||
Worklist.push_back(*SI);
|
Worklist.push_back(Succ);
|
||||||
} while (!Worklist.empty());
|
} while (!Worklist.empty());
|
||||||
return Changed;
|
return Changed;
|
||||||
}
|
}
|
||||||
|
@ -1263,9 +1263,9 @@ bool llvm::removeUnreachableBlocks(Function &F) {
|
||||||
if (Reachable.count(BB))
|
if (Reachable.count(BB))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
for (succ_iterator SI = succ_begin(BB), SE = succ_end(BB); SI != SE; ++SI)
|
for (BasicBlock *Succ : successors(BB))
|
||||||
if (Reachable.count(*SI))
|
if (Reachable.count(Succ))
|
||||||
(*SI)->removePredecessor(BB);
|
Succ->removePredecessor(BB);
|
||||||
BB->dropAllReferences();
|
BB->dropAllReferences();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -114,9 +114,7 @@ BasicBlock *llvm::InsertPreheaderForLoop(Loop *L, Pass *PP) {
|
||||||
|
|
||||||
// Compute the set of predecessors of the loop that are not in the loop.
|
// Compute the set of predecessors of the loop that are not in the loop.
|
||||||
SmallVector<BasicBlock*, 8> OutsideBlocks;
|
SmallVector<BasicBlock*, 8> OutsideBlocks;
|
||||||
for (pred_iterator PI = pred_begin(Header), PE = pred_end(Header);
|
for (BasicBlock *P : predecessors(Header)) {
|
||||||
PI != PE; ++PI) {
|
|
||||||
BasicBlock *P = *PI;
|
|
||||||
if (!L->contains(P)) { // Coming in from outside the loop?
|
if (!L->contains(P)) { // Coming in from outside the loop?
|
||||||
// If the loop is branched to from an indirect branch, we won't
|
// If the loop is branched to from an indirect branch, we won't
|
||||||
// be able to fully transform the loop, because it prohibits
|
// be able to fully transform the loop, because it prohibits
|
||||||
|
@ -158,8 +156,7 @@ BasicBlock *llvm::InsertPreheaderForLoop(Loop *L, Pass *PP) {
|
||||||
/// the loop.
|
/// the loop.
|
||||||
static BasicBlock *rewriteLoopExitBlock(Loop *L, BasicBlock *Exit, Pass *PP) {
|
static BasicBlock *rewriteLoopExitBlock(Loop *L, BasicBlock *Exit, Pass *PP) {
|
||||||
SmallVector<BasicBlock*, 8> LoopBlocks;
|
SmallVector<BasicBlock*, 8> LoopBlocks;
|
||||||
for (pred_iterator I = pred_begin(Exit), E = pred_end(Exit); I != E; ++I) {
|
for (BasicBlock *P : predecessors(Exit)) {
|
||||||
BasicBlock *P = *I;
|
|
||||||
if (L->contains(P)) {
|
if (L->contains(P)) {
|
||||||
// Don't do this if the loop is exited via an indirect branch.
|
// Don't do this if the loop is exited via an indirect branch.
|
||||||
if (isa<IndirectBrInst>(P->getTerminator())) return nullptr;
|
if (isa<IndirectBrInst>(P->getTerminator())) return nullptr;
|
||||||
|
@ -199,10 +196,8 @@ static void addBlockAndPredsToSet(BasicBlock *InputBB, BasicBlock *StopBlock,
|
||||||
if (Blocks.insert(BB).second && BB != StopBlock)
|
if (Blocks.insert(BB).second && BB != StopBlock)
|
||||||
// If BB is not already processed and it is not a stop block then
|
// If BB is not already processed and it is not a stop block then
|
||||||
// insert its predecessor in the work list
|
// insert its predecessor in the work list
|
||||||
for (pred_iterator I = pred_begin(BB), E = pred_end(BB); I != E; ++I) {
|
for (BasicBlock *WBB : predecessors(BB))
|
||||||
BasicBlock *WBB = *I;
|
|
||||||
Worklist.push_back(WBB);
|
Worklist.push_back(WBB);
|
||||||
}
|
|
||||||
} while (!Worklist.empty());
|
} while (!Worklist.empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -316,8 +311,7 @@ static Loop *separateNestedLoop(Loop *L, BasicBlock *Preheader,
|
||||||
// Determine which blocks should stay in L and which should be moved out to
|
// Determine which blocks should stay in L and which should be moved out to
|
||||||
// the Outer loop now.
|
// the Outer loop now.
|
||||||
std::set<BasicBlock*> BlocksInL;
|
std::set<BasicBlock*> BlocksInL;
|
||||||
for (pred_iterator PI=pred_begin(Header), E = pred_end(Header); PI!=E; ++PI) {
|
for (BasicBlock *P : predecessors(Header)) {
|
||||||
BasicBlock *P = *PI;
|
|
||||||
if (DT->dominates(Header, P))
|
if (DT->dominates(Header, P))
|
||||||
addBlockAndPredsToSet(P, Header, BlocksInL);
|
addBlockAndPredsToSet(P, Header, BlocksInL);
|
||||||
}
|
}
|
||||||
|
@ -371,9 +365,7 @@ static BasicBlock *insertUniqueBackedgeBlock(Loop *L, BasicBlock *Preheader,
|
||||||
|
|
||||||
// Figure out which basic blocks contain back-edges to the loop header.
|
// Figure out which basic blocks contain back-edges to the loop header.
|
||||||
std::vector<BasicBlock*> BackedgeBlocks;
|
std::vector<BasicBlock*> BackedgeBlocks;
|
||||||
for (pred_iterator I = pred_begin(Header), E = pred_end(Header); I != E; ++I){
|
for (BasicBlock *P : predecessors(Header)) {
|
||||||
BasicBlock *P = *I;
|
|
||||||
|
|
||||||
// Indirectbr edges cannot be split, so we must fail if we find one.
|
// Indirectbr edges cannot be split, so we must fail if we find one.
|
||||||
if (isa<IndirectBrInst>(P->getTerminator()))
|
if (isa<IndirectBrInst>(P->getTerminator()))
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
@ -488,9 +480,7 @@ ReprocessLoop:
|
||||||
if (*BB == L->getHeader()) continue;
|
if (*BB == L->getHeader()) continue;
|
||||||
|
|
||||||
SmallPtrSet<BasicBlock*, 4> BadPreds;
|
SmallPtrSet<BasicBlock*, 4> BadPreds;
|
||||||
for (pred_iterator PI = pred_begin(*BB),
|
for (BasicBlock *P : predecessors(*BB)) {
|
||||||
PE = pred_end(*BB); PI != PE; ++PI) {
|
|
||||||
BasicBlock *P = *PI;
|
|
||||||
if (!L->contains(P))
|
if (!L->contains(P))
|
||||||
BadPreds.insert(P);
|
BadPreds.insert(P);
|
||||||
}
|
}
|
||||||
|
@ -503,8 +493,8 @@ ReprocessLoop:
|
||||||
<< (*I)->getName() << "\n");
|
<< (*I)->getName() << "\n");
|
||||||
|
|
||||||
// Inform each successor of each dead pred.
|
// Inform each successor of each dead pred.
|
||||||
for (succ_iterator SI = succ_begin(*I), SE = succ_end(*I); SI != SE; ++SI)
|
for (BasicBlock *Succ : successors(*I))
|
||||||
(*SI)->removePredecessor(*I);
|
Succ->removePredecessor(*I);
|
||||||
// Zap the dead pred's terminator and replace it with unreachable.
|
// Zap the dead pred's terminator and replace it with unreachable.
|
||||||
TerminatorInst *TI = (*I)->getTerminator();
|
TerminatorInst *TI = (*I)->getTerminator();
|
||||||
TI->replaceAllUsesWith(UndefValue::get(TI->getType()));
|
TI->replaceAllUsesWith(UndefValue::get(TI->getType()));
|
||||||
|
@ -561,11 +551,10 @@ ReprocessLoop:
|
||||||
for (SmallSetVector<BasicBlock *, 8>::iterator I = ExitBlockSet.begin(),
|
for (SmallSetVector<BasicBlock *, 8>::iterator I = ExitBlockSet.begin(),
|
||||||
E = ExitBlockSet.end(); I != E; ++I) {
|
E = ExitBlockSet.end(); I != E; ++I) {
|
||||||
BasicBlock *ExitBlock = *I;
|
BasicBlock *ExitBlock = *I;
|
||||||
for (pred_iterator PI = pred_begin(ExitBlock), PE = pred_end(ExitBlock);
|
for (BasicBlock *Pred : predecessors(ExitBlock))
|
||||||
PI != PE; ++PI)
|
|
||||||
// Must be exactly this loop: no subloops, parent loops, or non-loop preds
|
// Must be exactly this loop: no subloops, parent loops, or non-loop preds
|
||||||
// allowed.
|
// allowed.
|
||||||
if (!L->contains(*PI)) {
|
if (!L->contains(Pred)) {
|
||||||
if (rewriteLoopExitBlock(L, ExitBlock, PP)) {
|
if (rewriteLoopExitBlock(L, ExitBlock, PP)) {
|
||||||
++NumInserted;
|
++NumInserted;
|
||||||
Changed = true;
|
Changed = true;
|
||||||
|
|
|
@ -328,11 +328,10 @@ bool llvm::UnrollLoop(Loop *L, unsigned Count, unsigned TripCount,
|
||||||
L->addBasicBlockToLoop(New, LI->getBase());
|
L->addBasicBlockToLoop(New, LI->getBase());
|
||||||
|
|
||||||
// Add phi entries for newly created values to all exit blocks.
|
// Add phi entries for newly created values to all exit blocks.
|
||||||
for (succ_iterator SI = succ_begin(*BB), SE = succ_end(*BB);
|
for (BasicBlock *Succ : successors(*BB)) {
|
||||||
SI != SE; ++SI) {
|
if (L->contains(Succ))
|
||||||
if (L->contains(*SI))
|
|
||||||
continue;
|
continue;
|
||||||
for (BasicBlock::iterator BBI = (*SI)->begin();
|
for (BasicBlock::iterator BBI = Succ->begin();
|
||||||
PHINode *phi = dyn_cast<PHINode>(BBI); ++BBI) {
|
PHINode *phi = dyn_cast<PHINode>(BBI); ++BBI) {
|
||||||
Value *Incoming = phi->getIncomingValueForBlock(*BB);
|
Value *Incoming = phi->getIncomingValueForBlock(*BB);
|
||||||
ValueToValueMapTy::iterator It = LastValueMap.find(Incoming);
|
ValueToValueMapTy::iterator It = LastValueMap.find(Incoming);
|
||||||
|
@ -414,11 +413,10 @@ bool llvm::UnrollLoop(Loop *L, unsigned Count, unsigned TripCount,
|
||||||
// Remove phi operands at this loop exit
|
// Remove phi operands at this loop exit
|
||||||
if (Dest != LoopExit) {
|
if (Dest != LoopExit) {
|
||||||
BasicBlock *BB = Latches[i];
|
BasicBlock *BB = Latches[i];
|
||||||
for (succ_iterator SI = succ_begin(BB), SE = succ_end(BB);
|
for (BasicBlock *Succ : successors(BB)) {
|
||||||
SI != SE; ++SI) {
|
if (Succ == Headers[i])
|
||||||
if (*SI == Headers[i])
|
|
||||||
continue;
|
continue;
|
||||||
for (BasicBlock::iterator BBI = (*SI)->begin();
|
for (BasicBlock::iterator BBI = Succ->begin();
|
||||||
PHINode *Phi = dyn_cast<PHINode>(BBI); ++BBI) {
|
PHINode *Phi = dyn_cast<PHINode>(BBI); ++BBI) {
|
||||||
Phi->removeIncomingValue(BB, false);
|
Phi->removeIncomingValue(BB, false);
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,9 +66,8 @@ static void ConnectProlog(Loop *L, Value *TripCount, unsigned Count,
|
||||||
// The new PHI node is inserted in the prolog end basic block.
|
// The new PHI node is inserted in the prolog end basic block.
|
||||||
// The new PHI name is added as an operand of a PHI node in either
|
// The new PHI name is added as an operand of a PHI node in either
|
||||||
// the loop header or the loop exit block.
|
// the loop header or the loop exit block.
|
||||||
for (succ_iterator SBI = succ_begin(Latch), SBE = succ_end(Latch);
|
for (BasicBlock *Succ : successors(Latch)) {
|
||||||
SBI != SBE; ++SBI) {
|
for (BasicBlock::iterator BBI = Succ->begin();
|
||||||
for (BasicBlock::iterator BBI = (*SBI)->begin();
|
|
||||||
PHINode *PN = dyn_cast<PHINode>(BBI); ++BBI) {
|
PHINode *PN = dyn_cast<PHINode>(BBI); ++BBI) {
|
||||||
|
|
||||||
// Add a new PHI node to the prolog end block and add the
|
// Add a new PHI node to the prolog end block and add the
|
||||||
|
|
|
@ -822,9 +822,7 @@ void PromoteMem2Reg::ComputeLiveInBlocks(
|
||||||
// Since the value is live into BB, it is either defined in a predecessor or
|
// Since the value is live into BB, it is either defined in a predecessor or
|
||||||
// live into it to. Add the preds to the worklist unless they are a
|
// live into it to. Add the preds to the worklist unless they are a
|
||||||
// defining block.
|
// defining block.
|
||||||
for (pred_iterator PI = pred_begin(BB), E = pred_end(BB); PI != E; ++PI) {
|
for (BasicBlock *P : predecessors(BB)) {
|
||||||
BasicBlock *P = *PI;
|
|
||||||
|
|
||||||
// The value is not live into a predecessor if it defines the value.
|
// The value is not live into a predecessor if it defines the value.
|
||||||
if (DefBlocks.count(P))
|
if (DefBlocks.count(P))
|
||||||
continue;
|
continue;
|
||||||
|
@ -885,9 +883,8 @@ void PromoteMem2Reg::DetermineInsertionPoint(AllocaInst *AI, unsigned AllocaNum,
|
||||||
DomTreeNode *Node = Worklist.pop_back_val();
|
DomTreeNode *Node = Worklist.pop_back_val();
|
||||||
BasicBlock *BB = Node->getBlock();
|
BasicBlock *BB = Node->getBlock();
|
||||||
|
|
||||||
for (succ_iterator SI = succ_begin(BB), SE = succ_end(BB); SI != SE;
|
for (BasicBlock *Succ : successors(BB)) {
|
||||||
++SI) {
|
DomTreeNode *SuccNode = DT.getNode(Succ);
|
||||||
DomTreeNode *SuccNode = DT.getNode(*SI);
|
|
||||||
|
|
||||||
// Quickly skip all CFG edges that are also dominator tree edges instead
|
// Quickly skip all CFG edges that are also dominator tree edges instead
|
||||||
// of catching them below.
|
// of catching them below.
|
||||||
|
|
|
@ -110,8 +110,7 @@ Value *SSAUpdater::GetValueInMiddleOfBlock(BasicBlock *BB) {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
bool isFirstPred = true;
|
bool isFirstPred = true;
|
||||||
for (pred_iterator PI = pred_begin(BB), E = pred_end(BB); PI != E; ++PI) {
|
for (BasicBlock *PredBB : predecessors(BB)) {
|
||||||
BasicBlock *PredBB = *PI;
|
|
||||||
Value *PredVal = GetValueAtEndOfBlock(PredBB);
|
Value *PredVal = GetValueAtEndOfBlock(PredBB);
|
||||||
PredValues.push_back(std::make_pair(PredBB, PredVal));
|
PredValues.push_back(std::make_pair(PredBB, PredVal));
|
||||||
|
|
||||||
|
@ -248,8 +247,7 @@ public:
|
||||||
for (unsigned PI = 0, E = SomePhi->getNumIncomingValues(); PI != E; ++PI)
|
for (unsigned PI = 0, E = SomePhi->getNumIncomingValues(); PI != E; ++PI)
|
||||||
Preds->push_back(SomePhi->getIncomingBlock(PI));
|
Preds->push_back(SomePhi->getIncomingBlock(PI));
|
||||||
} else {
|
} else {
|
||||||
for (pred_iterator PI = pred_begin(BB), E = pred_end(BB); PI != E; ++PI)
|
Preds->insert(Preds->end(), pred_begin(BB), pred_end(BB));
|
||||||
Preds->push_back(*PI);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -130,9 +130,9 @@ static bool SafeToMergeTerminators(TerminatorInst *SI1, TerminatorInst *SI2) {
|
||||||
BasicBlock *SI2BB = SI2->getParent();
|
BasicBlock *SI2BB = SI2->getParent();
|
||||||
SmallPtrSet<BasicBlock*, 16> SI1Succs(succ_begin(SI1BB), succ_end(SI1BB));
|
SmallPtrSet<BasicBlock*, 16> SI1Succs(succ_begin(SI1BB), succ_end(SI1BB));
|
||||||
|
|
||||||
for (succ_iterator I = succ_begin(SI2BB), E = succ_end(SI2BB); I != E; ++I)
|
for (BasicBlock *Succ : successors(SI2BB))
|
||||||
if (SI1Succs.count(*I))
|
if (SI1Succs.count(Succ))
|
||||||
for (BasicBlock::iterator BBI = (*I)->begin();
|
for (BasicBlock::iterator BBI = Succ->begin();
|
||||||
isa<PHINode>(BBI); ++BBI) {
|
isa<PHINode>(BBI); ++BBI) {
|
||||||
PHINode *PN = cast<PHINode>(BBI);
|
PHINode *PN = cast<PHINode>(BBI);
|
||||||
if (PN->getIncomingValueForBlock(SI1BB) !=
|
if (PN->getIncomingValueForBlock(SI1BB) !=
|
||||||
|
@ -171,9 +171,9 @@ static bool isProfitableToFoldUnconditional(BranchInst *SI1,
|
||||||
BasicBlock *SI1BB = SI1->getParent();
|
BasicBlock *SI1BB = SI1->getParent();
|
||||||
BasicBlock *SI2BB = SI2->getParent();
|
BasicBlock *SI2BB = SI2->getParent();
|
||||||
SmallPtrSet<BasicBlock*, 16> SI1Succs(succ_begin(SI1BB), succ_end(SI1BB));
|
SmallPtrSet<BasicBlock*, 16> SI1Succs(succ_begin(SI1BB), succ_end(SI1BB));
|
||||||
for (succ_iterator I = succ_begin(SI2BB), E = succ_end(SI2BB); I != E; ++I)
|
for (BasicBlock *Succ : successors(SI2BB))
|
||||||
if (SI1Succs.count(*I))
|
if (SI1Succs.count(Succ))
|
||||||
for (BasicBlock::iterator BBI = (*I)->begin();
|
for (BasicBlock::iterator BBI = Succ->begin();
|
||||||
isa<PHINode>(BBI); ++BBI) {
|
isa<PHINode>(BBI); ++BBI) {
|
||||||
PHINode *PN = cast<PHINode>(BBI);
|
PHINode *PN = cast<PHINode>(BBI);
|
||||||
if (PN->getIncomingValueForBlock(SI1BB) != Cond ||
|
if (PN->getIncomingValueForBlock(SI1BB) != Cond ||
|
||||||
|
@ -683,9 +683,9 @@ SimplifyEqualityComparisonWithOnlyPredecessor(TerminatorInst *TI,
|
||||||
|
|
||||||
// Remove PHI node entries for dead edges.
|
// Remove PHI node entries for dead edges.
|
||||||
BasicBlock *CheckEdge = TheRealDest;
|
BasicBlock *CheckEdge = TheRealDest;
|
||||||
for (succ_iterator SI = succ_begin(TIBB), e = succ_end(TIBB); SI != e; ++SI)
|
for (BasicBlock *Succ : successors(TIBB))
|
||||||
if (*SI != CheckEdge)
|
if (Succ != CheckEdge)
|
||||||
(*SI)->removePredecessor(TIBB);
|
Succ->removePredecessor(TIBB);
|
||||||
else
|
else
|
||||||
CheckEdge = nullptr;
|
CheckEdge = nullptr;
|
||||||
|
|
||||||
|
@ -981,9 +981,9 @@ bool SimplifyCFGOpt::FoldValueComparisonIntoPredecessors(TerminatorInst *TI,
|
||||||
// to put the select in this case.
|
// to put the select in this case.
|
||||||
static bool isSafeToHoistInvoke(BasicBlock *BB1, BasicBlock *BB2,
|
static bool isSafeToHoistInvoke(BasicBlock *BB1, BasicBlock *BB2,
|
||||||
Instruction *I1, Instruction *I2) {
|
Instruction *I1, Instruction *I2) {
|
||||||
for (succ_iterator SI = succ_begin(BB1), E = succ_end(BB1); SI != E; ++SI) {
|
for (BasicBlock *Succ : successors(BB1)) {
|
||||||
PHINode *PN;
|
PHINode *PN;
|
||||||
for (BasicBlock::iterator BBI = SI->begin();
|
for (BasicBlock::iterator BBI = Succ->begin();
|
||||||
(PN = dyn_cast<PHINode>(BBI)); ++BBI) {
|
(PN = dyn_cast<PHINode>(BBI)); ++BBI) {
|
||||||
Value *BB1V = PN->getIncomingValueForBlock(BB1);
|
Value *BB1V = PN->getIncomingValueForBlock(BB1);
|
||||||
Value *BB2V = PN->getIncomingValueForBlock(BB2);
|
Value *BB2V = PN->getIncomingValueForBlock(BB2);
|
||||||
|
@ -1063,9 +1063,9 @@ HoistTerminator:
|
||||||
if (isa<InvokeInst>(I1) && !isSafeToHoistInvoke(BB1, BB2, I1, I2))
|
if (isa<InvokeInst>(I1) && !isSafeToHoistInvoke(BB1, BB2, I1, I2))
|
||||||
return Changed;
|
return Changed;
|
||||||
|
|
||||||
for (succ_iterator SI = succ_begin(BB1), E = succ_end(BB1); SI != E; ++SI) {
|
for (BasicBlock *Succ : successors(BB1)) {
|
||||||
PHINode *PN;
|
PHINode *PN;
|
||||||
for (BasicBlock::iterator BBI = SI->begin();
|
for (BasicBlock::iterator BBI = Succ->begin();
|
||||||
(PN = dyn_cast<PHINode>(BBI)); ++BBI) {
|
(PN = dyn_cast<PHINode>(BBI)); ++BBI) {
|
||||||
Value *BB1V = PN->getIncomingValueForBlock(BB1);
|
Value *BB1V = PN->getIncomingValueForBlock(BB1);
|
||||||
Value *BB2V = PN->getIncomingValueForBlock(BB2);
|
Value *BB2V = PN->getIncomingValueForBlock(BB2);
|
||||||
|
@ -1094,9 +1094,9 @@ HoistTerminator:
|
||||||
// them. If they do, all PHI entries for BB1/BB2 must agree for all PHI
|
// them. If they do, all PHI entries for BB1/BB2 must agree for all PHI
|
||||||
// nodes, so we insert select instruction to compute the final result.
|
// nodes, so we insert select instruction to compute the final result.
|
||||||
std::map<std::pair<Value*,Value*>, SelectInst*> InsertedSelects;
|
std::map<std::pair<Value*,Value*>, SelectInst*> InsertedSelects;
|
||||||
for (succ_iterator SI = succ_begin(BB1), E = succ_end(BB1); SI != E; ++SI) {
|
for (BasicBlock *Succ : successors(BB1)) {
|
||||||
PHINode *PN;
|
PHINode *PN;
|
||||||
for (BasicBlock::iterator BBI = SI->begin();
|
for (BasicBlock::iterator BBI = Succ->begin();
|
||||||
(PN = dyn_cast<PHINode>(BBI)); ++BBI) {
|
(PN = dyn_cast<PHINode>(BBI)); ++BBI) {
|
||||||
Value *BB1V = PN->getIncomingValueForBlock(BB1);
|
Value *BB1V = PN->getIncomingValueForBlock(BB1);
|
||||||
Value *BB2V = PN->getIncomingValueForBlock(BB2);
|
Value *BB2V = PN->getIncomingValueForBlock(BB2);
|
||||||
|
@ -1118,8 +1118,8 @@ HoistTerminator:
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update any PHI nodes in our new successors.
|
// Update any PHI nodes in our new successors.
|
||||||
for (succ_iterator SI = succ_begin(BB1), E = succ_end(BB1); SI != E; ++SI)
|
for (BasicBlock *Succ : successors(BB1))
|
||||||
AddPredecessorToBlock(*SI, BIParent, BB1);
|
AddPredecessorToBlock(Succ, BIParent, BB1);
|
||||||
|
|
||||||
EraseTerminatorInstAndDCECond(BI);
|
EraseTerminatorInstAndDCECond(BI);
|
||||||
return true;
|
return true;
|
||||||
|
@ -2051,8 +2051,7 @@ bool llvm::FoldBranchToCommonDest(BranchInst *BI, const DataLayout *DL) {
|
||||||
if (TrueDest == BB || FalseDest == BB)
|
if (TrueDest == BB || FalseDest == BB)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
for (pred_iterator PI = pred_begin(BB), E = pred_end(BB); PI != E; ++PI) {
|
for (BasicBlock *PredBlock : predecessors(BB)) {
|
||||||
BasicBlock *PredBlock = *PI;
|
|
||||||
BranchInst *PBI = dyn_cast<BranchInst>(PredBlock->getTerminator());
|
BranchInst *PBI = dyn_cast<BranchInst>(PredBlock->getTerminator());
|
||||||
|
|
||||||
// Check that we have two conditional branches. If there is a PHI node in
|
// Check that we have two conditional branches. If there is a PHI node in
|
||||||
|
@ -2885,8 +2884,8 @@ bool SimplifyCFGOpt::SimplifyResume(ResumeInst *RI, IRBuilder<> &Builder) {
|
||||||
// Turn all invokes that unwind here into calls and delete the basic block.
|
// Turn all invokes that unwind here into calls and delete the basic block.
|
||||||
bool InvokeRequiresTableEntry = false;
|
bool InvokeRequiresTableEntry = false;
|
||||||
bool Changed = false;
|
bool Changed = false;
|
||||||
for (pred_iterator PI = pred_begin(BB), PE = pred_end(BB); PI != PE;) {
|
for (BasicBlock *Pred : predecessors(BB)) {
|
||||||
InvokeInst *II = cast<InvokeInst>((*PI++)->getTerminator());
|
InvokeInst *II = cast<InvokeInst>(Pred->getTerminator());
|
||||||
|
|
||||||
if (II->hasFnAttr(Attribute::UWTable)) {
|
if (II->hasFnAttr(Attribute::UWTable)) {
|
||||||
// Don't remove an `invoke' instruction if the ABI requires an entry into
|
// Don't remove an `invoke' instruction if the ABI requires an entry into
|
||||||
|
@ -2933,8 +2932,7 @@ bool SimplifyCFGOpt::SimplifyReturn(ReturnInst *RI, IRBuilder<> &Builder) {
|
||||||
// Find predecessors that end with branches.
|
// Find predecessors that end with branches.
|
||||||
SmallVector<BasicBlock*, 8> UncondBranchPreds;
|
SmallVector<BasicBlock*, 8> UncondBranchPreds;
|
||||||
SmallVector<BranchInst*, 8> CondBranchPreds;
|
SmallVector<BranchInst*, 8> CondBranchPreds;
|
||||||
for (pred_iterator PI = pred_begin(BB), E = pred_end(BB); PI != E; ++PI) {
|
for (BasicBlock *P : predecessors(BB)) {
|
||||||
BasicBlock *P = *PI;
|
|
||||||
TerminatorInst *PTI = P->getTerminator();
|
TerminatorInst *PTI = P->getTerminator();
|
||||||
if (BranchInst *BI = dyn_cast<BranchInst>(PTI)) {
|
if (BranchInst *BI = dyn_cast<BranchInst>(PTI)) {
|
||||||
if (BI->isUnconditional())
|
if (BI->isUnconditional())
|
||||||
|
@ -4100,8 +4098,8 @@ bool SimplifyCFGOpt::SimplifyCondBranch(BranchInst *BI, IRBuilder<> &Builder) {
|
||||||
return SimplifyCFG(BB, TTI, DL) | true;
|
return SimplifyCFG(BB, TTI, DL) | true;
|
||||||
|
|
||||||
// Scan predecessor blocks for conditional branches.
|
// Scan predecessor blocks for conditional branches.
|
||||||
for (pred_iterator PI = pred_begin(BB), E = pred_end(BB); PI != E; ++PI)
|
for (BasicBlock *Pred : predecessors(BB))
|
||||||
if (BranchInst *PBI = dyn_cast<BranchInst>((*PI)->getTerminator()))
|
if (BranchInst *PBI = dyn_cast<BranchInst>(Pred->getTerminator()))
|
||||||
if (PBI != BI && PBI->isConditional())
|
if (PBI != BI && PBI->isConditional())
|
||||||
if (SimplifyCondBranchToCondBranch(PBI, BI))
|
if (SimplifyCondBranchToCondBranch(PBI, BI))
|
||||||
return SimplifyCFG(BB, TTI, DL) | true;
|
return SimplifyCFG(BB, TTI, DL) | true;
|
||||||
|
|
|
@ -2934,9 +2934,8 @@ InnerLoopVectorizer::createBlockInMask(BasicBlock *BB) {
|
||||||
Value *Zero = ConstantInt::get(IntegerType::getInt1Ty(BB->getContext()), 0);
|
Value *Zero = ConstantInt::get(IntegerType::getInt1Ty(BB->getContext()), 0);
|
||||||
VectorParts BlockMask = getVectorValue(Zero);
|
VectorParts BlockMask = getVectorValue(Zero);
|
||||||
|
|
||||||
// For each pred:
|
for (BasicBlock *Pred : predecessors(BB)) {
|
||||||
for (pred_iterator it = pred_begin(BB), e = pred_end(BB); it != e; ++it) {
|
VectorParts EM = createEdgeMask(Pred, BB);
|
||||||
VectorParts EM = createEdgeMask(*it, BB);
|
|
||||||
for (unsigned part = 0; part < UF; ++part)
|
for (unsigned part = 0; part < UF; ++part)
|
||||||
BlockMask[part] = Builder.CreateOr(BlockMask[part], EM[part]);
|
BlockMask[part] = Builder.CreateOr(BlockMask[part], EM[part]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -292,8 +292,8 @@ bool ReduceCrashingBlocks::TestBlocks(std::vector<const BasicBlock*> &BBs) {
|
||||||
if (!Blocks.count(BB) && BB->getTerminator()->getNumSuccessors()) {
|
if (!Blocks.count(BB) && BB->getTerminator()->getNumSuccessors()) {
|
||||||
// Loop over all of the successors of this block, deleting any PHI nodes
|
// Loop over all of the successors of this block, deleting any PHI nodes
|
||||||
// that might include it.
|
// that might include it.
|
||||||
for (succ_iterator SI = succ_begin(BB), E = succ_end(BB); SI != E; ++SI)
|
for (BasicBlock *Succ : successors(BB))
|
||||||
(*SI)->removePredecessor(BB);
|
Succ->removePredecessor(BB);
|
||||||
|
|
||||||
TerminatorInst *BBTerm = BB->getTerminator();
|
TerminatorInst *BBTerm = BB->getTerminator();
|
||||||
|
|
||||||
|
|
|
@ -125,8 +125,8 @@ class FunctionDifferenceEngine {
|
||||||
|
|
||||||
unsigned getUnprocPredCount(BasicBlock *Block) const {
|
unsigned getUnprocPredCount(BasicBlock *Block) const {
|
||||||
unsigned Count = 0;
|
unsigned Count = 0;
|
||||||
for (pred_iterator I = pred_begin(Block), E = pred_end(Block); I != E; ++I)
|
for (BasicBlock *Pred : predecessors(Block))
|
||||||
if (!Blocks.count(*I)) Count++;
|
if (!Blocks.count(Pred)) Count++;
|
||||||
return Count;
|
return Count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue