From 1109d3ca85b69f399375c3e18f7392218503a0b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Catal=C3=A3o?= Date: Sat, 12 Jul 2025 23:40:27 +0100 Subject: [PATCH] [CFGPrinter] Added command line option to change DOT font This patch introduces the ability to change the fontname used in the DOT graphs of the view-cfg and dot-cfg passes. --- llvm/include/llvm/Analysis/CFGPrinter.h | 12 ++++++++++-- llvm/lib/Analysis/CFGPrinter.cpp | 5 +++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/llvm/include/llvm/Analysis/CFGPrinter.h b/llvm/include/llvm/Analysis/CFGPrinter.h index ec26da87eb916..8955ada815ed0 100644 --- a/llvm/include/llvm/Analysis/CFGPrinter.h +++ b/llvm/include/llvm/Analysis/CFGPrinter.h @@ -27,11 +27,14 @@ #include "llvm/IR/Instructions.h" #include "llvm/IR/PassManager.h" #include "llvm/IR/ProfDataUtils.h" +#include "llvm/Support/CommandLine.h" #include "llvm/Support/Compiler.h" #include "llvm/Support/DOTGraphTraits.h" #include "llvm/Support/FormatVariadic.h" namespace llvm { +LLVM_ABI extern cl::opt CFGFontName; + class ModuleSlotTracker; template struct GraphTraits; @@ -321,9 +324,14 @@ struct DOTGraphTraits : public DefaultDOTGraphTraits { ? (getHeatColor(0)) : (getHeatColor(1)); + std::string FontName = "Courier"; + if (!CFGFontName.empty()) { + FontName = CFGFontName; + } + std::string Attrs = "color=\"" + EdgeColor + "ff\", style=filled," + - " fillcolor=\"" + Color + "70\"" + - " fontname=\"Courier\""; + " fillcolor=\"" + Color + "70\"" + " fontname=\"" + + FontName + "\""; return Attrs; } LLVM_ABI bool isNodeHidden(const BasicBlock *Node, diff --git a/llvm/lib/Analysis/CFGPrinter.cpp b/llvm/lib/Analysis/CFGPrinter.cpp index 38aad849755be..d7f411ddbf9a4 100644 --- a/llvm/lib/Analysis/CFGPrinter.cpp +++ b/llvm/lib/Analysis/CFGPrinter.cpp @@ -26,6 +26,11 @@ using namespace llvm; +cl::opt + llvm::CFGFontName("cfg-fontname", cl::Hidden, + cl::desc("The name of a font to use for the DOT" + " file (defaults to Courier)")); + static cl::opt CFGFuncName("cfg-func-name", cl::Hidden, cl::desc("The name of a function (or its substring)"