diff options
| author | Xinliang David Li <davidxl@google.com> | 2016-06-28 06:58:21 +0000 |
|---|---|---|
| committer | Xinliang David Li <davidxl@google.com> | 2016-06-28 06:58:21 +0000 |
| commit | 3e176c77ab593e2edf659e7318cb41319cae10ff (patch) | |
| tree | 91c850fd5ff9444e40fa13d0f76d85f3fc5f1762 | |
| parent | a727f3cfde91553113ee33f7fea6f8c4299d2919 (diff) | |
| download | bcm5719-llvm-3e176c77ab593e2edf659e7318cb41319cae10ff.tar.gz bcm5719-llvm-3e176c77ab593e2edf659e7318cb41319cae10ff.zip | |
[BFI/MBFI]: cfg graph view with color scheme
This patch enhances dot graph viewer to show hot regions
with hot bbs/edges displayed in red. The ratio of the bb
freq to the max freq of the function needs to be no less
than the value specified by view-hot-freq-percent option.
The default value is 10 (i.e. 10%).
llvm-svn: 273996
| -rw-r--r-- | llvm/include/llvm/Analysis/BlockFrequencyInfoImpl.h | 47 | ||||
| -rw-r--r-- | llvm/lib/Analysis/BlockFrequencyInfo.cpp | 23 | ||||
| -rw-r--r-- | llvm/lib/CodeGen/MachineBlockFrequencyInfo.cpp | 10 |
3 files changed, 76 insertions, 4 deletions
diff --git a/llvm/include/llvm/Analysis/BlockFrequencyInfoImpl.h b/llvm/include/llvm/Analysis/BlockFrequencyInfoImpl.h index de310241137..7ed06b1bb68 100644 --- a/llvm/include/llvm/Analysis/BlockFrequencyInfoImpl.h +++ b/llvm/include/llvm/Analysis/BlockFrequencyInfoImpl.h @@ -1249,10 +1249,42 @@ struct BFIDOTGraphTraitsBase : public DefaultDOTGraphTraits { typedef typename GTraits::ChildIteratorType EdgeIter; typedef typename GTraits::nodes_iterator NodeIter; + uint64_t MaxFrequency = 0; static std::string getGraphName(const BlockFrequencyInfoT *G) { return G->getFunction()->getName(); } + std::string getNodeAttributes(const NodeType *Node, + const BlockFrequencyInfoT *Graph, + unsigned HotPercentThreshold = 0) { + std::string Result; + if (!HotPercentThreshold) + return Result; + + // Compute MaxFrequency on the fly: + if (!MaxFrequency) { + for (NodeIter I = GTraits::nodes_begin(Graph), + E = GTraits::nodes_end(Graph); + I != E; ++I) { + NodeType &N = *I; + MaxFrequency = + std::max(MaxFrequency, Graph->getBlockFreq(&N).getFrequency()); + } + } + BlockFrequency Freq = Graph->getBlockFreq(Node); + BlockFrequency HotFreq = + (BlockFrequency(MaxFrequency) * + BranchProbability::getBranchProbability(HotPercentThreshold, 100)); + + if (Freq < HotFreq) + return Result; + + raw_string_ostream OS(Result); + OS << "color=\"red\""; + OS.flush(); + return Result; + } + std::string getNodeLabel(const NodeType *Node, const BlockFrequencyInfoT *Graph, GVDAGType GType) { std::string Result; @@ -1282,7 +1314,9 @@ struct BFIDOTGraphTraitsBase : public DefaultDOTGraphTraits { } std::string getEdgeAttributes(const NodeType *Node, EdgeIter EI, - const BranchProbabilityInfoT *BPI) { + const BlockFrequencyInfoT *BFI, + const BranchProbabilityInfoT *BPI, + unsigned HotPercentThreshold = 0) { std::string Str; if (!BPI) return Str; @@ -1293,6 +1327,17 @@ struct BFIDOTGraphTraitsBase : public DefaultDOTGraphTraits { double Percent = 100.0 * N / D; raw_string_ostream OS(Str); OS << format("label=\"%.1f%%\"", Percent); + + if (HotPercentThreshold) { + BlockFrequency EFreq = BFI->getBlockFreq(Node) * BP; + BlockFrequency HotFreq = BlockFrequency(MaxFrequency) * + BranchProbability(HotPercentThreshold, 100); + + if (EFreq >= HotFreq) { + OS << ",color=\"red\""; + } + } + OS.flush(); return Str; } diff --git a/llvm/lib/Analysis/BlockFrequencyInfo.cpp b/llvm/lib/Analysis/BlockFrequencyInfo.cpp index f470d3c6a8b..de1c8553c93 100644 --- a/llvm/lib/Analysis/BlockFrequencyInfo.cpp +++ b/llvm/lib/Analysis/BlockFrequencyInfo.cpp @@ -42,7 +42,19 @@ static cl::opt<GVDAGType> ViewBlockFreqPropagationDAG( "profile count if available."), clEnumValEnd)); -cl::opt<std::string> ViewBlockFreqFuncName("view-bfi-func-name", cl::Hidden); +cl::opt<std::string> + ViewBlockFreqFuncName("view-bfi-func-name", cl::Hidden, + cl::desc("The option to specify " + "the name of the function " + "whose CFG will be displayed.")); + +cl::opt<unsigned> + ViewHotFreqPercent("view-hot-freq-percent", cl::init(10), cl::Hidden, + cl::desc("An integer in percent used to specify " + "the hot blocks/edges to be displayed " + "in red: a block or edge whose frequency " + "is no less than the max frequency of the " + "function multiplied by this percent.")); namespace llvm { @@ -84,9 +96,16 @@ struct DOTGraphTraits<BlockFrequencyInfo *> : public BFIDOTGTraitsBase { ViewBlockFreqPropagationDAG); } + std::string getNodeAttributes(const BasicBlock *Node, + const BlockFrequencyInfo *Graph) { + return BFIDOTGTraitsBase::getNodeAttributes(Node, Graph, + ViewHotFreqPercent); + } + std::string getEdgeAttributes(const BasicBlock *Node, EdgeIter EI, const BlockFrequencyInfo *BFI) { - return BFIDOTGTraitsBase::getEdgeAttributes(Node, EI, BFI->getBPI()); + return BFIDOTGTraitsBase::getEdgeAttributes(Node, EI, BFI, BFI->getBPI(), + ViewHotFreqPercent); } }; diff --git a/llvm/lib/CodeGen/MachineBlockFrequencyInfo.cpp b/llvm/lib/CodeGen/MachineBlockFrequencyInfo.cpp index 7e05ebe2848..4353ec4546a 100644 --- a/llvm/lib/CodeGen/MachineBlockFrequencyInfo.cpp +++ b/llvm/lib/CodeGen/MachineBlockFrequencyInfo.cpp @@ -47,6 +47,7 @@ static cl::opt<GVDAGType> ViewMachineBlockFreqPropagationDAG( clEnumValEnd)); extern cl::opt<std::string> ViewBlockFreqFuncName; +extern cl::opt<uint64_t> ViewHotFreqPercent; namespace llvm { @@ -92,9 +93,16 @@ struct DOTGraphTraits<MachineBlockFrequencyInfo *> Node, Graph, ViewMachineBlockFreqPropagationDAG); } + std::string getNodeAttributes(const MachineBasicBlock *Node, + const MachineBlockFrequencyInfo *Graph) { + return MBFIDOTGraphTraitsBase::getNodeAttributes(Node, Graph, + ViewHotFreqPercent); + } + std::string getEdgeAttributes(const MachineBasicBlock *Node, EdgeIter EI, const MachineBlockFrequencyInfo *MBFI) { - return MBFIDOTGraphTraitsBase::getEdgeAttributes(Node, EI, MBFI->getMBPI()); + return MBFIDOTGraphTraitsBase::getEdgeAttributes( + Node, EI, MBFI, MBFI->getMBPI(), ViewHotFreqPercent); } }; |

