summaryrefslogtreecommitdiffstats
path: root/llvm/lib/CodeGen/MachineBlockFrequencyInfo.cpp
diff options
context:
space:
mode:
authorXinliang David Li <davidxl@google.com>2016-06-28 03:41:29 +0000
committerXinliang David Li <davidxl@google.com>2016-06-28 03:41:29 +0000
commit55415f2565b9fd1c1033a9f0ad5551b39b3a9045 (patch)
tree0312a9c0c447f04c1c487fd4f0b3b17444438f5c /llvm/lib/CodeGen/MachineBlockFrequencyInfo.cpp
parent4fdc6485923c0624a56f75b164cbcbc70d84d566 (diff)
downloadbcm5719-llvm-55415f2565b9fd1c1033a9f0ad5551b39b3a9045.tar.gz
bcm5719-llvm-55415f2565b9fd1c1033a9f0ad5551b39b3a9045.zip
[BFI]: graph viewer code refactoring
BFI and MBFI's dot traits class share most of the code and all future enhancement. This patch extracts common implementation into base class BFIDOTGraphTraitsBase. This patch also enables BFI graph to show branch probability on edges as MBFI does before. llvm-svn: 273990
Diffstat (limited to 'llvm/lib/CodeGen/MachineBlockFrequencyInfo.cpp')
-rw-r--r--llvm/lib/CodeGen/MachineBlockFrequencyInfo.cpp58
1 files changed, 11 insertions, 47 deletions
diff --git a/llvm/lib/CodeGen/MachineBlockFrequencyInfo.cpp b/llvm/lib/CodeGen/MachineBlockFrequencyInfo.cpp
index e994aec4e1e..f02356b92c5 100644
--- a/llvm/lib/CodeGen/MachineBlockFrequencyInfo.cpp
+++ b/llvm/lib/CodeGen/MachineBlockFrequencyInfo.cpp
@@ -29,7 +29,6 @@ using namespace llvm;
#define DEBUG_TYPE "block-freq"
#ifndef NDEBUG
-enum GVDAGType { GVDT_None, GVDT_Fraction, GVDT_Integer, GVDT_Count };
static cl::opt<GVDAGType> ViewMachineBlockFreqPropagationDAG(
"view-machine-block-freq-propagation-dags", cl::Hidden,
@@ -79,59 +78,24 @@ template <> struct GraphTraits<MachineBlockFrequencyInfo *> {
}
};
+typedef BFIDOTGraphTraitsBase<MachineBlockFrequencyInfo,
+ MachineBranchProbabilityInfo>
+ MBFIDOTGraphTraitsBase;
template <>
struct DOTGraphTraits<MachineBlockFrequencyInfo *>
- : public DefaultDOTGraphTraits {
+ : public MBFIDOTGraphTraitsBase {
explicit DOTGraphTraits(bool isSimple = false)
- : DefaultDOTGraphTraits(isSimple) {}
-
- typedef MachineBasicBlock::const_succ_iterator EdgeIter;
- static std::string getGraphName(const MachineBlockFrequencyInfo *G) {
- return G->getFunction()->getName();
- }
+ : MBFIDOTGraphTraitsBase(isSimple) {}
std::string getNodeLabel(const MachineBasicBlock *Node,
const MachineBlockFrequencyInfo *Graph) {
- std::string Result;
- raw_string_ostream OS(Result);
-
- OS << Node->getName().str() << " : ";
- switch (ViewMachineBlockFreqPropagationDAG) {
- case GVDT_Fraction:
- Graph->printBlockFreq(OS, Node);
- break;
- case GVDT_Integer:
- OS << Graph->getBlockFreq(Node).getFrequency();
- break;
- case GVDT_Count: {
- auto Count = Graph->getBlockProfileCount(Node);
- if (Count)
- OS << Count.getValue();
- else
- OS << "Unknown";
- break;
- }
- case GVDT_None:
- llvm_unreachable("If we are not supposed to render a graph we should "
- "never reach this point.");
- }
- return Result;
+ return MBFIDOTGraphTraitsBase::getNodeLabel(
+ Node, Graph, ViewMachineBlockFreqPropagationDAG);
}
- static std::string getEdgeAttributes(const MachineBasicBlock *Node,
- EdgeIter EI,
- const MachineBlockFrequencyInfo *MBFI) {
- 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;
- raw_string_ostream OS(Str);
- OS << format("label=\"%.1f%%\"", Percent);
- OS.flush();
- return Str;
+
+ std::string getEdgeAttributes(const MachineBasicBlock *Node, EdgeIter EI,
+ const MachineBlockFrequencyInfo *MBFI) {
+ return MBFIDOTGraphTraitsBase::getEdgeAttributes(Node, EI, MBFI->getMBPI());
}
};
OpenPOWER on IntegriCloud