From: Xinliang David Li Date: Wed, 22 Jun 2016 16:04:51 +0000 (+0000) Subject: [MBFI]: show branch probability in DOT graph X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=27717d0f19449e44b8cf21402552aa891a546d43;p=llvm [MBFI]: show branch probability in DOT graph Differential Revision: http://reviews.llvm.org/D21596 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@273430 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/MachineBlockFrequencyInfo.cpp b/lib/CodeGen/MachineBlockFrequencyInfo.cpp index 884313673ba..f83e7ff2fbf 100644 --- a/lib/CodeGen/MachineBlockFrequencyInfo.cpp +++ b/lib/CodeGen/MachineBlockFrequencyInfo.cpp @@ -20,7 +20,9 @@ #include "llvm/InitializePasses.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/Debug.h" +#include "llvm/Support/Format.h" #include "llvm/Support/GraphWriter.h" +#include "llvm/Support/raw_ostream.h" using namespace llvm; @@ -80,6 +82,7 @@ struct DOTGraphTraits explicit DOTGraphTraits(bool isSimple = false) : DefaultDOTGraphTraits(isSimple) {} + typedef MachineBasicBlock::const_succ_iterator EdgeIter; static std::string getGraphName(const MachineBlockFrequencyInfo *G) { return G->getFunction()->getName(); } @@ -104,6 +107,21 @@ struct DOTGraphTraits return Result; } + static std::string getEdgeAttributes(const MachineBasicBlock *Node, + EdgeIter EI, + const MachineBlockFrequencyInfo *MBFI) { + MachineBranchProbabilityInfo &MBPI = + MBFI->getAnalysis(); + 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(); + return Str; + } }; } // end namespace llvm