[PATCH] D126248: [BOLT][NFC] Use colors in CFG dumps

Amir Ayupov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon May 23 17:06:37 PDT 2022


Amir created this revision.
Herald added a reviewer: rafauler.
Herald added a subscriber: ayermolo.
Herald added a reviewer: maksfb.
Herald added a project: All.
Amir edited the summary of this revision.
Amir published this revision for review.
Herald added subscribers: llvm-commits, yota9.
Herald added a project: LLVM.

Use color coding to distinguish nodes:

- Entry nodes have bold border
- Scalar (non-loopy) code is milk white
- Outer loops are light yellow
- Innermost loops are light blue

`-print-loops` needs to be enabled to provide BinaryLoopInfo.
Examples:
F23170673: Screen Shot 2022-05-23 at 3.37.15 PM.png <https://reviews.llvm.org/F23170673>
F23170680: Screen Shot 2022-05-23 at 3.37.56 PM.png <https://reviews.llvm.org/F23170680>


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D126248

Files:
  bolt/lib/Core/BinaryFunction.cpp


Index: bolt/lib/Core/BinaryFunction.cpp
===================================================================
--- bolt/lib/Core/BinaryFunction.cpp
+++ bolt/lib/Core/BinaryFunction.cpp
@@ -3045,15 +3045,33 @@
 } // namespace
 
 void BinaryFunction::dumpGraph(raw_ostream &OS) const {
-  OS << "digraph \"" << getPrintName() << "\" {\n";
-  OS << R"(node [fontname="courier"])" << '\n';
+  OS << "digraph \"" << getPrintName() << "\" {\n"
+     << "node [fontname=courier, shape=box, style=filled, colorscheme=brbg9]\n";
   uint64_t Offset = Address;
   for (BinaryBasicBlock *BB : BasicBlocks) {
     auto LayoutPos =
         std::find(BasicBlocksLayout.begin(), BasicBlocksLayout.end(), BB);
     unsigned Layout = LayoutPos - BasicBlocksLayout.begin();
     const char *ColdStr = BB->isCold() ? " (cold)" : "";
-    OS << format("\"%s\" [shape=box]\n", BB->getName().data());
+    std::vector<std::string> Attrs;
+    // Bold box for entry points
+    if (isEntryPoint(*BB))
+      Attrs.push_back("penwidth=2");
+    if (BLI && BLI->getLoopFor(BB)) {
+      // Distinguish innermost loops
+      const BinaryLoop *Loop = BLI->getLoopFor(BB);
+      if (Loop->isInnermost())
+        Attrs.push_back("fillcolor=6");
+      else // some outer loop
+        Attrs.push_back("fillcolor=4");
+    } else { // non-loopy code
+      Attrs.push_back("fillcolor=5");
+    }
+    ListSeparator LS;
+    OS << "\"" << BB->getName() << "\" [";
+    for (StringRef Attr : Attrs)
+      OS << LS << Attr;
+    OS << "]\n";
     OS << format("\"%s\" [label=\"%s%s\\n(C:%lu,O:%lu,I:%u,L:%u,CFI:%u)\\n",
                  BB->getName().data(), BB->getName().data(), ColdStr,
                  BB->getKnownExecutionCount(), BB->getOffset(), getIndex(BB),


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D126248.431499.patch
Type: text/x-patch
Size: 1738 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220524/66b64a6d/attachment.bin>


More information about the llvm-commits mailing list