diff --git a/bolt/include/bolt/Core/BinaryFunction.h b/bolt/include/bolt/Core/BinaryFunction.h --- a/bolt/include/bolt/Core/BinaryFunction.h +++ b/bolt/include/bolt/Core/BinaryFunction.h @@ -896,6 +896,9 @@ /// Dump CFG in graphviz format to file. void dumpGraphToFile(std::string Filename) const; + /// Dump CFG in d3.js format + void dumpGraphD3(raw_ostream &OS) const; + /// Dump CFG in graphviz format to a file with a filename that is derived /// from the function name and Annotation strings. Useful for dumping the /// CFG after an optimization pass. diff --git a/bolt/lib/Core/BinaryFunction.cpp b/bolt/lib/Core/BinaryFunction.cpp --- a/bolt/lib/Core/BinaryFunction.cpp +++ b/bolt/lib/Core/BinaryFunction.cpp @@ -80,6 +80,10 @@ cl::Hidden, cl::cat(BoltCategory)); +static cl::opt DotHtml("dot-html", + cl::desc("dump function DOT graph into html file"), + cl::ZeroOrMore, cl::Hidden, cl::cat(BoltCategory)); + cl::opt JumpTables("jump-tables", cl::desc("jump tables support (default=basic)"), @@ -3054,6 +3058,21 @@ } // namespace +void BinaryFunction::dumpGraphD3(raw_ostream &OS) const { + OS << "\n" + << "\n" + << "\n" + << ""; +} + void BinaryFunction::dumpGraph(raw_ostream &OS) const { OS << "strict digraph \"" << getPrintName() << "\" {\n"; uint64_t Offset = Address; @@ -3147,7 +3166,8 @@ } void BinaryFunction::dumpGraphForPass(std::string Annotation) const { - std::string Filename = constructFilename(getPrintName(), Annotation, ".dot"); + std::string Ext = opts::DotHtml ? ".html" : ".dot"; + std::string Filename = constructFilename(getPrintName(), Annotation, Ext); outs() << "BOLT-DEBUG: Dumping CFG to " << Filename << "\n"; dumpGraphToFile(Filename); } @@ -3162,7 +3182,10 @@ } return; } - dumpGraph(of); + if (opts::DotHtml) + dumpGraphD3(of); + else + dumpGraph(of); } bool BinaryFunction::validateCFG() const {