[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 11:53:10 PDT 2023
Amir created this revision.
Amir added a reviewer: bolt.
Herald added a reviewer: rafauler.
Herald added subscribers: treapster, ayermolo.
Herald added a reviewer: maksfb.
Herald added a project: All.
Amir requested review of this revision.
Herald added subscribers: llvm-commits, yota9.
Herald added a project: LLVM.
Repository:
rG LLVM Github Monorepo
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 {
@@ -270,6 +279,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.535483.patch
Type: text/x-patch
Size: 2536 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230628/988847ab/attachment.bin>
More information about the llvm-commits
mailing list