From patchwork Wed Mar 26 22:54:21 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dehao Chen X-Patchwork-Id: 334131 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]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 97C3C14008C for ; Thu, 27 Mar 2014 09:54:54 +1100 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:in-reply-to:references:date:message-id:subject :from:to:cc:content-type; q=dns; s=default; b=g5t5YT6Yd9tym/txxQ A1RZdfcR+rj4f6bixTAViAN+x+M9CNu+TdE36m2QiuFMLhIN9fvWJGVuw8jVFYHV ripdmqKw5qi/7hhvrooWkNZhCmO9G9R65q6mUH/MDq2LBY+CfOjkeCpLmcyo/GFj Q6fu/0A6NQTxs+4CxKGtBcIE8= 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 :mime-version:in-reply-to:references:date:message-id:subject :from:to:cc:content-type; s=default; bh=pmngeoWQU9EIMm2YmcP0h7eB y2c=; b=Iyn6qHtEysUIjLkBchvdyZKw6lF+w0GFQKfoRTIJIdULbDgtBZ6qers5 +40s5nZaRiou9crXCvfGCohQqAFlXpkNk92Ry4y7DMUlCf8uCxFebAS3UlhDCdih JSXUmO3SCd3AzEvKA+cW83d8u6y89GW98lLLL+/dkso6Q6nAoYc= Received: (qmail 12833 invoked by alias); 26 Mar 2014 22:54:25 -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 12772 invoked by uid 89); 26 Mar 2014 22:54:24 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.2 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, RP_MATCHES_RCVD, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-ie0-f174.google.com Received: from mail-ie0-f174.google.com (HELO mail-ie0-f174.google.com) (209.85.223.174) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Wed, 26 Mar 2014 22:54:23 +0000 Received: by mail-ie0-f174.google.com with SMTP id rp18so2344871iec.5 for ; Wed, 26 Mar 2014 15:54:21 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=bArd5OSvFnj7dHl+X7pWrZxHFZc0dB0jZ0JdGEgVH0w=; b=lZif7AiQJ+Lg49jivRc5xKzbGUgtIQmcP3SWRTqkVqEpLywsBkyMojBcyWe4lhNxnO Ribq5cdEFi0JFcBDjJpobvgHwDE5tT7yfuirTmSQaEXjgR+4tGvOdtHhzqrVXrQzYB32 cRnCPRXNf8OAIHV6NVLv3T9ctxDnTSbeTNO52oB7lKVuQal/kbcFqdTCc1PJx6KzDzPt h2c0EUOxz5dejyC61M0hnX3RfEE05QlT+zbuBkGQslARIn+0yrMZpcqTfYWCerEkLa9o ysvvYLPEcy8nN+k4aI2B8GqwpZ7CdqQY/azCSnrumxVPs1qXV9Skp4zBDP9e9n53IXgL 0NlQ== X-Gm-Message-State: ALoCoQlWD45zAgNHa9nzqo+wSa8cio8NB2+I4r6ran1GBNi/ra2numNHqIfH8QtM32vDEAlM6+6Lmp35WsyGRNAkCjFUFn6wsPQ0pHOPwBzttgW8gFjli4gudvL3o293FYvUfJ/I6/8HYvJOE4Q9yEo8K1Gr78hZqLJKA2kyB3ceSbQHeb6Ame1cq8ruzpYLYpBJLbIYT/feF78YvF45YIJMHKPbVaMRAw== MIME-Version: 1.0 X-Received: by 10.50.143.107 with SMTP id sd11mr27377088igb.39.1395874461430; Wed, 26 Mar 2014 15:54:21 -0700 (PDT) Received: by 10.64.18.207 with HTTP; Wed, 26 Mar 2014 15:54:21 -0700 (PDT) In-Reply-To: References: Date: Wed, 26 Mar 2014 15:54:21 -0700 Message-ID: Subject: Re: [GOOGLE] Refactor the LIPO fixup From: Dehao Chen To: Xinliang David Li Cc: GCC Patches , Rong Xu X-IsSubscribed: yes Patch updated, passed performance tests. Dehao On Tue, Mar 25, 2014 at 4:03 PM, Xinliang David Li wrote: > Add comment to the new function. init_node_map is better invoked after > the link step to avoid creating entries with for dead nodes. > > Ok if large perf testing is fine. > > David > > On Tue, Mar 25, 2014 at 3:38 PM, Dehao Chen wrote: >> This patch refactors LIPO fixup related code to move it into a >> standalone function. This makes sure that >> symtab_remove_unreachable_nodes is called right after the fixup so >> that there is not dangling cgraph nodes any time. >> >> Bootstrapped and regression test on-going. >> >> OK for google-4_8? >> >> Thanks, >> Dehao Index: gcc/l-ipo.h =================================================================== --- gcc/l-ipo.h (revision 208826) +++ gcc/l-ipo.h (working copy) @@ -60,7 +60,7 @@ void add_decl_to_current_module_scope (tree decl, int lipo_cmp_type (tree t1, tree t2); tree get_type_or_decl_name (tree); int equivalent_struct_types_for_tbaa (const_tree t1, const_tree t2); -void lipo_fixup_cgraph_edge_call_target (gimple); +void lipo_link_and_fixup (void); extern void copy_defined_module_set (tree, tree); extern bool is_parsing_done_p (void); extern const char* get_module_name (unsigned int); Index: gcc/auto-profile.c =================================================================== --- gcc/auto-profile.c (revision 208826) +++ gcc/auto-profile.c (working copy) @@ -1533,16 +1533,10 @@ auto_profile (void) if (cgraph_state == CGRAPH_STATE_FINISHED) return 0; - init_node_map (); profile_info = autofdo::afdo_profile_info; + lipo_link_and_fixup (); + init_node_map (); - cgraph_pre_profiling_inlining_done = true; - cgraph_process_module_scope_statics (); - /* Now perform link to allow cross module inlining. */ - cgraph_do_link (); - varpool_do_link (); - cgraph_unify_type_alias_sets (); - FOR_EACH_FUNCTION (node) { if (!gimple_has_body_p (node->symbol.decl)) @@ -1554,35 +1548,6 @@ auto_profile (void) push_cfun (DECL_STRUCT_FUNCTION (node->symbol.decl)); - if (L_IPO_COMP_MODE) - { - basic_block bb; - FOR_EACH_BB (bb) - { - gimple_stmt_iterator gsi; - for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi)) - { - gimple stmt = gsi_stmt (gsi); - if (is_gimple_call (stmt)) - lipo_fixup_cgraph_edge_call_target (stmt); - } - } - } - rebuild_cgraph_edges (); - pop_cfun (); - } - - FOR_EACH_FUNCTION (node) - { - if (!gimple_has_body_p (node->symbol.decl)) - continue; - - /* Don't profile functions produced for builtin stuff. */ - if (DECL_SOURCE_LOCATION (node->symbol.decl) == BUILTINS_LOCATION) - continue; - - push_cfun (DECL_STRUCT_FUNCTION (node->symbol.decl)); - /* First do indirect call promotion and early inline to make the IR match the profiled binary before actual annotation. Index: gcc/value-prof.c =================================================================== --- gcc/value-prof.c (revision 208826) +++ gcc/value-prof.c (working copy) @@ -1286,6 +1286,15 @@ init_gid_map (void) entp->node = n; entp->gid = ent.gid; } + else if (cgraph_pre_profiling_inlining_done) + { + (*slot)->node = cgraph_lipo_get_resolved_node (n->symbol.decl); + (*slot)->gid = ent.gid; + } + else + { + gcc_assert ((*slot)->gid == ent.gid && (*slot)->node == n); + } } } Index: gcc/cgraphbuild.c =================================================================== --- gcc/cgraphbuild.c (revision 208826) +++ gcc/cgraphbuild.c (working copy) @@ -244,9 +244,6 @@ add_fake_indirect_call_edges (struct cgraph_node * if (!L_IPO_COMP_MODE) return; - if (cgraph_pre_profiling_inlining_done) - return; - ic_counts = get_coverage_counts_no_warn (DECL_STRUCT_FUNCTION (node->symbol.decl), GCOV_COUNTER_ICALL_TOPNV, &n_counts); @@ -599,7 +596,7 @@ record_references_in_initializer (tree decl, bool needs to be set to the resolved node so that ipa-inline sees the definitions. */ #include "gimple-pretty-print.h" -void +static void lipo_fixup_cgraph_edge_call_target (gimple stmt) { tree decl; @@ -625,6 +622,57 @@ lipo_fixup_cgraph_edge_call_target (gimple stmt) } } +/* Link the cgraph nodes, varpool nodes and fixup the call target to + the correct decl. Remove dead functions. */ + + +void +lipo_link_and_fixup () +{ + struct cgraph_node *node; + + cgraph_pre_profiling_inlining_done = true; + cgraph_process_module_scope_statics (); + /* Now perform link to allow cross module inlining. */ + cgraph_do_link (); + varpool_do_link (); + cgraph_unify_type_alias_sets (); + + FOR_EACH_DEFINED_FUNCTION (node) + { + if (!gimple_has_body_p (node->symbol.decl)) + continue; + + /* Don't profile functions produced for builtin stuff. */ + if (DECL_SOURCE_LOCATION (node->symbol.decl) == BUILTINS_LOCATION) + continue; + + push_cfun (DECL_STRUCT_FUNCTION (node->symbol.decl)); + + if (L_IPO_COMP_MODE) + { + basic_block bb; + FOR_EACH_BB (bb) + { + gimple_stmt_iterator gsi; + for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi)) + { + gimple stmt = gsi_stmt (gsi); + if (is_gimple_call (stmt)) + lipo_fixup_cgraph_edge_call_target (stmt); + } + } + update_ssa (TODO_update_ssa); + } + rebuild_cgraph_edges (); + pop_cfun (); + } + + cgraph_add_fake_indirect_call_edges (); + symtab_remove_unreachable_nodes (true, dump_file); +} + + /* Rebuild cgraph edges for current function node. This needs to be run after passes that don't update the cgraph. */ @@ -677,7 +725,8 @@ rebuild_cgraph_edges (void) mark_load, mark_store, mark_address); } - add_fake_indirect_call_edges (node); + if (!cgraph_pre_profiling_inlining_done) + add_fake_indirect_call_edges (node); record_eh_tables (node, cfun); gcc_assert (!node->global.inlined_to); Index: gcc/tree-profile.c =================================================================== --- gcc/tree-profile.c (revision 208826) +++ gcc/tree-profile.c (working copy) @@ -1118,19 +1118,11 @@ tree_profiling (void) /* This is a small-ipa pass that gets called only once, from cgraphunit.c:ipa_passes(). */ gcc_assert (cgraph_state == CGRAPH_STATE_IPA_SSA); - /* After value profile transformation, artificial edges (that keep function body from being deleted) won't be needed. */ + lipo_link_and_fixup (); + init_node_map (); - cgraph_pre_profiling_inlining_done = true; - cgraph_process_module_scope_statics (); - /* Now perform link to allow cross module inlining. */ - cgraph_do_link (); - varpool_do_link (); - cgraph_unify_type_alias_sets (); - - init_node_map(); - FOR_EACH_DEFINED_FUNCTION (node) { if (!gimple_has_body_p (node->symbol.decl)) @@ -1142,23 +1134,6 @@ tree_profiling (void) push_cfun (DECL_STRUCT_FUNCTION (node->symbol.decl)); - if (L_IPO_COMP_MODE) - { - basic_block bb; - FOR_EACH_BB (bb) - { - gimple_stmt_iterator gsi; - for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi)) - { - gimple stmt = gsi_stmt (gsi); - if (is_gimple_call (stmt)) - lipo_fixup_cgraph_edge_call_target (stmt); - } - } - update_ssa (TODO_update_ssa); - } - - /* Local pure-const may imply need to fixup the cfg. */ if (execute_fixup_cfg () & TODO_cleanup_cfg) cleanup_tree_cfg ();