[BOLT][NFC] Print block instructions in dumpGraph as part of node label
authorAmir Ayupov <aaupov@fb.com>
Thu, 2 Jun 2022 06:40:55 +0000 (23:40 -0700)
committerAmir Ayupov <aaupov@fb.com>
Thu, 2 Jun 2022 06:41:41 +0000 (23:41 -0700)
Reuse the option `-dot-tooltip-code` to put block instructions into the label.
This way, the instructions are displayed by default when used with dot viewer.

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

{F23169510}

Reviewed By: rafauler

Differential Revision: https://reviews.llvm.org/D126237

bolt/lib/Core/BinaryFunction.cpp

index dabc557..9eb843d 100644 (file)
@@ -3007,28 +3007,31 @@ std::string formatEscapes(const std::string &Str) {
 } // 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.