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;
}
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;
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;
}
"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 {
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);
}
};
clEnumValEnd));
extern cl::opt<std::string> ViewBlockFreqFuncName;
+extern cl::opt<uint64_t> ViewHotFreqPercent;
namespace llvm {
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);
}
};