[llvm-commits] Call graph printer/viewer

Andrew Trick atrick at apple.com
Thu Jan 10 20:47:04 PST 2013


On Jan 10, 2013, at 8:29 AM, Speziale Ettore <speziale.ettore at gmail.com> wrote:

> Hi,
> 
> I would like viewing the call graph using opt. Right now this is
> not possible. Indeed, to view the call graph one should tell
> opt to dump it to a file and then open it with a DOT viewer.
> 
> So I started adding support for viewing the call graph from opt.
> Basically, there are 2 alternatives:
> 
> 1) If you are trying to print/view a graph that is a Function
>   analysis, then exploit DOTGraphTraits{Viewer,Printer}
>   * lib/Analysis/DomPrinter.cpp
>   * lib/Analysis/RegionPrinter.cpp
> 
> 2) Otherwise, use low-level interface {View,Write}Graph
>   * lib/Analysis/CFGPrinter.cpp
>     - View the graph, defines passes for viewing/printing
> 
>   * lib/CodeGen/SelectionDAG/SelectionDAGPrinter.cpp
>   * lib/CodeGen/ScheduleDAGPrinter.cpp
>     - View the graph, no associate pass
> 
>   * lib/CodeGen/EdgeBundles.cpp
>     - MachineFunction pass. Provide a member function to view the
>       graph using a custom ViewGraph function because the default 
>       implementation "it won't work"
> 
>   * lib/CodeGen/MachineFunction.cpp
>     - Provide member function to see/print the MachineFunction as a 
>       graph. Passes not available. I think because MachineFunctions
>       can only be viewed/printed on debug builds
> 
> I chosen to follow the first alternative. However, it works only for
> FunctionPass, while I need a ModulePass, so I defined
> DOTGraphTraitsModule{Viewer,Printer} for handling Module viewer/helpers
> and I exploited them for providing call graph viewer/printer.
> 
> Attached is the patch. In the case it is OK, maybe
> DOTGraphTraits{Viewer,Printer} should be renamed in something like
> DOTGraphTraitsFunction{Viewer,Printer} to point out that they handle
> function-related graph viewing/printing.


LGTM. I have a few minor comments.

The existing code for graph printers follows an odd style. I would add new code using a more standard style...

+    : ModulePass(ID) {
+    Name = GraphName;

...use the initializer list.

+  virtual bool runOnModule(Module &M) {
+    Analysis *Graph;
+    std::string Title;
+    Graph = &getAnalysis<Analysis>();
+    Title = DOTGraphTraits<Analysis*>::getGraphName(Graph);

...declare and initialize your variables on the same line.

+++ tools/opt/GraphPrinters.cpp

Please remove unnecessary includes from this file now that you've removed most of the implementation.

-Andy



More information about the llvm-commits mailing list