Add BlockFrequency::getEntryFrequency()

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@136618 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Jakub Staszak 2011-08-01 15:22:10 +00:00
parent 5cd8ea2fd3
commit e2481ff8ee
2 changed files with 11 additions and 7 deletions

View File

@ -49,7 +49,7 @@ class BlockFrequencyImpl {
typedef GraphTraits< Inverse<BlockT *> > GT;
static const uint32_t START_FREQ = 1024;
const uint32_t EntryFreq;
std::string getBlockName(BasicBlock *BB) const {
return BB->getNameStr();
@ -176,7 +176,7 @@ class BlockFrequencyImpl {
setBlockFreq(BB, 0);
if (BB == LoopHead) {
setBlockFreq(BB, START_FREQ);
setBlockFreq(BB, EntryFreq);
return;
}
@ -211,10 +211,10 @@ class BlockFrequencyImpl {
if (!isLoopHead)
return;
assert(START_FREQ >= CycleProb[BB]);
assert(EntryFreq >= CycleProb[BB]);
uint32_t CProb = CycleProb[BB];
uint32_t Numerator = START_FREQ - CProb ? START_FREQ - CProb : 1;
divBlockFreq(BB, BranchProbability(Numerator, START_FREQ));
uint32_t Numerator = EntryFreq - CProb ? EntryFreq - CProb : 1;
divBlockFreq(BB, BranchProbability(Numerator, EntryFreq));
}
/// doLoop - Propagate block frequency down throught the loop.
@ -243,8 +243,8 @@ class BlockFrequencyImpl {
if (isReachable(Pred) && isBackedge(Pred, Head)) {
uint64_t N = getEdgeFreq(Pred, Head).getFrequency();
uint64_t D = getBlockFreq(Head).getFrequency();
assert(N <= 1024 && "Backedge frequency must be <= 1024!");
uint64_t Res = (N * START_FREQ) / D;
assert(N <= EntryFreq && "Backedge frequency must be <= EntryFreq!");
uint64_t Res = (N * EntryFreq) / D;
assert(Res <= UINT32_MAX);
CycleProb[Head] += (uint32_t) Res;
@ -257,6 +257,8 @@ class BlockFrequencyImpl {
friend class BlockFrequencyInfo;
friend class MachineBlockFrequencyInfo;
BlockFrequencyImpl() : EntryFreq(BlockFrequency::getEntryFrequency()) { }
void doFunction(FunctionT *fn, BlockProbInfoT *bpi) {
Fn = fn;
BPI = bpi;

View File

@ -23,10 +23,12 @@ class BranchProbability;
class BlockFrequency {
uint64_t Frequency;
static const int64_t ENTRY_FREQ = 1024;
public:
BlockFrequency(uint64_t Freq = 0) : Frequency(Freq) { }
static uint64_t getEntryFrequency() { return ENTRY_FREQ; }
uint64_t getFrequency() const { return Frequency; }
BlockFrequency &operator*=(const BranchProbability &Prob);