From 3264fdd3caa0acf19c91a4eb0d09a282cc788bbd Mon Sep 17 00:00:00 2001 From: Xinliang David Li Date: Tue, 28 Jun 2016 00:15:45 +0000 Subject: [PATCH] [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 --- llvm/include/llvm/Analysis/BlockFrequencyInfoImpl.h | 2 ++ .../llvm/CodeGen/MachineBlockFrequencyInfo.h | 1 + llvm/lib/CodeGen/MachineBlockFrequencyInfo.cpp | 13 +++++++++---- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/llvm/include/llvm/Analysis/BlockFrequencyInfoImpl.h b/llvm/include/llvm/Analysis/BlockFrequencyInfoImpl.h index 34739360a65c..6315e7efb7df 100644 --- a/llvm/include/llvm/Analysis/BlockFrequencyInfoImpl.h +++ b/llvm/include/llvm/Analysis/BlockFrequencyInfoImpl.h @@ -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. diff --git a/llvm/include/llvm/CodeGen/MachineBlockFrequencyInfo.h b/llvm/include/llvm/CodeGen/MachineBlockFrequencyInfo.h index 4a881ee354af..7a236086ed09 100644 --- a/llvm/include/llvm/CodeGen/MachineBlockFrequencyInfo.h +++ b/llvm/include/llvm/CodeGen/MachineBlockFrequencyInfo.h @@ -54,6 +54,7 @@ public: Optional 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 diff --git a/llvm/lib/CodeGen/MachineBlockFrequencyInfo.cpp b/llvm/lib/CodeGen/MachineBlockFrequencyInfo.cpp index 689deb8c370d..e994aec4e1ef 100644 --- a/llvm/lib/CodeGen/MachineBlockFrequencyInfo.cpp +++ b/llvm/lib/CodeGen/MachineBlockFrequencyInfo.cpp @@ -120,13 +120,14 @@ struct DOTGraphTraits static std::string getEdgeAttributes(const MachineBasicBlock *Node, EdgeIter EI, const MachineBlockFrequencyInfo *MBFI) { - MachineBranchProbabilityInfo &MBPI = - MBFI->getAnalysis(); - 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 {