diff --git a/llvm/lib/Analysis/CFGPrinter.cpp b/llvm/lib/Analysis/CFGPrinter.cpp --- a/llvm/lib/Analysis/CFGPrinter.cpp +++ b/llvm/lib/Analysis/CFGPrinter.cpp @@ -42,6 +42,10 @@ static cl::opt HideDeoptimizePaths("cfg-hide-deoptimize-paths", cl::init(false)); +static cl::opt HideColdPaths( + "cfg-hide-cold-paths", cl::init(0.0), + cl::desc("Hide blocks with relative frequency below the given value")); + static cl::opt ShowHeatColors("cfg-heat-colors", cl::init(true), cl::Hidden, cl::desc("Show heat colors in CFG")); @@ -296,6 +300,14 @@ bool DOTGraphTraits::isNodeHidden(const BasicBlock *Node, const DOTFuncInfo *CFGInfo) { + if (HideColdPaths.getNumOccurrences() > 0) + if (auto *BFI = CFGInfo->getBFI()) { + uint64_t NodeFreq = BFI->getBlockFreq(Node).getFrequency(); + uint64_t EntryFreq = BFI->getEntryFreq(); + // Hide blocks with relative frequency below HideColdPaths threshold. + if ((double)NodeFreq / EntryFreq < HideColdPaths) + return true; + } if (HideUnreachablePaths || HideDeoptimizePaths) { if (isOnDeoptOrUnreachablePath.find(Node) == isOnDeoptOrUnreachablePath.end())