[BOLT] Add -dump-cg option to dump call graph

Reviewed By: #bolt, rafauler

Differential Revision: https://reviews.llvm.org/D153994
This commit is contained in:
Amir Ayupov
2023-06-28 17:53:54 -07:00
parent 3fe2c21872
commit 2f3f7d1206
3 changed files with 24 additions and 8 deletions

View File

@@ -148,7 +148,7 @@ public:
// 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 @@ private:
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;

View File

@@ -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 @@ buildCallGraph(BinaryContext &BC, CgFilterFunction Filter, bool CgFromPerfData,
Cg.density(), NotProcessed, NoProfileCallsites,
NumFallbacks);
if (opts::DumpCGDot.getNumOccurrences()) {
Cg.printDot(opts::DumpCGDot, [&](CallGraph::NodeId Id) {
return Cg.nodeIdToFunc(Id)->getPrintName();
});
}
return Cg;
}

View File

@@ -172,9 +172,9 @@ cl::opt<bool>
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",