From patchwork Fri Nov 17 20:17:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Michal_Jire=C5=A1?= X-Patchwork-Id: 1865208 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=suse.cz header.i=@suse.cz header.a=rsa-sha256 header.s=susede2_rsa header.b=qY3mjI+A; dkim=pass header.d=suse.cz header.i=@suse.cz header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=ggdqQt7q; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4SX7XN3xhMz1yRV for ; Sat, 18 Nov 2023 07:19:00 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 27D373858422 for ; Fri, 17 Nov 2023 20:18:58 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by sourceware.org (Postfix) with ESMTPS id CA0693857B8B for ; Fri, 17 Nov 2023 20:17:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CA0693857B8B Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.cz ARC-Filter: OpenARC Filter v1.0.0 sourceware.org CA0693857B8B Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=195.135.220.29 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700252258; cv=none; b=Gc0O5uUwsOPSMc+FHbnR2g+UTs8kFWiA5dh4gh6s7e5GJ+v64gNk9gvRTwcItnw+RAN6DZoQHf+i9Mc0dTSwK0nahSq9jG0xqNuslo/d6SEuPfj74cXZ2j08Gw2p0XIEj8CggS83T3xM+J6wAaRSftdqvzTDTpD2IJ4I3zDrhAM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700252258; c=relaxed/simple; bh=XqZfn1Klj0awjdeMxfSv9n8ID2VjvGYG3bvTQoL4tWo=; h=DKIM-Signature:DKIM-Signature:Date:From:To:Subject:Message-ID: MIME-Version; b=B1mYqTdJNOMQVeKPhcRu8yFasO7Ut7s8264YWKL6iqgd84l00xsa4D2xkP9WtP8tX+7yT5PiBuQWRga1CXKzBvU5Yv/Q+ZEhg4Al9trWAeqA+xCkPMudFnnC7m1CS0EgLCPubt46v0Irhfnv4gLQN+A5k8wkpXit40i8N+4UwnY= 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-out2.suse.de (Postfix) with ESMTPS id E71AA1F37E for ; Fri, 17 Nov 2023 20:17:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1700252255; 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=+weIGxwXo/8De0+gZFSXrhCKLRAnzFdsl4El7qME/iI=; b=qY3mjI+A4vx83qdUCF/JMNvfDoR0+U+XGEmvST0iR6GaeQm7nsLhG7MD+QQaVePdc9iLTe 7JJKLbEGpU7s2ruCu8bWHQ/ChwZsMdcXFal/0iqf4EwQYtx5/VQTvw/w+Zf7Ss4WUDP1tM 6Ex0m9fpNPifqGBp8tMZi5tYWID9vEw= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1700252255; 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=+weIGxwXo/8De0+gZFSXrhCKLRAnzFdsl4El7qME/iI=; b=ggdqQt7qkeSjrNeWHw6XEfu7mluJPT3abtHlPhApAClR8zfSyqQDudovumgOFdJAQbVzd7 tOwDjp13MQ1mzdAg== 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 D02E41341F for ; Fri, 17 Nov 2023 20:17:35 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id qJEGMV/KV2VnGgAAMHmgww (envelope-from ) for ; Fri, 17 Nov 2023 20:17:35 +0000 Date: Fri, 17 Nov 2023 21:17:34 +0100 From: Michal Jires To: gcc-patches@gcc.gnu.org Subject: [PATCH 7/7] lto: partition specific lto_clone_numbers Message-ID: <7c76f258995c20eb0b44eb021f44039718dc45ce.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-out2.suse.de; none X-Spam-Level: X-Spam-Score: -3.02 X-Spamd-Result: default: False [-3.02 / 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)[]; CLAM_VIRUS_FAIL(0.00)[failed to scan and retransmits exceed]; RCPT_COUNT_ONE(0.00)[1]; DKIM_SIGNED(0.00)[suse.cz:s=susede2_rsa,suse.cz:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.17)[-0.859]; 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(-2.75)[98.89%] X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, 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+incoming=patchwork.ozlabs.org@gcc.gnu.org Replaces "lto_priv.$clone_number" by "lto_priv.$partition_hash.$partition_specific_clone_number". To reduce divergence for incremental LTO. Bootstrapped/regtested on x86_64-pc-linux-gnu gcc/lto/ChangeLog: * lto-partition.cc (set_clone_partition_name_checksum): New. (CHECKSUM_STRING): New. (privatize_symbol_name_1): Use partition hash for lto_priv. (lto_promote_cross_file_statics): Use set_clone_partition_name_checksum. (lto_promote_statics_nonwpa): Changed clone_map type. --- gcc/lto/lto-partition.cc | 49 +++++++++++++++++++++++++++++++++++----- 1 file changed, 43 insertions(+), 6 deletions(-) diff --git a/gcc/lto/lto-partition.cc b/gcc/lto/lto-partition.cc index eb31ecba0d3..a2ce24eea23 100644 --- a/gcc/lto/lto-partition.cc +++ b/gcc/lto/lto-partition.cc @@ -35,6 +35,7 @@ along with GCC; see the file COPYING3. If not see #include "ipa-fnsummary.h" #include "lto-partition.h" #include "sreal.h" +#include "md5.h" #include #include @@ -1516,8 +1517,36 @@ validize_symbol_for_target (symtab_node *node) } } -/* Maps symbol names to unique lto clone counters. */ -static hash_map *lto_clone_numbers; +/* Maps symbol names with partition checksum to unique lto clone counters. */ +using clone_map = hash_map>, unsigned>; +static clone_map *lto_clone_numbers; +uint64_t current_partition_checksum = 0; + +/* Computes a quick checksum to distinguish partitions of clone numbers. */ +void +set_clone_partition_name_checksum (ltrans_partition part) +{ +#define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), &ctx) + struct md5_ctx ctx; + md5_init_ctx (&ctx); + + CHECKSUM_STRING (part->name); + + lto_symtab_encoder_iterator lsei; + lto_symtab_encoder_t encoder = part->encoder; + + for (lsei = lsei_start (encoder); !lsei_end_p (lsei); lsei_next (&lsei)) + { + symtab_node *node = lsei_node (lsei); + CHECKSUM_STRING (node->name ()); + } + + uint64_t checksum[2]; + md5_finish_ctx (&ctx, checksum); + current_partition_checksum = checksum[0]; +#undef CHECKSUM_STRING +} /* Helper for privatize_symbol_name. Mangle NODE symbol name represented by DECL. */ @@ -1531,10 +1560,16 @@ privatize_symbol_name_1 (symtab_node *node, tree decl) return false; const char *name = maybe_rewrite_identifier (name0); - unsigned &clone_number = lto_clone_numbers->get_or_insert (name); + + unsigned &clone_number = lto_clone_numbers->get_or_insert ( + std::pair {name, current_partition_checksum}); + + char lto_priv[32]; + sprintf (lto_priv, "lto_priv.%lu", current_partition_checksum); + symtab->change_decl_assembler_name (decl, clone_function_name ( - name, "lto_priv", clone_number)); + name, lto_priv, clone_number)); clone_number++; if (node->lto_file_data) @@ -1735,11 +1770,13 @@ lto_promote_cross_file_statics (void) part->encoder = compute_ltrans_boundary (part->encoder); } - lto_clone_numbers = new hash_map; + lto_clone_numbers = new clone_map; /* Look at boundaries and promote symbols as needed. */ for (i = 0; i < n_sets; i++) { + set_clone_partition_name_checksum (ltrans_partitions[i]); + lto_symtab_encoder_iterator lsei; lto_symtab_encoder_t encoder = ltrans_partitions[i]->encoder; @@ -1778,7 +1815,7 @@ lto_promote_statics_nonwpa (void) { symtab_node *node; - lto_clone_numbers = new hash_map; + lto_clone_numbers = new clone_map; FOR_EACH_SYMBOL (node) { rename_statics (NULL, node);