[PATCH] D126237: [BOLT][NFC] Print block instructions in dumpGraph as part of node label

Amir Ayupov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon May 23 13:16:05 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.

Reuse the option `-dot-tooltip-code` to put block instructions into the label.
This way, the instruction are displayed by default when used with dot viewer.

When the produced .dot file is used with dot2html, instructions are hidden
by default, and are expanded by clicking on a node.

F23169510: Screen Shot 2022-05-23 at 1.14.07 PM.png <https://reviews.llvm.org/F23169510>


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D126237

Files:
  bolt/lib/Core/BinaryFunction.cpp


Index: bolt/lib/Core/BinaryFunction.cpp
===================================================================
--- bolt/lib/Core/BinaryFunction.cpp
+++ bolt/lib/Core/BinaryFunction.cpp
@@ -3055,28 +3055,31 @@
 } // namespace
 
 void BinaryFunction::dumpGraph(raw_ostream &OS) const {
-  OS << "strict digraph \"" << getPrintName() << "\" {\n";
+  OS << "digraph \"" << getPrintName() << "\" {\n";
+  OS << R"(node [fontname="courier"])" << '\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\" [label=\"%s%s\\n(C:%lu,O:%lu,I:%u,L:%u:CFI:%u)\"]\n",
-                 BB->getName().data(), BB->getName().data(), ColdStr,
-                 (BB->ExecutionCount != BinaryBasicBlock::COUNT_NO_PROFILE
-                      ? BB->ExecutionCount
-                      : 0),
-                 BB->getOffset(), getIndex(BB), Layout, BB->getCFIState());
     OS << format("\"%s\" [shape=box]\n", BB->getName().data());
+    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),
+                 Layout, BB->getCFIState());
+
     if (opts::DotToolTipCode) {
       std::string Str;
       raw_string_ostream CS(Str);
-      Offset = BC.printInstructions(CS, BB->begin(), BB->end(), Offset, this);
-      const std::string Code = formatEscapes(CS.str());
-      OS << format("\"%s\" [tooltip=\"%s\"]\n", BB->getName().data(),
-                   Code.c_str());
+      Offset = BC.printInstructions(CS, BB->begin(), BB->end(), Offset, this,
+                                    /* PrintMCInst = */ false,
+                                    /* PrintMemData = */ false,
+                                    /* PrintRelocations = */ false,
+                                    /* Endl = */ R"(\\l)");
+      OS << formatEscapes(CS.str()) << '\n';
     }
+    OS << "\"]\n";
 
     // analyzeBranch is just used to get the names of the branch
     // opcodes.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D126237.431465.patch
Type: text/x-patch
Size: 2286 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220523/d41ec2ae/attachment.bin>


More information about the llvm-commits mailing list