[BFI]: code cleanup

Expose getBPI interface from BFI impl and use
it in graph viewer. This eliminates the dependency
on old PM interface.

llvm-svn: 273967
This commit is contained in:
Xinliang David Li 2016-06-28 00:15:45 +00:00
parent 0f684b0d04
commit 3264fdd3ca
3 changed files with 12 additions and 4 deletions

View File

@ -927,6 +927,8 @@ public:
return BlockFrequencyInfoImplBase::getFloatingBlockFreq(getNode(BB));
}
const BranchProbabilityInfoT &getBPI() const { return *BPI; }
/// \brief Print the frequencies for the current function.
///
/// Prints the frequencies for the blocks in the current function.

View File

@ -54,6 +54,7 @@ public:
Optional<uint64_t> getBlockProfileCount(const MachineBasicBlock *MBB) const;
const MachineFunction *getFunction() const;
const MachineBranchProbabilityInfo *getMBPI() const;
void view() const;
// Print the block frequency Freq to OS using the current functions entry

View File

@ -120,13 +120,14 @@ struct DOTGraphTraits<MachineBlockFrequencyInfo *>
static std::string getEdgeAttributes(const MachineBasicBlock *Node,
EdgeIter EI,
const MachineBlockFrequencyInfo *MBFI) {
MachineBranchProbabilityInfo &MBPI =
MBFI->getAnalysis<MachineBranchProbabilityInfo>();
BranchProbability BP = MBPI.getEdgeProbability(Node, EI);
std::string Str;
const MachineBranchProbabilityInfo *MBPI = MBFI->getMBPI();
if (!MBPI)
return Str;
BranchProbability BP = MBPI->getEdgeProbability(Node, EI);
uint32_t N = BP.getNumerator();
uint32_t D = BP.getDenominator();
double Percent = 100.0 * N / D;
std::string Str;
raw_string_ostream OS(Str);
OS << format("label=\"%.1f%%\"", Percent);
OS.flush();
@ -207,6 +208,10 @@ const MachineFunction *MachineBlockFrequencyInfo::getFunction() const {
return MBFI ? MBFI->getFunction() : nullptr;
}
const MachineBranchProbabilityInfo *MachineBlockFrequencyInfo::getMBPI() const {
return MBFI ? &MBFI->getBPI() : nullptr;
}
raw_ostream &
MachineBlockFrequencyInfo::printBlockFreq(raw_ostream &OS,
const BlockFrequency Freq) const {