From patchwork Fri Aug 20 11:58:20 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Hubicka X-Patchwork-Id: 62270 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 954D9B70A6 for ; Fri, 20 Aug 2010 21:58:33 +1000 (EST) Received: (qmail 8996 invoked by alias); 20 Aug 2010 11:58:32 -0000 Received: (qmail 8983 invoked by uid 22791); 20 Aug 2010 11:58:30 -0000 X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=AWL, BAYES_00, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from nikam-dmz.ms.mff.cuni.cz (HELO nikam.ms.mff.cuni.cz) (195.113.20.16) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 20 Aug 2010 11:58:22 +0000 Received: from localhost (occam.ms.mff.cuni.cz [195.113.18.121]) by nikam.ms.mff.cuni.cz (Postfix) with ESMTP id 3C6049AC80B; Fri, 20 Aug 2010 13:58:20 +0200 (CEST) Received: by localhost (Postfix, from userid 16202) id 369C256419E; Fri, 20 Aug 2010 13:58:20 +0200 (CEST) Date: Fri, 20 Aug 2010 13:58:20 +0200 From: Jan Hubicka To: gcc-patches@gcc.gnu.org, rguenther@suse.de, dnovillo@redhat.com, tglek@mozilla.com Subject: Allow WPA stage to build new functions Message-ID: <20100820115820.GG18841@kam.mff.cuni.cz> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.18 (2008-05-17) 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 Hi, this patch allows WPA stage to construct new functions and ship them to LTO units. This is something I planned for a while (since IPA passes should have ability to build new functions) and I use it now in the ctor merging (to construct new function calling all the constructors) When the new function have unknown location, still patch I sent earlier for proper cgraph materialization is needed. Bootstrapped/regtested x86_64-linux, OK? Honza * lto-cgraph.c (lto_output_edge): Use gimple_has_body_p instead of flag_wpa. * lto-streamer-out.c (lto_output): Likewise. * passes.c (ipa_write_optimization_summaries): Initialize statement uids. * lto.c (lto_1_to_1_map): Be prepared for node to have no file data. (lto_wpa_write_files): Update comments. Index: lto-cgraph.c =================================================================== --- lto-cgraph.c (revision 163302) +++ lto-cgraph.c (working copy) @@ -281,7 +281,8 @@ lto_output_edge (struct lto_simple_outpu lto_output_sleb128_stream (ob->main_stream, edge->count); bp = bitpack_create (ob->main_stream); - uid = flag_wpa ? edge->lto_stmt_uid : gimple_uid (edge->call_stmt); + uid = (!gimple_has_body_p (edge->caller->decl) + ? edge->lto_stmt_uid : gimple_uid (edge->call_stmt)); bp_pack_value (&bp, uid, HOST_BITS_PER_INT); bp_pack_value (&bp, edge->inline_failed, HOST_BITS_PER_INT); bp_pack_value (&bp, edge->frequency, HOST_BITS_PER_INT); Index: lto-streamer-out.c =================================================================== --- lto-streamer-out.c (revision 163302) +++ lto-streamer-out.c (working copy) @@ -2124,7 +2124,7 @@ lto_output (cgraph_node_set set, varpool #endif decl_state = lto_new_out_decl_state (); lto_push_out_decl_state (decl_state); - if (!flag_wpa) + if (gimple_has_body_p (node->decl)) output_function (node); else copy_function (node); Index: lto/lto.c =================================================================== --- lto/lto.c (revision 163302) +++ lto/lto.c (working copy) @@ -805,15 +805,28 @@ lto_1_to_1_map (void) continue; file_data = node->local.lto_file_data; - gcc_assert (!node->same_body_alias && file_data); + gcc_assert (!node->same_body_alias); - slot = pointer_map_contains (pmap, file_data); - if (slot) - partition = (ltrans_partition) *slot; + if (file_data) + { + slot = pointer_map_contains (pmap, file_data); + if (slot) + partition = (ltrans_partition) *slot; + else + { + partition = new_partition (file_data->file_name); + slot = pointer_map_insert (pmap, file_data); + *slot = partition; + npartitions++; + } + } + else if (!file_data + && VEC_length (ltrans_partition, ltrans_partitions)) + partition = VEC_index (ltrans_partition, ltrans_partitions, 0); else { - partition = new_partition (file_data->file_name); - slot = pointer_map_insert (pmap, file_data); + partition = new_partition (""); + slot = pointer_map_insert (pmap, NULL); *slot = partition; npartitions++; } @@ -1059,16 +1072,13 @@ lto_wpa_write_files (void) timevar_push (TV_WHOPR_WPA); - /* Include all inlined functions and determine what sets need to be - compiled by LTRANS. After this loop, only those sets that - contain callgraph nodes from more than one file will need to be - compiled by LTRANS. */ for (i = 0; VEC_iterate (ltrans_partition, ltrans_partitions, i, part); i++) lto_stats.num_output_cgraph_nodes += VEC_length (cgraph_node_ptr, part->cgraph_set->nodes); - /* After adding all inlinees, find out statics that need to be promoted - to globals because of cross-file inlining. */ + /* Find out statics that need to be promoted + to globals with hidden visibility because they are accessed from multiple + partitions. */ lto_promote_cross_file_statics (); timevar_pop (TV_WHOPR_WPA); Index: passes.c =================================================================== --- passes.c (revision 163302) +++ passes.c (working copy) @@ -1793,8 +1793,25 @@ ipa_write_optimization_summaries (cgraph { struct lto_out_decl_state *state = lto_new_out_decl_state (); + cgraph_node_set_iterator csi; compute_ltrans_boundary (state, set, vset); lto_push_out_decl_state (state); + for (csi = csi_start (set); !csi_end_p (csi); csi_next (&csi)) + { + struct cgraph_node *node = csi_node (csi); + /* When streaming out references to statements as part of some IPA + pass summary, the statements need to have uids assigned. + + For functions newly born at WPA stage we need to initialize + the uids here. */ + if (node->analyzed + && gimple_has_body_p (node->decl)) + { + push_cfun (DECL_STRUCT_FUNCTION (node->decl)); + renumber_gimple_stmt_uids (); + pop_cfun (); + } + } gcc_assert (flag_wpa); ipa_write_optimization_summaries_1 (all_regular_ipa_passes, set, vset, state);