diff --git a/bolt/include/bolt/Passes/CallGraph.h b/bolt/include/bolt/Passes/CallGraph.h --- a/bolt/include/bolt/Passes/CallGraph.h +++ b/bolt/include/bolt/Passes/CallGraph.h @@ -148,7 +148,7 @@ // samples for every node void adjustArcWeights(); - template void printDot(char *fileName, L getLabel) const; + template void printDot(StringRef FileName, L getLabel) const; private: void setSamples(const NodeId Id, uint64_t Samples) { @@ -160,9 +160,10 @@ ArcsType Arcs; }; -template void CallGraph::printDot(char *FileName, L GetLabel) const { +template +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; diff --git a/bolt/lib/Passes/BinaryFunctionCallGraph.cpp b/bolt/lib/Passes/BinaryFunctionCallGraph.cpp --- a/bolt/lib/Passes/BinaryFunctionCallGraph.cpp +++ b/bolt/lib/Passes/BinaryFunctionCallGraph.cpp @@ -19,9 +19,18 @@ #define DEBUG_TYPE "callgraph" +using namespace llvm; + namespace opts { -extern llvm::cl::opt TimeOpts; -extern llvm::cl::opt Verbosity; + +extern cl::opt TimeOpts; +extern cl::opt Verbosity; +extern cl::OptionCategory BoltCategory; + +static cl::opt + 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; } diff --git a/bolt/lib/Utils/CommandLineOpts.cpp b/bolt/lib/Utils/CommandLineOpts.cpp --- a/bolt/lib/Utils/CommandLineOpts.cpp +++ b/bolt/lib/Utils/CommandLineOpts.cpp @@ -172,9 +172,9 @@ cl::cat(BoltCategory)); -llvm::cl::opt TimeOpts("time-opts", - cl::desc("print time spent in each optimization"), - cl::cat(BoltOptCategory)); +cl::opt TimeOpts("time-opts", + cl::desc("print time spent in each optimization"), + cl::cat(BoltOptCategory)); cl::opt UseOldText( "use-old-text",