diff mbox series

[v2] Make lto-dump dump callgraph in DOT format

Message ID 20190702123603.numbkwxovt7y5zj7@smtp.gmail.com
State New
Headers show
Series [v2] Make lto-dump dump callgraph in DOT format | expand

Commit Message

Giuliano Belinassi July 2, 2019, 12:36 p.m. UTC
This patch makes lto-dump the symtab callgraph in graphviz DOT format.

Previously, the suggested patch had some minor and checkstyle issues
that were fixed in this version.


    gcc/ChangeLog
    2019-07-02  Giuliano Belinassi  <giuliano.belinassi@usp.br>

            * cgraph.c (dump_graphviz): New function
            * cgraph.h (dump_graphviz): New function
            * symtab.c (dump_graphviz): New function

    gcc/lto/ChangeLog
    2019-07-02  Giuliano Belinassi  <giuliano.belinassi@usp.br>

            * lang.opt (flag_dump_callgraph): New flag
            * lto-dump.c (dump_symtab_graphviz): New function
            * lto-dump.c (dump_tool_help): New option
            * lto-dump.c (lto_main): New option

Comments

Martin Liška July 2, 2019, 12:40 p.m. UTC | #1
On 7/2/19 2:36 PM, Giuliano Belinassi wrote:
> This patch makes lto-dump the symtab callgraph in graphviz DOT format.
> 
> Previously, the suggested patch had some minor and checkstyle issues
> that were fixed in this version.
> 
> 
>     gcc/ChangeLog
>     2019-07-02  Giuliano Belinassi  <giuliano.belinassi@usp.br>
> 
>             * cgraph.c (dump_graphviz): New function
>             * cgraph.h (dump_graphviz): New function
>             * symtab.c (dump_graphviz): New function
> 
>     gcc/lto/ChangeLog
>     2019-07-02  Giuliano Belinassi  <giuliano.belinassi@usp.br>
> 
>             * lang.opt (flag_dump_callgraph): New flag
>             * lto-dump.c (dump_symtab_graphviz): New function
>             * lto-dump.c (dump_tool_help): New option
>             * lto-dump.c (lto_main): New option
> 

I like the patch. However, I can't approve the patch.
Hope Honza can approve it quickly?

Martin
Jeff Law July 2, 2019, 7:33 p.m. UTC | #2
On 7/2/19 6:36 AM, Giuliano Belinassi wrote:
> This patch makes lto-dump the symtab callgraph in graphviz DOT format.
> 
> Previously, the suggested patch had some minor and checkstyle issues
> that were fixed in this version.
> 
> 
>     gcc/ChangeLog
>     2019-07-02  Giuliano Belinassi  <giuliano.belinassi@usp.br>
> 
>             * cgraph.c (dump_graphviz): New function
>             * cgraph.h (dump_graphviz): New function
>             * symtab.c (dump_graphviz): New function
> 
>     gcc/lto/ChangeLog
>     2019-07-02  Giuliano Belinassi  <giuliano.belinassi@usp.br>
> 
>             * lang.opt (flag_dump_callgraph): New flag
>             * lto-dump.c (dump_symtab_graphviz): New function
>             * lto-dump.c (dump_tool_help): New option
>             * lto-dump.c (lto_main): New option
> 
OK for the trunk.
jeff
Giuliano Belinassi July 12, 2019, 8:36 p.m. UTC | #3
Hi,

It seems that this patch wasn't merged to trunk yet. Is there any
problem to it?

On 07/02, Jeff Law wrote:
> On 7/2/19 6:36 AM, Giuliano Belinassi wrote:
> > This patch makes lto-dump the symtab callgraph in graphviz DOT format.
> > 
> > Previously, the suggested patch had some minor and checkstyle issues
> > that were fixed in this version.
> > 
> > 
> >     gcc/ChangeLog
> >     2019-07-02  Giuliano Belinassi  <giuliano.belinassi@usp.br>
> > 
> >             * cgraph.c (dump_graphviz): New function
> >             * cgraph.h (dump_graphviz): New function
> >             * symtab.c (dump_graphviz): New function
> > 
> >     gcc/lto/ChangeLog
> >     2019-07-02  Giuliano Belinassi  <giuliano.belinassi@usp.br>
> > 
> >             * lang.opt (flag_dump_callgraph): New flag
> >             * lto-dump.c (dump_symtab_graphviz): New function
> >             * lto-dump.c (dump_tool_help): New option
> >             * lto-dump.c (lto_main): New option
> > 
> OK for the trunk.
> jeff

Giuliano.
Jeff Law July 12, 2019, 9:10 p.m. UTC | #4
On 7/12/19 2:36 PM, Giuliano Belinassi wrote:
> Hi,
> 
> It seems that this patch wasn't merged to trunk yet. Is there any
> problem to it?
Nope.  Just assumed you had access and would commit it yourself.  I'll
go ahead and commit it for you shortly.

jeff
diff mbox series

Patch

diff --git gcc/cgraph.c gcc/cgraph.c
index 28019aba434..34e449915d7 100644
--- gcc/cgraph.c
+++ gcc/cgraph.c
@@ -2204,6 +2204,22 @@  cgraph_node::dump (FILE *f)
     }
 }
 
+/* Dump call graph node to file F in graphviz format.  */
+
+void
+cgraph_node::dump_graphviz (FILE *f)
+{
+  cgraph_edge *edge;
+
+  for (edge = callees; edge; edge = edge->next_callee)
+    {
+      cgraph_node *callee = edge->callee;
+
+      fprintf (f, "\t\"%s\" -> \"%s\"\n", name (), callee->name ());
+    }
+}
+
+
 /* Dump call graph node NODE to stderr.  */
 
 DEBUG_FUNCTION void
diff --git gcc/cgraph.h gcc/cgraph.h
index 18839a4a5ec..efd6f41c4ae 100644
--- gcc/cgraph.h
+++ gcc/cgraph.h
@@ -135,6 +135,9 @@  public:
   /* Dump symtab node to F.  */
   void dump (FILE *f);
 
+  /* Dump symtab callgraph in graphviz format.  */
+  void dump_graphviz (FILE *f);
+
   /* Dump symtab node to stderr.  */
   void DEBUG_FUNCTION debug (void);
 
@@ -1106,6 +1109,9 @@  public:
   /* Dump call graph node to file F.  */
   void dump (FILE *f);
 
+  /* Dump call graph node to file F.  */
+  void dump_graphviz (FILE *f);
+
   /* Dump call graph node to stderr.  */
   void DEBUG_FUNCTION debug (void);
 
@@ -2279,6 +2285,9 @@  public:
   /* Dump symbol table to F.  */
   void dump (FILE *f);
 
+  /* Dump symbol table to F in graphviz format.  */
+  void dump_graphviz (FILE *f);
+
   /* Dump symbol table to stderr.  */
   void DEBUG_FUNCTION debug (void);
 
diff --git gcc/lto/lang.opt gcc/lto/lang.opt
index 5bacef349e3..c62dd5aac08 100644
--- gcc/lto/lang.opt
+++ gcc/lto/lang.opt
@@ -127,6 +127,9 @@  help
 LTODump Var(flag_lto_dump_tool_help)
 Dump the dump tool command line options.
 
+callgraph
+LTODump Var(flag_dump_callgraph)
+Dump the symtab callgraph.
 
 fresolution=
 LTO Joined
diff --git gcc/lto/lto-dump.c gcc/lto/lto-dump.c
index 691d109ff34..6856a4b6358 100644
--- gcc/lto/lto-dump.c
+++ gcc/lto/lto-dump.c
@@ -197,6 +197,12 @@  void dump_list_variables (void)
     e->dump ();
 }
 
+/* Dump symbol table in graphviz format.  */
+void dump_symtab_graphviz (void)
+{
+  symtab->dump_graphviz (stdout);
+}
+
 /* Dump symbol list.  */
 
 void dump_list (void)
@@ -251,26 +257,27 @@  void dump_body ()
 /* List of command line options for dumping.  */
 void dump_tool_help ()
 {
-  printf ("Usage: lto-dump [OPTION]... SUB_COMMAND [OPTION]...\n\n");
-  printf ("LTO dump tool command line options.\n\n");
-  printf ("  -list [options]           Dump the symbol list.\n");
-  printf ("    -demangle               Dump the demangled output.\n");
-  printf ("    -defined-only           Dump only the defined symbols.\n");
-  printf ("    -print-value            Dump initial values of the "
-	  "variables.\n");
-  printf ("    -name-sort              Sort the symbols alphabetically.\n");
-  printf ("    -size-sort              Sort the symbols according to size.\n");
-  printf ("    -reverse-sort           Dump the symbols in reverse order.\n");
-  printf ("  -symbol=                  Dump the details of specific symbol.\n");
-  printf ("  -objects                  Dump the details of LTO objects.\n");
-  printf ("  -type-stats               Dump statistics of tree types.\n");
-  printf ("  -tree-stats               Dump statistics of trees.\n");
-  printf ("  -gimple-stats             Dump statistics of gimple "
-	  "statements.\n");
-  printf ("  -dump-body=               Dump the specific gimple body.\n");
-  printf ("  -dump-level=              Deciding the optimization level "
-	  "of body.\n");
-  printf ("  -help                     Display the dump tool help.\n");
+  const char *msg =
+    "Usage: lto-dump [OPTION]... SUB_COMMAND [OPTION]...\n\n"
+    "LTO dump tool command line options.\n\n"
+    "  -list [options]           Dump the symbol list.\n"
+    "    -demangle               Dump the demangled output.\n"
+    "    -defined-only           Dump only the defined symbols.\n"
+    "    -print-value            Dump initial values of the variables.\n"
+    "    -name-sort              Sort the symbols alphabetically.\n"
+    "    -size-sort              Sort the symbols according to size.\n"
+    "    -reverse-sort           Dump the symbols in reverse order.\n"
+    "  -symbol=                  Dump the details of specific symbol.\n"
+    "  -objects                  Dump the details of LTO objects.\n"
+    "  -callgraph                Dump the callgraph in graphviz format.\n"
+    "  -type-stats               Dump statistics of tree types.\n"
+    "  -tree-stats               Dump statistics of trees.\n"
+    "  -gimple-stats             Dump statistics of gimple statements.\n"
+    "  -dump-body=               Dump the specific gimple body.\n"
+    "  -dump-level=              Deciding the optimization level of body.\n"
+    "  -help                     Display the dump tool help.\n";
+
+  fputs (msg, stdout);
   return;
 }
 
@@ -344,4 +351,9 @@  lto_main (void)
       dump_body ();
       return;
     }
+  else if (flag_dump_callgraph)
+    {
+      dump_symtab_graphviz ();
+      return;
+    }
 }
diff --git gcc/symtab.c gcc/symtab.c
index 905ca05e578..ae021667c59 100644
--- gcc/symtab.c
+++ gcc/symtab.c
@@ -955,6 +955,13 @@  symtab_node::dump (FILE *f)
     vnode->dump (f);
 }
 
+void
+symtab_node::dump_graphviz (FILE *f)
+{
+  if (cgraph_node *cnode = dyn_cast <cgraph_node *> (this))
+    cnode->dump_graphviz (f);
+}
+
 void
 symbol_table::dump (FILE *f)
 {
@@ -964,6 +971,16 @@  symbol_table::dump (FILE *f)
     node->dump (f);
 }
 
+void
+symbol_table::dump_graphviz (FILE *f)
+{
+  symtab_node *node;
+  fprintf (f, "digraph symtab {\n");
+  FOR_EACH_SYMBOL (node)
+    node->dump_graphviz (f);
+  fprintf (f, "}\n");
+}
+
 DEBUG_FUNCTION void
 symbol_table::debug (void)
 {