[PATCH] D103640: Add an option to hide "cold" blocks from CFG graph

Artur Pilipenko via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 3 12:06:02 PDT 2021


apilipenko created this revision.
apilipenko added reviewers: knaumov, davidxl, wenlei, hoy.
Herald added a subscriber: hiraditya.
apilipenko requested review of this revision.
Herald added a project: LLVM.

Introduce a new cl::opt to hide "cold" blocks from CFG DOT graphs. Use BFI to get block relative frequency. Hide the block if the frequency is below the threshold set by the command line option value.

This is a generalization of the existing cfg-hide-unreachable-paths and cfg-hide-deoptimize-paths options. Just like with the existing options the main use case is performance analysis. Hiding cold blocks reduces the size of the graph by highlighting the common path.


https://reviews.llvm.org/D103640

Files:
  llvm/lib/Analysis/CFGPrinter.cpp


Index: llvm/lib/Analysis/CFGPrinter.cpp
===================================================================
--- llvm/lib/Analysis/CFGPrinter.cpp
+++ llvm/lib/Analysis/CFGPrinter.cpp
@@ -42,6 +42,10 @@
 static cl::opt<bool> HideDeoptimizePaths("cfg-hide-deoptimize-paths",
                                          cl::init(false));
 
+static cl::opt<double> HideColdPaths(
+    "cfg-hide-cold-paths", cl::init(0.0),
+    cl::desc("Hide blocks with relative frequency below the given value"));
+
 static cl::opt<bool> ShowHeatColors("cfg-heat-colors", cl::init(true),
                                     cl::Hidden,
                                     cl::desc("Show heat colors in CFG"));
@@ -296,6 +300,14 @@
 
 bool DOTGraphTraits<DOTFuncInfo *>::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())


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D103640.349621.patch
Type: text/x-patch
Size: 1384 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210603/a0fb8941/attachment.bin>


More information about the llvm-commits mailing list