[llvm] 9197bac - Add an option to hide "cold" blocks from CFG graph

Artur Pilipenko via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 8 11:29:43 PDT 2021


Author: Artur Pilipenko
Date: 2021-06-08T11:29:27-07:00
New Revision: 9197bac297f73552882820ba25d245115e29e7af

URL: https://github.com/llvm/llvm-project/commit/9197bac297f73552882820ba25d245115e29e7af
DIFF: https://github.com/llvm/llvm-project/commit/9197bac297f73552882820ba25d245115e29e7af.diff

LOG: Add an option to hide "cold" blocks from CFG graph

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.

Reviewed By: davidxl, hoy
Differential Revision: https://reviews.llvm.org/D103640

Added: 
    

Modified: 
    llvm/lib/Analysis/CFGPrinter.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Analysis/CFGPrinter.cpp b/llvm/lib/Analysis/CFGPrinter.cpp
index f9fb584a6141..76f9f7783863 100644
--- a/llvm/lib/Analysis/CFGPrinter.cpp
+++ b/llvm/lib/Analysis/CFGPrinter.cpp
@@ -42,6 +42,10 @@ static cl::opt<bool> HideUnreachablePaths("cfg-hide-unreachable-paths",
 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 @@ void DOTGraphTraits<DOTFuncInfo *>::computeDeoptOrUnreachablePaths(
 
 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())


        


More information about the llvm-commits mailing list