forked from OSchip/llvm-project
Now that we have comparison on probabilities, add some static functions
to get important constant branch probabilities and use them for finding the best branch out of a set of possibilities. llvm-svn: 142762
This commit is contained in:
parent
446210b616
commit
fd7475e906
|
@ -39,6 +39,9 @@ public:
|
||||||
assert(n <= d && "Probability cannot be bigger than 1!");
|
assert(n <= d && "Probability cannot be bigger than 1!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static BranchProbability getZero() { return BranchProbability(0, 1); }
|
||||||
|
static BranchProbability getOne() { return BranchProbability(1, 1); }
|
||||||
|
|
||||||
uint32_t getNumerator() const { return N; }
|
uint32_t getNumerator() const { return N; }
|
||||||
uint32_t getDenominator() const { return D; }
|
uint32_t getDenominator() const { return D; }
|
||||||
|
|
||||||
|
|
|
@ -287,10 +287,8 @@ void MachineBlockPlacement::mergeSuccessor(MachineBasicBlock *BB,
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Walk through the successors looking for the highest probability edge.
|
// Walk through the successors looking for the highest probability edge.
|
||||||
// FIXME: This is an annoying way to do the comparison, but it's correct.
|
|
||||||
// Support should be added to BranchProbability to properly compare two.
|
|
||||||
MachineBasicBlock *Successor = 0;
|
MachineBasicBlock *Successor = 0;
|
||||||
BlockFrequency BestFreq;
|
BranchProbability BestProb = BranchProbability::getZero();
|
||||||
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_iterator SI = BB->succ_begin(),
|
||||||
SE = BB->succ_end();
|
SE = BB->succ_end();
|
||||||
|
@ -298,13 +296,12 @@ void MachineBlockPlacement::mergeSuccessor(MachineBasicBlock *BB,
|
||||||
if (BB == *SI || (Filter && !Filter->count(*SI)))
|
if (BB == *SI || (Filter && !Filter->count(*SI)))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
BlockFrequency SuccFreq(BlockFrequency::getEntryFrequency());
|
BranchProbability SuccProb = MBPI->getEdgeProbability(BB, *SI);
|
||||||
SuccFreq *= MBPI->getEdgeProbability(BB, *SI);
|
DEBUG(dbgs() << " " << getBlockName(*SI) << " -> " << SuccProb << "\n");
|
||||||
DEBUG(dbgs() << " " << getBlockName(*SI) << " -> " << SuccFreq << "\n");
|
if (!Successor || SuccProb > BestProb || (!(SuccProb < BestProb) &&
|
||||||
if (!Successor || SuccFreq > BestFreq || (!(SuccFreq < BestFreq) &&
|
|
||||||
BB->isLayoutSuccessor(*SI))) {
|
BB->isLayoutSuccessor(*SI))) {
|
||||||
Successor = *SI;
|
Successor = *SI;
|
||||||
BestFreq = SuccFreq;
|
BestProb = SuccProb;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!Successor)
|
if (!Successor)
|
||||||
|
|
Loading…
Reference in New Issue