From patchwork Fri Nov 17 20:17:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Jires X-Patchwork-Id: 166327 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9910:0:b0:403:3b70:6f57 with SMTP id i16csp789748vqn; Fri, 17 Nov 2023 12:18:41 -0800 (PST) X-Google-Smtp-Source: AGHT+IE+XrpGicduDSa8x1IrisH11HYO25fhiYrwOFnysrAMhdELihmaf6oumZMxOd6278ZELvU7 X-Received: by 2002:ac8:58ce:0:b0:417:9a94:870b with SMTP id u14-20020ac858ce000000b004179a94870bmr929974qta.35.1700252321054; Fri, 17 Nov 2023 12:18:41 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1700252321; cv=pass; d=google.com; s=arc-20160816; b=ik2k0KKdbYGJrUl8rMVumYKAY3Y9lwPachaSK1VzL1XbRyedNGEDvZdGrwkVr1NX2i PoAN8lDGTPq/Nwg9+XRQEUhDnjN6mUPQ1s5RRtgarI6iMWiJRi0VnJrLfN7UNIk1hyO6 MRh5BnRrtOMfCZ2YJ1eJl15NzXdbT/ow0FPqTO9yyKTot9fRnRO3mvuFJcsUrmD0ZLce BYTgP7JoIhgacygbY3USI6XWge3cfhsK6xciiIYiSLRp3jgGIgKh56NAtAtJ7nSmNcKK SdtShzbCvQ3FAFwzMpx33ShTtAD4UQUflZFLphyi+nGSwYmjntVyKtbtTgw466WTfO/m r0Ug== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:in-reply-to:content-disposition :mime-version:references:message-id:subject:to:from:date :dkim-signature:dkim-signature:arc-filter:dmarc-filter:delivered-to; bh=TYCVoSOQPM/Sd+vhuhaE0Y76vqvgrWbiNH+fDNAXStU=; fh=hPrbWPhweUx4V0GV9uXJqbyAzg2ABmTz7kczrAQqMmM=; b=DlAlr5wTDGnxWbvcKRaIoey8AyutcYzJYPRZXfUamcThphcmugPKUHg/9fyG5aPdJG 9Oug0zvXl32oFrQm6M3MtqT2mdliJrXflqjmwwIDknmCOSMrqGwAetNImfw7uR0Qdqh8 xXqFNbq1RhNbEEvjKiKsHz3Ri7uTgN+VjPxU5ZQLd6+eKt0qBGkhzpzEzaOYGeptUunZ wdv13yQ8mN+9xGJQ1+ePZhV0mi80ggXXbxr6GSbpr7CDFn4KhIHWuaT6Du1pvuANhElv 6fezblTqKfAut3tfJma+LyQvh1jrq+7/R+hNVM3SRMGjw4m0Tu1adKDOTCUTbYEEOxKk PL1A== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=Gz3N9g39; dkim=neutral (no key) header.i=@suse.cz; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id u22-20020ac858d6000000b00403bf9d2091si2347752qta.363.2023.11.17.12.18.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Nov 2023 12:18:41 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=Gz3N9g39; dkim=neutral (no key) header.i=@suse.cz; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CCD023858C50 for ; Fri, 17 Nov 2023 20:18:40 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by sourceware.org (Postfix) with ESMTPS id 43F8A3857830 for ; Fri, 17 Nov 2023 20:17:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 43F8A3857830 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=suse.cz ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 43F8A3857830 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2001:67c:2178:6::1c ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700252251; cv=none; b=By1+MVEGfAfb1PFv8opXWwQcJ0jmkyT8uqZ2fcAO3osLSbXTsr+If+04ZT4K48PHLvXNlNqRWiQWxh+xLUk3b99+9mc8IMgSy+3A4d+RURc++qQtyz6cdwagj/i/+5RNpulqSBIe90MzKmWkYJkESO0fwMEGvEBXP/r/oKGZnxE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700252251; c=relaxed/simple; bh=fU1MnP2nhBngY3mkYq70ipSFi+rAxZx1ta3lZ5U6xlU=; h=DKIM-Signature:DKIM-Signature:Date:From:To:Subject:Message-ID: MIME-Version; b=fb+HjRWABUAXnXPsVMUO9Ra/LcmHQkpH4Y7ECBkZ42SHxBaL7TxExBfzHjqriKAO1n5jGFVChIIdC7eaqXp1Nb7BC0AN4cnayoNytBadTsgeJD7sjZh6bDMtBIt3guvHKqkbFoH+AoVgRiDIzUpSvvrvMciBROaDNmAHvwzWQ5c= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 4839A2293E for ; Fri, 17 Nov 2023 20:17:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1700252248; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=TYCVoSOQPM/Sd+vhuhaE0Y76vqvgrWbiNH+fDNAXStU=; b=Gz3N9g39/Up65UstIpOivywrDw6cXM5hjou3Z3Mc0HX7nzT8bhE/xjmLEfMKIswguAzejn p/ieZCtodgX2VLiuxXXsu35A/UKURlA1yOwJDQKiq5F0l5q+6SBQk95StcxW9Wz/LIavDW z7q9AhwpFOSdk/wh4QFMR4IRn/dM2hQ= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1700252248; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=TYCVoSOQPM/Sd+vhuhaE0Y76vqvgrWbiNH+fDNAXStU=; b=Fb6TkshA/DBOTpRey1cY2PwQESbeWvqMlc2LERjD10ZZXGAoD4zWI5bMHT4V8i3CgCBapa sWX7rHZjtF5yE9Cg== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 278481341F for ; Fri, 17 Nov 2023 20:17:28 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id E5GrB1jKV2VWGgAAMHmgww (envelope-from ) for ; Fri, 17 Nov 2023 20:17:28 +0000 Date: Fri, 17 Nov 2023 21:17:26 +0100 From: Michal Jires To: gcc-patches@gcc.gnu.org Subject: [PATCH 6/7] lto: squash order of symbols in partitions Message-ID: <1169efeea8ca079fc9297a4f95ad292558b1bbcf.1700222403.git.mjires@suse.cz> References: <18cc1c3980551ac1881eea6e78811a629c7baa82.1700222403.git.mjires@suse.cz> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <18cc1c3980551ac1881eea6e78811a629c7baa82.1700222403.git.mjires@suse.cz> Authentication-Results: smtp-out1.suse.de; none X-Spam-Level: X-Spam-Score: -3.29 X-Spamd-Result: default: False [-3.29 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; MIME_GOOD(-0.10)[text/plain]; PREVIOUSLY_DELIVERED(0.00)[gcc-patches@gcc.gnu.org]; TO_DN_NONE(0.00)[]; RCPT_COUNT_ONE(0.00)[1]; DKIM_SIGNED(0.00)[suse.cz:s=susede2_rsa,suse.cz:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.19)[-0.968]; MID_CONTAINS_FROM(1.00)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_COUNT_TWO(0.00)[2]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-3.00)[100.00%] X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_SOFTFAIL, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782843777913605433 X-GMAIL-MSGID: 1782843777913605433 This patch squashes order of symbols in individual partitions, so that their relative order is conserved, but is not influenced by symbols in other partitions. Order of cloned symbols is set to 0. This should be fine because order specifies order of symbols in input files, which cloned symbols are not part of. This is important for incremental LTO because if there is a new symbol, it otherwise shifts order of all symbols with higher order, which would diverge them all. Bootstrapped/regtested on x86_64-pc-linux-gnu gcc/ChangeLog: * lto-cgraph.cc (lto_output_node): Add and use order_remap. (lto_output_varpool_node): Likewise. (output_symtab): Likewise. * lto-streamer-out.cc (produce_asm): Likewise. (output_function): Likewise. (output_constructor): Likewise. (copy_function_or_variable): Likewise. (cmp_int): New. (lto_output): Generate order_remap. * lto-streamer.h (produce_asm): Add order_remap. (output_symtab): Likewise. --- gcc/lto-cgraph.cc | 20 ++++++++---- gcc/lto-streamer-out.cc | 71 +++++++++++++++++++++++++++++++++-------- gcc/lto-streamer.h | 5 +-- 3 files changed, 73 insertions(+), 23 deletions(-) diff --git a/gcc/lto-cgraph.cc b/gcc/lto-cgraph.cc index 32c0f5ac6db..a7530290fba 100644 --- a/gcc/lto-cgraph.cc +++ b/gcc/lto-cgraph.cc @@ -381,7 +381,8 @@ reachable_from_this_partition_p (struct cgraph_node *node, lto_symtab_encoder_t static void lto_output_node (struct lto_simple_output_block *ob, struct cgraph_node *node, - lto_symtab_encoder_t encoder) + lto_symtab_encoder_t encoder, + hash_map, int>* order_remap) { unsigned int tag; struct bitpack_d bp; @@ -405,7 +406,9 @@ lto_output_node (struct lto_simple_output_block *ob, struct cgraph_node *node, streamer_write_enum (ob->main_stream, LTO_symtab_tags, LTO_symtab_last_tag, tag); - streamer_write_hwi_stream (ob->main_stream, node->order); + + int order = flag_wpa ? *order_remap->get (node->order) : node->order; + streamer_write_hwi_stream (ob->main_stream, order); /* In WPA mode, we only output part of the call-graph. Also, we fake cgraph node attributes. There are two cases that we care. @@ -585,7 +588,8 @@ lto_output_node (struct lto_simple_output_block *ob, struct cgraph_node *node, static void lto_output_varpool_node (struct lto_simple_output_block *ob, varpool_node *node, - lto_symtab_encoder_t encoder) + lto_symtab_encoder_t encoder, + hash_map, int>* order_remap) { bool boundary_p = !lto_symtab_encoder_in_partition_p (encoder, node); bool encode_initializer_p @@ -602,7 +606,8 @@ lto_output_varpool_node (struct lto_simple_output_block *ob, varpool_node *node, streamer_write_enum (ob->main_stream, LTO_symtab_tags, LTO_symtab_last_tag, LTO_symtab_variable); - streamer_write_hwi_stream (ob->main_stream, node->order); + int order = flag_wpa ? *order_remap->get (node->order) : node->order; + streamer_write_hwi_stream (ob->main_stream, order); lto_output_var_decl_ref (ob->decl_state, ob->main_stream, node->decl); bp = bitpack_create (ob->main_stream); bp_pack_value (&bp, node->externally_visible, 1); @@ -967,7 +972,7 @@ compute_ltrans_boundary (lto_symtab_encoder_t in_encoder) /* Output the part of the symtab in SET and VSET. */ void -output_symtab (void) +output_symtab (hash_map, int>* order_remap) { struct cgraph_node *node; struct lto_simple_output_block *ob; @@ -994,9 +999,10 @@ output_symtab (void) { symtab_node *node = lto_symtab_encoder_deref (encoder, i); if (cgraph_node *cnode = dyn_cast (node)) - lto_output_node (ob, cnode, encoder); + lto_output_node (ob, cnode, encoder, order_remap); else - lto_output_varpool_node (ob, dyn_cast (node), encoder); + lto_output_varpool_node (ob, dyn_cast (node), encoder, + order_remap); } /* Go over the nodes in SET again to write edges. */ diff --git a/gcc/lto-streamer-out.cc b/gcc/lto-streamer-out.cc index a1bbea8fc68..9448ab195d5 100644 --- a/gcc/lto-streamer-out.cc +++ b/gcc/lto-streamer-out.cc @@ -2212,7 +2212,8 @@ output_cfg (struct output_block *ob, struct function *fn) a function, set FN to the decl for that function. */ void -produce_asm (struct output_block *ob, tree fn) +produce_asm (struct output_block *ob, tree fn, + hash_map, int>* order_remap) { enum lto_section_type section_type = ob->section_type; struct lto_function_header header; @@ -2221,9 +2222,11 @@ produce_asm (struct output_block *ob, tree fn) if (section_type == LTO_section_function_body) { const char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (fn)); - section_name = lto_get_section_name (section_type, name, - symtab_node::get (fn)->order, - NULL); + + int order = symtab_node::get (fn)->order; + if (flag_wpa && order_remap) + order = *order_remap->get (order); + section_name = lto_get_section_name (section_type, name, order, NULL); } else section_name = lto_get_section_name (section_type, NULL, 0, NULL); @@ -2405,7 +2408,8 @@ streamer_write_chain (struct output_block *ob, tree t, bool ref_p) /* Output the body of function NODE->DECL. */ static void -output_function (struct cgraph_node *node) +output_function (struct cgraph_node *node, + hash_map, int>* order_remap) { tree function; struct function *fn; @@ -2482,7 +2486,7 @@ output_function (struct cgraph_node *node) streamer_write_uhwi (ob, 0); /* Create a section to hold the pickled output of this function. */ - produce_asm (ob, function); + produce_asm (ob, function, order_remap); destroy_output_block (ob); if (streamer_dump_file) @@ -2493,7 +2497,8 @@ output_function (struct cgraph_node *node) /* Output the body of function NODE->DECL. */ static void -output_constructor (struct varpool_node *node) +output_constructor (struct varpool_node *node, + hash_map, int>* order_remap) { tree var = node->decl; struct output_block *ob; @@ -2515,7 +2520,7 @@ output_constructor (struct varpool_node *node) stream_write_tree (ob, DECL_INITIAL (var), true); /* Create a section to hold the pickled output of this function. */ - produce_asm (ob, var); + produce_asm (ob, var, order_remap); destroy_output_block (ob); if (streamer_dump_file) @@ -2576,15 +2581,18 @@ lto_output_toplevel_asms (void) /* Copy the function body or variable constructor of NODE without deserializing. */ static void -copy_function_or_variable (struct symtab_node *node) +copy_function_or_variable (struct symtab_node *node, + hash_map, int>* order_remap) { tree function = node->decl; struct lto_file_decl_data *file_data = node->lto_file_data; const char *data; size_t len; const char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (function)); + + int order = flag_wpa ? *order_remap->get (node->order) : node->order; char *section_name = - lto_get_section_name (LTO_section_function_body, name, node->order, NULL); + lto_get_section_name (LTO_section_function_body, name, order, NULL); size_t i, j; struct lto_in_decl_state *in_state; struct lto_out_decl_state *out_state = lto_get_out_decl_state (); @@ -2729,6 +2737,15 @@ cmp_symbol_files (const void *pn1, const void *pn2, void *id_map_) return n1->order - n2->order; } +/* Compare ints, callback for qsort. */ +static int +cmp_int (const void *a, const void *b) +{ + int ia = *(int const*) a; + int ib = *(int const*) b; + return ia - ib; +} + /* Main entry point from the pass manager. */ void @@ -2741,6 +2758,32 @@ lto_output (void) lto_symtab_encoder_t encoder = lto_get_out_decl_state ()->symtab_node_encoder; auto_vec symbols_to_copy; + hash_map, int> order_remap; + if (flag_wpa) + { + /* Remap order so that it does not depend on symbols outside of + partition. */ + auto_vec orders; + + n_nodes = lto_symtab_encoder_size (encoder); + for (i = 0; i < n_nodes; i++) + { + symtab_node *snode = lto_symtab_encoder_deref (encoder, i); + if (cgraph_node *cnode = dyn_cast (snode)) + { + if (cnode->clone_of) + { + order_remap.put (snode->order, 0); + continue; + } + } + orders.safe_push (snode->order); + } + orders.qsort (cmp_int); + for (i = 0; i < orders.length (); i++) + order_remap.put (orders[i], i); + } + prune_offload_funcs (); if (flag_checking) @@ -2817,14 +2860,14 @@ lto_output (void) at WPA time. */ || DECL_ARGUMENTS (cnode->decl) || cnode->declare_variant_alt)) - output_function (cnode); + output_function (cnode, &order_remap); else if ((vnode = dyn_cast (snode)) && (DECL_INITIAL (vnode->decl) != error_mark_node || (!flag_wpa && flag_incremental_link != INCREMENTAL_LINK_LTO))) - output_constructor (vnode); + output_constructor (vnode, &order_remap); else - copy_function_or_variable (snode); + copy_function_or_variable (snode, &order_remap); gcc_assert (lto_get_out_decl_state () == decl_state); lto_pop_out_decl_state (); lto_record_function_out_decl_state (snode->decl, decl_state); @@ -2834,7 +2877,7 @@ lto_output (void) be done now to make sure that all the statements in every function have been renumbered so that edges can be associated with call statements using the statement UIDs. */ - output_symtab (); + output_symtab (&order_remap); output_offload_tables (); diff --git a/gcc/lto-streamer.h b/gcc/lto-streamer.h index 0556b34c837..3363e6f9e61 100644 --- a/gcc/lto-streamer.h +++ b/gcc/lto-streamer.h @@ -888,7 +888,8 @@ extern void lto_output_fn_decl_ref (struct lto_out_decl_state *, extern tree lto_input_var_decl_ref (lto_input_block *, lto_file_decl_data *); extern tree lto_input_fn_decl_ref (lto_input_block *, lto_file_decl_data *); extern void lto_output_toplevel_asms (void); -extern void produce_asm (struct output_block *ob, tree fn); +extern void produce_asm (struct output_block *ob, tree fn, + hash_map, int>* order_remap = 0); extern void lto_output (); extern void produce_asm_for_decls (); void lto_output_decl_state_streams (struct output_block *, @@ -919,7 +920,7 @@ void lto_set_symtab_encoder_in_partition (lto_symtab_encoder_t, bool lto_symtab_encoder_encode_initializer_p (lto_symtab_encoder_t, varpool_node *); -void output_symtab (void); +void output_symtab (hash_map, int>*); void input_symtab (void); void output_offload_tables (void); void input_offload_tables (bool);