[PATCH] D153994: [BOLT] Add -dump-cg option to dump call graph

Amir Ayupov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 28 17:54:40 PDT 2023


This revision was automatically updated to reflect the committed changes.
Closed by commit rG2f3f7d1206f8: [BOLT] Add -dump-cg option to dump call graph (authored by Amir).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153994/new/

https://reviews.llvm.org/D153994

Files:
  bolt/include/bolt/Passes/CallGraph.h
  bolt/lib/Passes/BinaryFunctionCallGraph.cpp
  bolt/lib/Utils/CommandLineOpts.cpp


Index: bolt/lib/Utils/CommandLineOpts.cpp
===================================================================
--- bolt/lib/Utils/CommandLineOpts.cpp
+++ bolt/lib/Utils/CommandLineOpts.cpp
@@ -172,9 +172,9 @@
 
                cl::cat(BoltCategory));
 
-llvm::cl::opt<bool> TimeOpts("time-opts",
-                             cl::desc("print time spent in each optimization"),
-                             cl::cat(BoltOptCategory));
+cl::opt<bool> TimeOpts("time-opts",
+                       cl::desc("print time spent in each optimization"),
+                       cl::cat(BoltOptCategory));
 
 cl::opt<bool> UseOldText(
     "use-old-text",
Index: bolt/lib/Passes/BinaryFunctionCallGraph.cpp
===================================================================
--- bolt/lib/Passes/BinaryFunctionCallGraph.cpp
+++ bolt/lib/Passes/BinaryFunctionCallGraph.cpp
@@ -19,9 +19,18 @@
 
 #define DEBUG_TYPE "callgraph"
 
+using namespace llvm;
+
 namespace opts {
-extern llvm::cl::opt<bool> TimeOpts;
-extern llvm::cl::opt<unsigned> Verbosity;
+
+extern cl::opt<bool> TimeOpts;
+extern cl::opt<unsigned> Verbosity;
+extern cl::OptionCategory BoltCategory;
+
+static cl::opt<std::string>
+    DumpCGDot("dump-cg", cl::desc("dump callgraph to the given file"),
+              cl::cat(BoltCategory));
+
 } // namespace opts
 
 namespace llvm {
@@ -277,6 +286,12 @@
                      Cg.density(), NotProcessed, NoProfileCallsites,
                      NumFallbacks);
 
+  if (opts::DumpCGDot.getNumOccurrences()) {
+    Cg.printDot(opts::DumpCGDot, [&](CallGraph::NodeId Id) {
+      return Cg.nodeIdToFunc(Id)->getPrintName();
+    });
+  }
+
   return Cg;
 }
 
Index: bolt/include/bolt/Passes/CallGraph.h
===================================================================
--- bolt/include/bolt/Passes/CallGraph.h
+++ bolt/include/bolt/Passes/CallGraph.h
@@ -148,7 +148,7 @@
   // samples for every node
   void adjustArcWeights();
 
-  template <typename L> void printDot(char *fileName, L getLabel) const;
+  template <typename L> void printDot(StringRef FileName, L getLabel) const;
 
 private:
   void setSamples(const NodeId Id, uint64_t Samples) {
@@ -160,9 +160,10 @@
   ArcsType Arcs;
 };
 
-template <class L> void CallGraph::printDot(char *FileName, L GetLabel) const {
+template <class L>
+void CallGraph::printDot(StringRef FileName, L GetLabel) const {
   std::error_code EC;
-  raw_fd_ostream OS(std::string(FileName), EC, sys::fs::OF_None);
+  raw_fd_ostream OS(FileName, EC, sys::fs::OF_None);
   if (EC)
     return;
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D153994.535589.patch
Type: text/x-patch
Size: 2536 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230629/d0603846/attachment.bin>


More information about the llvm-commits mailing list