From patchwork Tue Mar 25 22:38:06 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dehao Chen X-Patchwork-Id: 333733 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 ABD4514008F for ; Wed, 26 Mar 2014 09:38:20 +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:date:message-id:subject:from:to:cc:content-type; q=dns; s=default; b=NnTAbnhIXNW3z67jveS7/sBk4mxJYDiBLYj/OL39L4H DWUIyG6Zzdj9Y3ssnCFsVwbqJqPnbX/k2MPiCpdIsCdJrteZHwHCWfWutbh/W36e RucUlylWDu6HecrE9onBJTIKpuxKSfE+3ON5qEGbMVWle+7Ucu7l5BaiN2A1eLgE = 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:date:message-id:subject:from:to:cc:content-type; s=default; bh=x4+QNFJvnP6nXincEYv9hZXRUy4=; b=rOQdGhAeivRy4FoU0 aztfYs7pJqvPYkZ7yhFbC8E5sJF1c/SOy80DC9CFbJbUobnUdAS0SeRyau2FnL+5 AS1F+9aOVPqRi3t/GQgsOX8IV8n40iFTTZtpAppWw3NUGAjeFlbfVSGqBL95sCkm 31Yl648wCY4P4wK0SF5xvF/8to= Received: (qmail 3251 invoked by alias); 25 Mar 2014 22:38:10 -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 3163 invoked by uid 89); 25 Mar 2014 22:38:09 -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-f179.google.com Received: from mail-ie0-f179.google.com (HELO mail-ie0-f179.google.com) (209.85.223.179) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Tue, 25 Mar 2014 22:38:08 +0000 Received: by mail-ie0-f179.google.com with SMTP id lx4so1037888iec.24 for ; Tue, 25 Mar 2014 15:38:06 -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:date:message-id:subject:from:to:cc :content-type; bh=4EJxntT20QK/CZfe4+Yu9ykELXtm8ATGhx7f1BRxM54=; b=fJv+YwvcFocztj4mDGCTnZm7DL64/klKcCcSNzWbGc7cpWShxU2LMZougTH/sY+tFb b6vdy3TUD7s3jMIECEF3BkO4iJFaczjGAVEWmcR11F90ac5P59wSXryM1cYqUF6mseqW GyGl6Npl0wXyyxgNMSSt/Y445QYXRaMHmnvfIJ1GFz/mNQXREeXwqKcLTLZob2gY6hjb pkWmZgf+7nzBYBfFl80sMPPZBkI+qEFAzBn+qBTWTIyGvPV0rpDY3CSlRVEHmvLXqRoE Bn+7dM/+8XomfDSyTP2XCwgKZwdxzgk+xoKUEqW5ylitOWgPCiL0eaTq1IkKi3EdsWhy w/qg== X-Gm-Message-State: ALoCoQkalxT/ee7OxciV3zVCMHZm8FKtwjK3YSjyJSacPIxMUpCwnClrV7TPE5Q9YqCUsS1ObEHtI4NTNKuFP3ifikw2kgMedxvEPxZIIbQ1bEYPWpv6OiTRnKy2JJKfaKrZ5dVfHZ5BjSNR48DKaDM9yObQXKZGx+HlTalK/D57xmCj9/L16Bm9JsYa5n7ZWg8aZD6qYmsIn1cMpllVPyd1Nn7TwZANoQ== MIME-Version: 1.0 X-Received: by 10.42.232.206 with SMTP id jv14mr9593608icb.52.1395787086407; Tue, 25 Mar 2014 15:38:06 -0700 (PDT) Received: by 10.64.18.207 with HTTP; Tue, 25 Mar 2014 15:38:06 -0700 (PDT) Date: Tue, 25 Mar 2014 15:38:06 -0700 Message-ID: Subject: [GOOGLE] Refactor the LIPO fixup From: Dehao Chen To: GCC Patches Cc: David Li , Rong Xu X-IsSubscribed: yes 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/tree-profile.c =================================================================== --- gcc/tree-profile.c (revision 208818) +++ gcc/tree-profile.c (working copy) @@ -1119,18 +1119,12 @@ tree_profiling (void) cgraphunit.c:ipa_passes(). */ gcc_assert (cgraph_state == CGRAPH_STATE_IPA_SSA); + init_node_map (); + /* After value profile transformation, artificial edges (that keep function body from being deleted) won't be needed. */ + lipo_link_and_fixup (); - 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 +1136,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 (); Index: gcc/l-ipo.h =================================================================== --- gcc/l-ipo.h (revision 208818) +++ 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 208818) +++ gcc/auto-profile.c (working copy) @@ -1535,14 +1535,8 @@ auto_profile (void) init_node_map (); profile_info = autofdo::afdo_profile_info; + lipo_link_and_fixup (); - 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/cgraphbuild.c =================================================================== --- gcc/cgraphbuild.c (revision 208818) +++ gcc/cgraphbuild.c (working copy) @@ -599,7 +599,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 +625,52 @@ lipo_fixup_cgraph_edge_call_target (gimple stmt) } } +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 (); + } + + 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. */