From 6333e5dde9872ae56d7979432a76f83cf7ac6820 Mon Sep 17 00:00:00 2001 From: Amir Ayupov Date: Thu, 2 Jun 2022 00:26:23 -0700 Subject: [PATCH] [BOLT][NFC] Use colors in CFG dumps 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} {F23170680} Reviewed By: rafauler Differential Revision: https://reviews.llvm.org/D126248 --- bolt/lib/Core/BinaryFunction.cpp | 24 +++++++++++++++++++++--- bolt/lib/Rewrite/RewriteInstance.cpp | 11 +++++------ 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/bolt/lib/Core/BinaryFunction.cpp b/bolt/lib/Core/BinaryFunction.cpp index 9eb843d4447e..671836c5cb44 100644 --- a/bolt/lib/Core/BinaryFunction.cpp +++ b/bolt/lib/Core/BinaryFunction.cpp @@ -3007,15 +3007,33 @@ std::string formatEscapes(const std::string &Str) { } // 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 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), diff --git a/bolt/lib/Rewrite/RewriteInstance.cpp b/bolt/lib/Rewrite/RewriteInstance.cpp index d5dc49997f88..d19dc67c7694 100644 --- a/bolt/lib/Rewrite/RewriteInstance.cpp +++ b/bolt/lib/Rewrite/RewriteInstance.cpp @@ -101,12 +101,11 @@ AllowStripped("allow-stripped", cl::Hidden, cl::cat(BoltCategory)); -cl::opt -DumpDotAll("dump-dot-all", - cl::desc("dump function CFGs to graphviz format after each stage"), - cl::ZeroOrMore, - cl::Hidden, - cl::cat(BoltCategory)); +cl::opt DumpDotAll( + "dump-dot-all", + cl::desc("dump function CFGs to graphviz format after each stage;" + "enable '-print-loops' for color-coded blocks"), + cl::ZeroOrMore, cl::Hidden, cl::cat(BoltCategory)); static cl::list ForceFunctionNames("funcs",