From patchwork Wed Dec 14 06:03:33 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Dehao Chen X-Patchwork-Id: 131311 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id D9A821007D5 for ; Wed, 14 Dec 2011 17:03:58 +1100 (EST) Received: (qmail 27117 invoked by alias); 14 Dec 2011 06:03:51 -0000 Received: (qmail 27099 invoked by uid 22791); 14 Dec 2011 06:03:49 -0000 X-SWARE-Spam-Status: No, hits=-3.2 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mail-iy0-f175.google.com (HELO mail-iy0-f175.google.com) (209.85.210.175) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 14 Dec 2011 06:03:33 +0000 Received: by iadj38 with SMTP id j38so797757iad.20 for ; Tue, 13 Dec 2011 22:03:33 -0800 (PST) Received: by 10.50.140.1 with SMTP id rc1mr22678901igb.25.1323842613182; Tue, 13 Dec 2011 22:03:33 -0800 (PST) MIME-Version: 1.0 Received: by 10.50.140.1 with SMTP id rc1mr22678891igb.25.1323842613067; Tue, 13 Dec 2011 22:03:33 -0800 (PST) Received: by 10.50.85.132 with HTTP; Tue, 13 Dec 2011 22:03:33 -0800 (PST) In-Reply-To: References: Date: Wed, 14 Dec 2011 14:03:33 +0800 Message-ID: Subject: Re: [google] dump inline decisions to stderr under -fopt-info From: Dehao Chen To: gcc-patches@gcc.gnu.org X-System-Of-Record: true X-IsSubscribed: yes 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 Sorry, forgot to attach the patch... Dehao On Wed, Dec 14, 2011 at 9:13 AM, Dehao Chen wrote: > I've updated the patch to fix a bug in dump_inline_decision. > > Thanks, > Dehao > > On Thu, Dec 1, 2011 at 9:59 AM, Dehao Chen wrote: >> >> This patch is for google-{main|gcc_4.6} only. >> >> Tested with bootstrap and regression tests. >> >> Dump inline decisions, also output the inline chain. >> >> Dehao >> >> 2011-12-01  Dehao Chen   >> >>        * ipa-inline.c (dump_inline_decision): New function. >>        (inline_small_functions): Use it to dump the inline decisions to stderr. >> >> Index: gcc/ipa-inline.c >> =================================================================== >> --- gcc/ipa-inline.c    (revision 181835) >> +++ gcc/ipa-inline.c    (working copy) >> @@ -1377,6 +1377,45 @@ >>  } >> >> >> +/* Dump the inline decision of EDGE to stderr.  */ >> + >> +static void >> +dump_inline_decision (struct cgraph_edge *edge) >> +{ >> +  location_t locus; >> +  size_t buf_size = 4096; >> +  size_t current_string_len = 0; >> +  char *buf = (char *) xmalloc (buf_size); >> +  struct cgraph_node *inlined_to; >> +  gcov_type callee_count = edge->callee->count; >> +  buf[0] = 0; >> +  if (edge->inline_failed == CIF_OK && edge->callee->clone_of) >> +    callee_count += edge->callee->clone_of->count; >> +  for (inlined_to = edge->caller->global.inlined_to; >> +       inlined_to; inlined_to = inlined_to->global.inlined_to) >> +    { >> +      const char *name = cgraph_node_name (inlined_to); >> +      if (!name) >> +       name = "unknown"; >> +      current_string_len += (strlen (name) + 4); >> +      while (current_string_len >= buf_size) >> +       { >> +         buf_size *= 2; >> +         buf = (char *) xrealloc (buf, buf_size); >> +       } >> +      strcat (buf, "-->"); >> +      strcat (buf, name); >> +    } >> +  locus = gimple_location (edge->call_stmt); >> +  inform (locus, "%s ("HOST_WIDEST_INT_PRINT_DEC") --" >> +         HOST_WIDEST_INT_PRINT_DEC"--> %s (" >> +         HOST_WIDEST_INT_PRINT_DEC") %s : %s", >> +         cgraph_node_name (edge->callee), callee_count, edge->count, >> +         cgraph_node_name (edge->caller), edge->caller->count, buf, >> +         edge->inline_failed == CIF_OK ? "INLINED": "IGNORED"); >> +} >> + >> + >>  /* We use greedy algorithm for inlining of small functions: >>    All inline candidates are put into prioritized heap ordered in >>    increasing badness. >> @@ -1428,6 +1467,7 @@ >>   overall_size = initial_size; >>   max_size = compute_max_insns (overall_size); >>   min_size = overall_size; >> +  edge = NULL; >> >>   /* Populate the heeap with all edges we might inline.  */ >> >> @@ -1462,6 +1502,9 @@ >>       int current_badness; >>       int growth; >> >> +      if (edge && flag_opt_info >= OPT_INFO_MIN) >> +       dump_inline_decision (edge); >> + >>       edge = (struct cgraph_edge *) fibheap_extract_min (heap); >>       gcc_assert (edge->aux); >>       edge->aux = NULL; >> @@ -1482,6 +1525,7 @@ >>       if (current_badness != badness) >>        { >>          edge->aux = fibheap_insert (heap, current_badness, edge); >> +         edge = NULL; >>          continue; >>        } >> >> @@ -1636,6 +1680,8 @@ >>            fprintf (dump_file, "New minimal size reached: %i\n", min_size); >>        } >>     } >> +  if (edge && flag_opt_info >= OPT_INFO_MIN) >> +    dump_inline_decision (edge); >> >>   free_growth_caches (); >>   if (new_indirect_edges) Index: ipa-inline.c =================================================================== --- ipa-inline.c (revision 181835) +++ ipa-inline.c (working copy) @@ -1073,6 +1073,44 @@ return false; } +/* Dump the inline decision of EDGE to stderr. */ + +static void +dump_inline_decision (struct cgraph_edge *edge) +{ + location_t locus; + size_t buf_size = 4096; + size_t current_string_len = 0; + char *buf = (char *) xmalloc (buf_size); + struct cgraph_node *inlined_to; + gcov_type callee_count = edge->callee->count; + buf[0] = 0; + if (edge->inline_failed == CIF_OK && edge->callee->clone_of) + callee_count += edge->callee->clone_of->count; + for (inlined_to = edge->caller->global.inlined_to; + inlined_to; inlined_to = inlined_to->global.inlined_to) + { + const char *name = cgraph_node_name (inlined_to); + if (!name) + name = "unknown"; + current_string_len += (strlen (name) + 4); + while (current_string_len >= buf_size) + { + buf_size *= 2; + buf = (char *) xrealloc (buf, buf_size); + } + strcat (buf, "-->"); + strcat (buf, name); + } + locus = gimple_location (edge->call_stmt); + inform (locus, "%s ("HOST_WIDEST_INT_PRINT_DEC") --" + HOST_WIDEST_INT_PRINT_DEC"--> %s (" + HOST_WIDEST_INT_PRINT_DEC") %s : %s", + xstrdup (cgraph_node_name (edge->callee)), callee_count, edge->count, + xstrdup (cgraph_node_name (edge->caller)), edge->caller->count, buf, + edge->inline_failed == CIF_OK ? "INLINED": "IGNORED"); +} + /* We use greedy algorithm for inlining of small functions: All inline candidates are put into prioritized heap based on estimated @@ -1125,6 +1163,7 @@ max_size = compute_max_insns (overall_size); min_size = overall_size; + edge = NULL; while (overall_size <= max_size && !fibheap_empty (heap)) @@ -1136,6 +1175,9 @@ int growth; cgraph_inline_failed_t not_good = CIF_OK; + if (edge && flag_opt_info >= OPT_INFO_MIN) + dump_inline_decision (edge); + edge = (struct cgraph_edge *) fibheap_extract_min (heap); gcc_assert (edge->aux); edge->aux = NULL; @@ -1150,6 +1192,7 @@ if (current_badness != badness) { edge->aux = fibheap_insert (heap, current_badness, edge); + edge = NULL; continue; } @@ -1337,6 +1380,9 @@ fprintf (dump_file, "New minimal size reached: %i\n", min_size); } } + if (edge && flag_opt_info >= OPT_INFO_MIN) + dump_inline_decision (edge); + while (!fibheap_empty (heap)) { int badness = fibheap_min_key (heap);