From patchwork Tue Jul 2 12:36:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Giuliano Belinassi X-Patchwork-Id: 1126239 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-504177-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=usp.br Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="IWuVkHNV"; dkim=pass (2048-bit key; unprotected) header.d=usp-br.20150623.gappssmtp.com header.i=@usp-br.20150623.gappssmtp.com header.b="NehXNPeZ"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 45dNyd0m94z9s00 for ; Tue, 2 Jul 2019 22:36:23 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; q=dns; s= default; b=xW5SBJKxd/ZhN02Fo4+SFbeq5TczZeD5WyFCSyWfTuN9ImPVf+boX 2thciPOwrmJJ5qjT2Vg+GVRFQLvhsWkQYW3Vsb6sDzvq+0yJRhwIPvyk1dAGOnQS B4sebN4vu5BpmYPr7GvlXng08ddMTIsjuUJOVjcucC0qUoxAp6b5Do= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; s= default; bh=ZBwLL5tsKfNX5qvX5pyy/7C0ty4=; b=IWuVkHNVWC8uNBdzFbT5 VfYvGg6c5AC6Obj0TN+rdrHodiD37r/C3YqIiMVVZL/msE7bA4WsDCZben9Y6gv8 FdlI4pPQc6Ppu7H4KwJBugfZdf+l/1umonIkBjw2tgWuW4B3yHP8YLb+BIsbJuLk VHuGnANZdwZpWnTORUftjUY= Received: (qmail 74076 invoked by alias); 2 Jul 2019 12:36:16 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 73785 invoked by uid 89); 2 Jul 2019 12:36:15 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-18.7 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy= X-HELO: mail-qt1-f173.google.com Received: from mail-qt1-f173.google.com (HELO mail-qt1-f173.google.com) (209.85.160.173) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 02 Jul 2019 12:36:09 +0000 Received: by mail-qt1-f173.google.com with SMTP id p15so18219568qtl.3 for ; Tue, 02 Jul 2019 05:36:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=usp-br.20150623.gappssmtp.com; s=20150623; h=date:from:to:subject:message-id:mime-version:content-disposition :user-agent; bh=cMoEaewDDY63iexPaCik1S3DRnNqYkHW8nUvG5PLdAM=; b=NehXNPeZQEIHh6fQH9oYWMSkBmf8LlXwrtH9p19+Lr6YCHLmfGJ9FyPA9eGBaaZDoh ZId27UNj2TaZSXMVcgCJ3MqcpoXOUmXUTulc3/YgV72oY7lalkOn8zEphAWC1FGPq9j9 kmMBAxWDJhteruQrYAfvtNJgzQj7Us8Kx4hCdzx6pY1BHgplOgR2ABGhiuQDBUzDJmX2 aNO4PIqbl6r/y+oGtDh6PlmyrkeVAhxoRyNbd3uVRVMhimbMeqPUn+zjKNCPLqPn0hLf CsW2e63omistG/xiAmGeq0rMhg7UK8C0Yz7VoSZ3F1ok9iyu3MAL8Flwhn6xE3SLog/X DoZA== Received: from smtp.gmail.com ([143.107.45.1]) by smtp.gmail.com with ESMTPSA id x8sm6713643qka.106.2019.07.02.05.36.06 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Tue, 02 Jul 2019 05:36:07 -0700 (PDT) Date: Tue, 2 Jul 2019 09:36:03 -0300 From: Giuliano Belinassi To: Martin =?utf-8?b?TGnFoWth?= , gcc-patches@gcc.gnu.org Subject: [PATCH v2] Make lto-dump dump callgraph in DOT format Message-ID: <20190702123603.numbkwxovt7y5zj7@smtp.gmail.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: NeoMutt/20180716 X-IsSubscribed: yes 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 * 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 * 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 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 (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) {