From patchwork Thu Sep 22 23:01:05 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sriraman Tallam X-Patchwork-Id: 116017 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 1F7C61007D3 for ; Fri, 23 Sep 2011 09:01:35 +1000 (EST) Received: (qmail 5588 invoked by alias); 22 Sep 2011 23:01:29 -0000 Received: (qmail 5570 invoked by uid 22791); 22 Sep 2011 23:01:26 -0000 X-SWARE-Spam-Status: No, hits=-1.6 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RP_MATCHES_RCVD, SPF_HELO_PASS X-Spam-Check-By: sourceware.org Received: from smtp-out.google.com (HELO smtp-out.google.com) (216.239.44.51) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 22 Sep 2011 23:01:10 +0000 Received: from hpaq7.eem.corp.google.com (hpaq7.eem.corp.google.com [172.25.149.7]) by smtp-out.google.com with ESMTP id p8MN18k9005672; Thu, 22 Sep 2011 16:01:08 -0700 Received: from azwildcat.mtv.corp.google.com (azwildcat.mtv.corp.google.com [172.18.110.231]) by hpaq7.eem.corp.google.com with ESMTP id p8MN16Dn015008; Thu, 22 Sep 2011 16:01:06 -0700 Received: by azwildcat.mtv.corp.google.com (Postfix, from userid 69128) id AF352B21BB; Thu, 22 Sep 2011 16:01:05 -0700 (PDT) To: reply@codereview.appspotmail.com, davidxl@google.com, gcc-patches@gcc.gnu.org Subject: Preserve callee cgraph edges when callgraph profiles sections are requested. (issue5101042) Message-Id: <20110922230105.AF352B21BB@azwildcat.mtv.corp.google.com> Date: Thu, 22 Sep 2011 16:01:05 -0700 (PDT) From: tmsriram@google.com (Sriraman Tallam) 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 This patch preserves cgraph callee edges till pass_final if callgraph edge profiles sections are requested. It also renames callgraph edge profile sections to be .gnu.callgraph instead of .note.callgraph --- This patch is available for review at http://codereview.appspot.com/5101042 Index: cgraphbuild.c =================================================================== --- cgraphbuild.c (revision 179098) +++ cgraphbuild.c (working copy) @@ -697,10 +697,18 @@ struct gimple_opt_pass pass_rebuild_cgraph_edges = } }; +/* Defined in tree-optimize.c */ +extern bool cgraph_callee_edges_final_cleanup; static unsigned int remove_cgraph_callee_edges (void) { + /* The -fcallgraph-profiles-sections flag needs the call-graph preserved + till pass_final. */ + if (cgraph_callee_edges_final_cleanup + && flag_callgraph_profiles_sections) + return 0; + cgraph_node_remove_callees (cgraph_node (current_function_decl)); return 0; } Index: final.c =================================================================== --- final.c (revision 179098) +++ final.c (working copy) @@ -4425,10 +4425,11 @@ rest_of_handle_final (void) profiling information. */ if (flag_callgraph_profiles_sections && flag_profile_use - && cgraph_node (current_function_decl) != NULL) + && cgraph_node (current_function_decl) != NULL + && (cgraph_node (current_function_decl))->callees != NULL) { flags = SECTION_DEBUG; - asprintf (&profile_fnname, ".note.callgraph.text.%s", fnname); + asprintf (&profile_fnname, ".gnu.callgraph.text.%s", fnname); switch_to_section (get_section (profile_fnname, flags, NULL)); fprintf (asm_out_file, "\t.string \"Function %s\"\n", fnname); dump_cgraph_profiles (); Index: testsuite/g++.dg/tree-prof/callgraph-profiles.C =================================================================== --- testsuite/g++.dg/tree-prof/callgraph-profiles.C (revision 0) +++ testsuite/g++.dg/tree-prof/callgraph-profiles.C (revision 0) @@ -0,0 +1,29 @@ +/* Verify if call-graph profile sections are created + with -fcallgraph-profiles-sections. */ +/* { dg-options "-O2 -fcallgraph-profiles-sections -ffunction-sections --save-temps" } */ + +int __attribute__ ((noinline)) +foo () +{ + return 1; +} + +int __attribute__ ((noinline)) +bar () +{ + return 0; +} + +int main () +{ + int sum; + for (int i = 0; i< 1000; i++) + { + sum = foo () + bar(); + } + return sum * bar (); +} + +/* { dg-final-use { scan-assembler "\.gnu\.callgraph\.text\.main" } } */ +/* { dg-final-use { scan-assembler "\.string \"1000\"" } } */ +/* { dg-final-use { cleanup-saved-temps } } */ Index: tree-optimize.c =================================================================== --- tree-optimize.c (revision 179098) +++ tree-optimize.c (working copy) @@ -48,11 +48,17 @@ along with GCC; see the file COPYING3. If not see #include "plugin.h" #include "regset.h" /* FIXME: For reg_obstack. */ +/* Decides if the cgraph callee edges are being cleaned up for the + last time. */ +bool cgraph_callee_edges_final_cleanup = false; + /* Gate: execute, or not, all of the non-trivial optimizations. */ static bool gate_all_optimizations (void) { + /* The cgraph callee edges can be cleaned up for the last time. */ + cgraph_callee_edges_final_cleanup = true; return (optimize >= 1 /* Don't bother doing anything if the program has errors. We have to pass down the queue if we already went into SSA */