NFC: Use range-based for loops and more consistent naming.

No functional changes intended.

(I plan on doing some modifications to this function and would like to
have as few unrelated changes as possible in the patch)

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@229649 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Daniel Jasper
2015-02-18 08:19:16 +00:00
parent 66bd6852bb
commit 87010b0917

View File

@ -347,29 +347,27 @@ MachineBasicBlock *MachineBlockPlacement::selectBestSuccessor(
uint32_t WeightScale = 0; uint32_t WeightScale = 0;
uint32_t SumWeight = MBPI->getSumForBlock(BB, WeightScale); uint32_t SumWeight = MBPI->getSumForBlock(BB, WeightScale);
DEBUG(dbgs() << "Attempting merge from: " << getBlockName(BB) << "\n"); DEBUG(dbgs() << "Attempting merge from: " << getBlockName(BB) << "\n");
for (MachineBasicBlock::succ_iterator SI = BB->succ_begin(), for (MachineBasicBlock *Succ : BB->successors()) {
SE = BB->succ_end(); if (BlockFilter && !BlockFilter->count(Succ))
SI != SE; ++SI) {
if (BlockFilter && !BlockFilter->count(*SI))
continue; continue;
BlockChain &SuccChain = *BlockToChain[*SI]; BlockChain &SuccChain = *BlockToChain[Succ];
if (&SuccChain == &Chain) { if (&SuccChain == &Chain) {
DEBUG(dbgs() << " " << getBlockName(*SI) << " -> Already merged!\n"); DEBUG(dbgs() << " " << getBlockName(Succ) << " -> Already merged!\n");
continue; continue;
} }
if (*SI != *SuccChain.begin()) { if (Succ != *SuccChain.begin()) {
DEBUG(dbgs() << " " << getBlockName(*SI) << " -> Mid chain!\n"); DEBUG(dbgs() << " " << getBlockName(Succ) << " -> Mid chain!\n");
continue; continue;
} }
uint32_t SuccWeight = MBPI->getEdgeWeight(BB, *SI); uint32_t SuccWeight = MBPI->getEdgeWeight(BB, Succ);
BranchProbability SuccProb(SuccWeight / WeightScale, SumWeight); BranchProbability SuccProb(SuccWeight / WeightScale, SumWeight);
// Only consider successors which are either "hot", or wouldn't violate // Only consider successors which are either "hot", or wouldn't violate
// any CFG constraints. // any CFG constraints.
if (SuccChain.LoopPredecessors != 0) { if (SuccChain.LoopPredecessors != 0) {
if (SuccProb < HotProb) { if (SuccProb < HotProb) {
DEBUG(dbgs() << " " << getBlockName(*SI) << " -> " << SuccProb DEBUG(dbgs() << " " << getBlockName(Succ) << " -> " << SuccProb
<< " (prob) (CFG conflict)\n"); << " (prob) (CFG conflict)\n");
continue; continue;
} }
@ -379,33 +377,31 @@ MachineBasicBlock *MachineBlockPlacement::selectBestSuccessor(
BlockFrequency CandidateEdgeFreq = BlockFrequency CandidateEdgeFreq =
MBFI->getBlockFreq(BB) * SuccProb * HotProb.getCompl(); MBFI->getBlockFreq(BB) * SuccProb * HotProb.getCompl();
bool BadCFGConflict = false; bool BadCFGConflict = false;
for (MachineBasicBlock::pred_iterator PI = (*SI)->pred_begin(), for (MachineBasicBlock *Pred : Succ->predecessors()) {
PE = (*SI)->pred_end(); if (Pred == Succ || (BlockFilter && !BlockFilter->count(Pred)) ||
PI != PE; ++PI) { BlockToChain[Pred] == &Chain)
if (*PI == *SI || (BlockFilter && !BlockFilter->count(*PI)) ||
BlockToChain[*PI] == &Chain)
continue; continue;
BlockFrequency PredEdgeFreq = BlockFrequency PredEdgeFreq =
MBFI->getBlockFreq(*PI) * MBPI->getEdgeProbability(*PI, *SI); MBFI->getBlockFreq(Pred) * MBPI->getEdgeProbability(Pred, Succ);
if (PredEdgeFreq >= CandidateEdgeFreq) { if (PredEdgeFreq >= CandidateEdgeFreq) {
BadCFGConflict = true; BadCFGConflict = true;
break; break;
} }
} }
if (BadCFGConflict) { if (BadCFGConflict) {
DEBUG(dbgs() << " " << getBlockName(*SI) << " -> " << SuccProb DEBUG(dbgs() << " " << getBlockName(Succ) << " -> " << SuccProb
<< " (prob) (non-cold CFG conflict)\n"); << " (prob) (non-cold CFG conflict)\n");
continue; continue;
} }
} }
DEBUG(dbgs() << " " << getBlockName(*SI) << " -> " << SuccProb DEBUG(dbgs() << " " << getBlockName(Succ) << " -> " << SuccProb
<< " (prob)" << " (prob)"
<< (SuccChain.LoopPredecessors != 0 ? " (CFG break)" : "") << (SuccChain.LoopPredecessors != 0 ? " (CFG break)" : "")
<< "\n"); << "\n");
if (BestSucc && BestWeight >= SuccWeight) if (BestSucc && BestWeight >= SuccWeight)
continue; continue;
BestSucc = *SI; BestSucc = Succ;
BestWeight = SuccWeight; BestWeight = SuccWeight;
} }
return BestSucc; return BestSucc;