From patchwork Wed Nov 13 06:28:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Strager Neds X-Patchwork-Id: 1194069 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-513187-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="Jai6keBt"; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="Z44ApCBY"; dkim-atps=neutral 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 47CZSD4vZSz9sNH for ; Wed, 13 Nov 2019 17:28:27 +1100 (AEDT) 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:from:date:message-id:subject:to:content-type; q= dns; s=default; b=EbNFg2z7gH2kL+Q/omIy0tFJHSh1sYOWWAfTsQbfATCv0w 4D22Dk9DvOzbaX1DqZ5UULm1nU9G8FtK4zMO6qyjkbRFsnbwZl4aXcIzKxG7qEcd azRXv3xcXvfLQh+MkUF84AthfDCMie/Wiz2AwyT0jmOiW89Ii/TisvQRl77w0= 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:from:date:message-id:subject:to:content-type; s= default; bh=Qghg7g3+tERle8Gpk47DAR59ZRY=; b=Jai6keBtETuNi8VajZAv LumfaRXH01nbSXUwQZWKe0iUAtXUY/DO4AZAGssw/i9nw1pi3bKCmeDhP7nyZv5m DrK1sdh9mKXWr28eEF+aZ6GYL2rPzX0pU7Nehm1P3Ac//ANRwfBuehR7nx7jCb/a 4apE71kArnsQoWqzCqXOwfc= Received: (qmail 39582 invoked by alias); 13 Nov 2019 06:28:19 -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 39574 invoked by uid 89); 13 Nov 2019 06:28:19 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-22.7 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy=transparent, DECL_EXTERNAL, sk:decl_co, methodc X-HELO: mail-io1-f66.google.com Received: from mail-io1-f66.google.com (HELO mail-io1-f66.google.com) (209.85.166.66) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 13 Nov 2019 06:28:16 +0000 Received: by mail-io1-f66.google.com with SMTP id k1so1267279ioj.6 for ; Tue, 12 Nov 2019 22:28:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=EoI6KzDOKBpsdjsqG4r9KOQvORtqSGaxqqcYfsK/+SM=; b=Z44ApCBYGYhU7nuc/peQC+K8n2S/UEPuUQCTykq/JKnsAmkKwKh7lmuXWFzklr92v5 fKcyA51QLlMmDRQ23P4nVkrc16fRurxJytVigql31OfNysjA2mi0UZtnt08+8kv3lAjA qT2z0Jz5v5qkS4RNMMMaQ6sjZZqFWG6EVb+iiZ9fXn4+FXv8Y020G1DiTrCoWsJUR/Kq +ly64lJ2bl3JZRkAWQXZkM0MbQTJu+LQvQo8/JQ2uwXsAud3J9GjsJ6w9UrmCLvOmAwA vHlyAJRQNNnFjQgVzlO3VcoFKfOMYSb6XFnjJbW89gRx+t70rGZ3BDdIrYePzOvjVui6 Ne6A== MIME-Version: 1.0 From: Strager Neds Date: Tue, 12 Nov 2019 22:28:02 -0800 Message-ID: Subject: [PATCH 1/3] Refactor copying decl section names To: gcc-patches@gcc.gnu.org Sometimes, we need to copy a section name from one decl or symtab node to another. Currently, this is done by getting the source's section name and setting the destination's section name. For example: set_decl_section_name (dest, DECL_SECTION_NAME (source)); dest->set_section (source->get_section ()); This code could be more efficient. Section names are stored in an interning hash table, but the current interfaces of set_decl_section_name and symtab_node::set_section force unnecessary indirections (to get the section name) and hashing (to find the section name in the hash table). Overload set_decl_section_name and symtab_node::set_section to accept an existing symtab_node to copy the section name from: set_decl_section_name (dest, source); dest->set_section (*source); For now, implement these new functions as a simple wrapper around the existing functions. In the future, these functions can be implemented using just a pointer copy and an increment (for the reference count). This patch should not change behavior. Testing: Bootstrap on x86_64-linux-gnu with --disable-multilib --enable-checking=release --enable-languages=c,c++. Observe no change in test results. 2019-11-12 Matthew Glazar * gcc/cgraph.h (symtab_node::get_section): Constify. (symtab_node::set_section): Declare new overload. * gcc/symtab.c (symtab_node::set_section): Define new overload. (symtab_node::copy_visibility_from): Use new overload of symtab_node::set_section. (symtab_node::resolve_alias): Same. * gcc/tree.h (set_decl_section_name): Declare new overload. * gcc/tree.c (set_decl_section_name): Define new overload. * gcc/c/c-decl.c (merge_decls): Use new overload of set_decl_section_name. * gcc/cp/decl.c (duplicate_decls): Same. * gcc/cp/method.c (use_thunk): Same. * gcc/cp/optimize.c (maybe_clone_body): Same. * gcc/d/decl.cc (finish_thunk): Same. * gcc/tree-emutls.c (get_emutls_init_templ_addr): Same. * gcc/cgraphclones.c (cgraph_node::create_virtual_clone): Use new overload of symtab_node::set_section. (cgraph_node::create_version_clone_with_body): Same. * gcc/trans-mem.c (ipa_tm_create_version): Same. diff --git a/gcc/c/c-decl.c b/gcc/c/c-decl.c index 2841b4f5a77..366fbf2a28a 100644 --- a/gcc/c/c-decl.c +++ b/gcc/c/c-decl.c @@ -2845,7 +2845,7 @@ merge_decls (tree newdecl, tree olddecl, tree newtype, tree oldtype) || TREE_PUBLIC (olddecl) || TREE_STATIC (olddecl)) && DECL_SECTION_NAME (newdecl) != NULL) - set_decl_section_name (olddecl, DECL_SECTION_NAME (newdecl)); + set_decl_section_name (olddecl, newdecl); /* This isn't quite correct for something like int __thread x attribute ((tls_model ("local-exec"))); diff --git a/gcc/cgraph.h b/gcc/cgraph.h index 0abde3d8f91..3b07258b31d 100644 --- a/gcc/cgraph.h +++ b/gcc/cgraph.h @@ -246,7 +246,7 @@ public: } /* Return section as string. */ - const char * get_section () + const char * get_section () const { if (!x_section) return NULL; @@ -305,6 +305,9 @@ public: /* Set section for symbol and its aliases. */ void set_section (const char *section); + /* Like set_section, but copying the section name from another node. */ + void set_section (const symtab_node &other); + /* Set section, do not recurse into aliases. When one wants to change section of symbol and its aliases, use set_section. */ diff --git a/gcc/cgraphclones.c b/gcc/cgraphclones.c index 41a600e64a5..0b1c93534f2 100644 --- a/gcc/cgraphclones.c +++ b/gcc/cgraphclones.c @@ -572,7 +572,7 @@ cgraph_node::create_virtual_clone (vec redirect_callers, set_new_clone_decl_and_node_flags (new_node); new_node->clone.tree_map = tree_map; if (!implicit_section) - new_node->set_section (get_section ()); + new_node->set_section (*this); /* Clones of global symbols or symbols with unique names are unique. */ if ((TREE_PUBLIC (old_decl) @@ -996,7 +996,7 @@ cgraph_node::create_version_clone_with_body new_version_node->local = 1; new_version_node->lowered = true; if (!implicit_section) - new_version_node->set_section (get_section ()); + new_version_node->set_section (*this); /* Clones of global symbols or symbols with unique names are unique. */ if ((TREE_PUBLIC (old_decl) && !DECL_EXTERNAL (old_decl) diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 5c5a85e3221..ed4034f8e9d 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -2830,7 +2830,7 @@ duplicate_decls (tree newdecl, tree olddecl, bool newdecl_is_friend) done later in decl_attributes since we are called before attributes are assigned. */ if (DECL_SECTION_NAME (newdecl) != NULL) - set_decl_section_name (olddecl, DECL_SECTION_NAME (newdecl)); + set_decl_section_name (olddecl, newdecl); if (DECL_ONE_ONLY (newdecl)) { diff --git a/gcc/cp/method.c b/gcc/cp/method.c index 47441c10c52..d111792af5b 100644 --- a/gcc/cp/method.c +++ b/gcc/cp/method.c @@ -351,7 +351,7 @@ use_thunk (tree thunk_fndecl, bool emit_p) resolve_unique_section (thunk_fndecl, 0, flag_function_sections); /* Output the thunk into the same section as function. */ - set_decl_section_name (thunk_fndecl, DECL_SECTION_NAME (fn)); + set_decl_section_name (thunk_fndecl, fn); symtab_node::get (thunk_fndecl)->implicit_section = symtab_node::get (fn)->implicit_section; } diff --git a/gcc/cp/optimize.c b/gcc/cp/optimize.c index 994ee9148c0..707ccdafcdb 100644 --- a/gcc/cp/optimize.c +++ b/gcc/cp/optimize.c @@ -518,7 +518,7 @@ maybe_clone_body (tree fn) DECL_DLLIMPORT_P (clone) = DECL_DLLIMPORT_P (fn); DECL_ATTRIBUTES (clone) = copy_list (DECL_ATTRIBUTES (fn)); DECL_DISREGARD_INLINE_LIMITS (clone) = DECL_DISREGARD_INLINE_LIMITS (fn); - set_decl_section_name (clone, DECL_SECTION_NAME (fn)); + set_decl_section_name (clone, fn); /* Adjust the parameter names and locations. */ parm = DECL_ARGUMENTS (fn); diff --git a/gcc/d/decl.cc b/gcc/d/decl.cc index bcce245e59c..d6c934b1163 100644 --- a/gcc/d/decl.cc +++ b/gcc/d/decl.cc @@ -1677,7 +1677,7 @@ finish_thunk (tree thunk, tree function) resolve_unique_section (thunk, 0, flag_function_sections); /* Output the thunk into the same section as function. */ - set_decl_section_name (thunk, DECL_SECTION_NAME (fn)); + set_decl_section_name (thunk, fn); symtab_node::get (thunk)->implicit_section = symtab_node::get (fn)->implicit_section; } diff --git a/gcc/symtab.c b/gcc/symtab.c index 3e634e22c86..84d17c36189 100644 --- a/gcc/symtab.c +++ b/gcc/symtab.c @@ -1418,8 +1418,7 @@ symtab_node::copy_visibility_from (symtab_node *n) DECL_DLLIMPORT_P (decl) = DECL_DLLIMPORT_P (n->decl); resolution = n->resolution; set_comdat_group (n->get_comdat_group ()); - call_for_symbol_and_aliases (symtab_node::set_section, - const_cast(n->get_section ()), true); + set_section (*n); externally_visible = n->externally_visible; if (!DECL_RTL_SET_P (decl)) return; @@ -1605,6 +1604,14 @@ symtab_node::set_section (const char *section) (symtab_node::set_section, const_cast(section), true); } +void +symtab_node::set_section (const symtab_node &other) +{ + const char *section = other.get_section (); + call_for_symbol_and_aliases + (symtab_node::set_section, const_cast(section), true); +} + /* Return the initialization priority. */ priority_type @@ -1748,8 +1755,7 @@ symtab_node::resolve_alias (symtab_node *target, bool transparent) { error ("section of alias %q+D must match section of its target", decl); } - call_for_symbol_and_aliases (symtab_node::set_section, - const_cast(target->get_section ()), true); + set_section (*target); if (target->implicit_section) call_for_symbol_and_aliases (set_implicit_section, NULL, true); diff --git a/gcc/trans-mem.c b/gcc/trans-mem.c index 2e775286540..a2023d60ea0 100644 --- a/gcc/trans-mem.c +++ b/gcc/trans-mem.c @@ -4994,7 +4994,7 @@ ipa_tm_create_version (struct cgraph_node *old_node) new_node->lowered = true; new_node->tm_clone = 1; if (!old_node->implicit_section) - new_node->set_section (old_node->get_section ()); + new_node->set_section (*old_node); get_cg_data (&old_node, true)->clone = new_node; if (old_node->get_availability () >= AVAIL_INTERPOSABLE) diff --git a/gcc/tree-emutls.c b/gcc/tree-emutls.c index 6fc8370f42c..b7b0a57bde4 100644 --- a/gcc/tree-emutls.c +++ b/gcc/tree-emutls.c @@ -259,7 +259,7 @@ get_emutls_init_templ_addr (tree decl) if (targetm.emutls.tmpl_section) set_decl_section_name (to, targetm.emutls.tmpl_section); else - set_decl_section_name (to, DECL_SECTION_NAME (decl)); + set_decl_section_name (to, decl); /* Create varpool node for the new variable and finalize it if it is not external one. */ diff --git a/gcc/tree.c b/gcc/tree.c index d2c9fe35995..0c5b88302b7 100644 --- a/gcc/tree.c +++ b/gcc/tree.c @@ -774,6 +774,33 @@ set_decl_section_name (tree node, const char *value) snode->set_section (value); } +/* Set section name of NODE to match the section name of OTHER. + + set_decl_section_name (decl, other) is equivalent to + set_decl_section_name (decl, DECL_SECTION_NAME (other)), but possibly more + efficient. */ +void +set_decl_section_name (tree decl, const_tree other) +{ + struct symtab_node *other_node = symtab_node::get (other); + if (other_node) + { + struct symtab_node *decl_node; + if (VAR_P (decl)) + decl_node = varpool_node::get_create (decl); + else + decl_node = cgraph_node::get_create (decl); + decl_node->set_section (*other_node); + } + else + { + struct symtab_node *decl_node = symtab_node::get (decl); + if (!decl_node) + return; + decl_node->set_section (NULL); + } +} + /* Return TLS model of a variable NODE. */ enum tls_model decl_tls_model (const_tree node) diff --git a/gcc/tree.h b/gcc/tree.h index a7d39c3a74d..91e519cdb83 100644 --- a/gcc/tree.h +++ b/gcc/tree.h @@ -4241,6 +4241,7 @@ extern tree decl_comdat_group (const_tree); extern tree decl_comdat_group_id (const_tree); extern const char *decl_section_name (const_tree); extern void set_decl_section_name (tree, const char *); +extern void set_decl_section_name (tree, const_tree); extern enum tls_model decl_tls_model (const_tree); extern void set_decl_tls_model (tree, enum tls_model); From patchwork Wed Nov 13 06:28:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Strager Neds X-Patchwork-Id: 1194070 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-513188-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="cQk+asot"; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="Sd98qfh0"; dkim-atps=neutral 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 47CZSx3lLLz9sNH for ; Wed, 13 Nov 2019 17:29:05 +1100 (AEDT) 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:references:in-reply-to:from:date:message-id :subject:to:content-type; q=dns; s=default; b=vQCi+w93D/c5sQKWaF 6qVNZbVNiSYXfusac2UC9fTYID5MQ5ZTBHr/6C0DEP9BucWUH6LH73m9Rh7JZWKN /x9MEkc4bcd5TN+TlYt12Hh2Z1Y0i0YgSfKRiyf6k5x19dw6Chd1xaAhepBLN1gH wftYYqpaB7jdsN8y5lDwyUbPE= 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:references:in-reply-to:from:date:message-id :subject:to:content-type; s=default; bh=FgaB48twDawX5DI5OGeRF9vI T3c=; b=cQk+asotur9NUt+N1i6iHEKfflrCVYPTFqKKVspRNdBcnHuZKoQsKOYY FBzj0C7OfSR2KF5jKRX2dR8BLk2CoXwJYvgIqZnvRJLrwQK296OMwGBjgOK+baBi pG/duE+OVpMTPm+0j7vpPGD8WX9lQo8xpeKavRcb3edGkz/QVp8= Received: (qmail 41347 invoked by alias); 13 Nov 2019 06:28:58 -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 41338 invoked by uid 89); 13 Nov 2019 06:28:58 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-23.8 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy= X-HELO: mail-il1-f170.google.com Received: from mail-il1-f170.google.com (HELO mail-il1-f170.google.com) (209.85.166.170) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 13 Nov 2019 06:28:54 +0000 Received: by mail-il1-f170.google.com with SMTP id s5so748261iln.4 for ; Tue, 12 Nov 2019 22:28:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=+hbRkiKc8+KufAJPdSvF649ki5xtR0xDxZrqp02lF3I=; b=Sd98qfh0xx481bMJddrDtAGTm2/FGrkzvwgCSS0TsOBdu47MriB+A2YGwmsPvvsTF7 O4sZnHg/UkD65z73dERgeOBTASY9OVfffVzxg1MMCe3T8bxfd5EBYcobr2ss6ynz1ABv p4rqgdMwujK4FmLflsF1lZpEVT3+bhAg79KQujn73uCLF6cYX/z+wIxCxxjZaf1Kc3JM N9WFDr/gykpzA+ZqrZSy3MseUjX5G/F0jV4rV98Nemt3C6Ju0RjwJVNq8J2VT5cLskD7 uF4CY4uzgbJSHmQsXBxm/DflzlhwbwnGYQNI0Te2qXilL8yeTi52q3xkLE8XG9klowiq bsfw== MIME-Version: 1.0 References: In-Reply-To: From: Strager Neds Date: Tue, 12 Nov 2019 22:28:41 -0800 Message-ID: Subject: [PATCH 2/3] Refactor section name ref counting To: gcc-patches@gcc.gnu.org symtab_node::set_section_for_node manages the reference count of section_hash_entry objects. I plan to add another function which needs to manage the reference count of these objects. To avoid duplicating code, factor the existing logic into reusable functions. This patch should not change behavior. Testing: Bootstrap on x86_64-linux-gnu with --disable-multilib --enable-checking=release --enable-languages=c,c++. Observe no change in test results. 2019-11-12 Matthew Glazar * gcc/symtab.c (symtab_node::set_section_for_node): Extract reference counting logic into ... (retain_section_hash_entry): ... here (new function) and ... (release_section_hash_entry): ... here (new function). cgraph/varpool node creation routines. */ @@ -1543,46 +1567,33 @@ void symtab_node::set_section_for_node (const char *section) { const char *current = get_section (); - section_hash_entry **slot; if (current == section || (current && section && !strcmp (current, section))) return; - if (current) - { - x_section->ref_count--; - if (!x_section->ref_count) - { - hashval_t hash = htab_hash_string (x_section->name); - slot = symtab->section_hash->find_slot_with_hash (x_section->name, - hash, INSERT); - ggc_free (x_section); - symtab->section_hash->clear_slot (slot); - } - x_section = NULL; - } + release_section_hash_entry (x_section); if (!section) { + x_section = NULL; implicit_section = false; return; } if (!symtab->section_hash) symtab->section_hash = hash_table::create_ggc (10); - slot = symtab->section_hash->find_slot_with_hash (section, - htab_hash_string (section), - INSERT); + section_hash_entry **slot = symtab->section_hash->find_slot_with_hash + (section, htab_hash_string (section), INSERT); if (*slot) - x_section = (section_hash_entry *)*slot; + x_section = retain_section_hash_entry (*slot); else { int len = strlen (section); *slot = x_section = ggc_cleared_alloc (); + x_section->ref_count = 1; x_section->name = ggc_vec_alloc (len + 1); memcpy (x_section->name, section, len + 1); } - x_section->ref_count++; } /* Worker for set_section. */ diff --git a/gcc/symtab.c b/gcc/symtab.c index 84d17c36189..a2aa519e760 100644 --- a/gcc/symtab.c +++ b/gcc/symtab.c @@ -368,6 +368,30 @@ section_name_hasher::equal (section_hash_entry *n1, const char *name) return n1->name == name || !strcmp (n1->name, name); } +static section_hash_entry * +retain_section_hash_entry (section_hash_entry *entry) +{ + entry->ref_count++; + return entry; +} + +static void +release_section_hash_entry (section_hash_entry *entry) +{ + if (entry) + { + entry->ref_count--; + if (!entry->ref_count) + { + hashval_t hash = htab_hash_string (entry->name); + section_hash_entry **slot = symtab->section_hash->find_slot_with_hash (entry->name, + hash, INSERT); + ggc_free (entry); + symtab->section_hash->clear_slot (slot); + } + } +} + /* Add node into symbol table. This function is not used directly, but via From patchwork Wed Nov 13 06:29:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Strager Neds X-Patchwork-Id: 1194071 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-513189-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="DNZEg1GN"; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="q0D3c6V9"; dkim-atps=neutral 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 47CZTX4L9qz9sNH for ; Wed, 13 Nov 2019 17:29:36 +1100 (AEDT) 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:references:in-reply-to:from:date:message-id :subject:to:content-type; q=dns; s=default; b=gRhfqS5OBJpv696uyJ wP2qrLQ4Dpqsfkdq/Ub9xu9K+KsvQ5Rsqim67PBVB7UMQx9l87ElgoiBS7jhvctc y8zj9JQSyV9miHxKlYG/WFCfI8dj4YwSLRH/Nhquh4UPG8OKoxdAp4wDo/vwLHKs qn19945+tim3qTX9lVDREZwys= 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:references:in-reply-to:from:date:message-id :subject:to:content-type; s=default; bh=dm/0s5Xa6K9iAeZnpSIhd99h HP4=; b=DNZEg1GNzQLclJDS/exjCN6Ie6KdxiyjZu0Zt5P9q2nHzAgmZDjHapRl i6KnvXCpPkwNxcvhIDepA9N21zDqbSRCMZv00HAFzDQeUwEZJ1Ww0TuxK9bjoN7d +cyMFlfk1YaPUzVy2tBMLDwSYuG4D1CP74QMqDz63qm6+B8UL0M= Received: (qmail 43620 invoked by alias); 13 Nov 2019 06:29:29 -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 43612 invoked by uid 89); 13 Nov 2019 06:29:29 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-24.4 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy= X-HELO: mail-io1-f65.google.com Received: from mail-io1-f65.google.com (HELO mail-io1-f65.google.com) (209.85.166.65) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 13 Nov 2019 06:29:26 +0000 Received: by mail-io1-f65.google.com with SMTP id j13so1314042ioe.0 for ; Tue, 12 Nov 2019 22:29:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=Gf7koB3NjK+yLwxSU6n5UuuIwOOUZUYuvhf4JsKIvkE=; b=q0D3c6V9lus3rp6FUJhocDo/KegVrXiM15UyWUQajD1keR+XTqkLkUYF9tf9odtxSG wS/ACCT7NzIMwjovD3TomV36i6ryPYYMZZeD0LvXGwlyN1ZQ7AlPu0sBn7ab+dcVfga4 kw3TayJ/vImfJWD6Cj7oCAEqt01z3qnvp+Vgu1p/hz4JrpsJZpWIrLZoUaZ/cqwBnaKf aUOKu4vgbA3NVrZ5kRveQrlIiKYubfZud8D2ma3Ww0efwyAe3WmnQyfbhjFbeGtvWVGb 6kQdDPfURWze/ahVv/Ty9GkSGjgJADOoWs1hk3gH2faJkj8ZB2HycrIgyQe+XCXD7YrP /CIQ== MIME-Version: 1.0 References: In-Reply-To: From: Strager Neds Date: Tue, 12 Nov 2019 22:29:12 -0800 Message-ID: Subject: [PATCH 3/3] Improve efficiency of copying section from another tree To: gcc-patches@gcc.gnu.org Several parts of GCC need to copy a section name from one tree (or symtab_node) to another. Currently, this is implemented naively: 1. Query the source's section name 2. Hash the section name string 3. Find the section_hash_entry in the symbol table 4. Increment the section_hash_entry's reference count 5. Assign the destination's section to the section_hash_entry Since we have the source's section_hash_entry, we can copy the section name from one symtab_node to another efficiently with the following algorithm: 1. Query the source's section_hash_entry 2. Increment the section_hash_entry's reference count 3. Assign the destination's section to the section_hash_entry Implement this algorithm in the overload of symtab_node::set_section which takes an existing symtab_node. I did not measure the performance impact of this patch. In particular, I do not know if this patch actually improves performance. This patch should not change behavior. Testing: Bootstrap on x86_64-linux-gnu with --disable-multilib --enable-checking=release --enable-languages=c,c++. Observe no change in test results. 2019-11-12 Matthew Glazar * gcc/cgraph.h (symtab_node::set_section_for_node): Declare new overload. (symtab_node::set_section_from_string): Rename from set_section. (symtab_node::set_section_from_node): Declare. * gcc/symtab.c (symtab_node::set_section_for_node): Define new overload. (symtab_node::set_section_from_string): Rename from set_section. (symtab_node::set_section_from_node): Define. (symtab_node::set_section): Call renamed set_section_from_string. (symtab_node::set_section): Call new set_section_from_node. /* Return the initialization priority. */ diff --git a/gcc/cgraph.h b/gcc/cgraph.h index 3b07258b31d..928a8bc2729 100644 --- a/gcc/cgraph.h +++ b/gcc/cgraph.h @@ -313,6 +313,10 @@ public: use set_section. */ void set_section_for_node (const char *section); + /* Like set_section_for_node, but copying the section name from another + node. */ + void set_section_for_node (const symtab_node &other); + /* Set initialization priority to PRIORITY. */ void set_init_priority (priority_type priority); @@ -627,8 +631,9 @@ protected: void *data, bool include_overwrite); private: - /* Worker for set_section. */ - static bool set_section (symtab_node *n, void *s); + /* Workers for set_section. */ + static bool set_section_from_string (symtab_node *n, void *s); + static bool set_section_from_node (symtab_node *n, void *o); /* Worker for symtab_resolve_alias. */ static bool set_implicit_section (symtab_node *n, void *); diff --git a/gcc/symtab.c b/gcc/symtab.c index a2aa519e760..40752addcb6 100644 --- a/gcc/symtab.c +++ b/gcc/symtab.c @@ -1596,15 +1596,37 @@ symtab_node::set_section_for_node (const char *section) } } -/* Worker for set_section. */ +void +symtab_node::set_section_for_node (const symtab_node &other) +{ + if (x_section == other.x_section) + return; + if (get_section () && other.get_section ()) + gcc_checking_assert (strcmp (get_section (), other.get_section ()) != 0); + release_section_hash_entry (x_section); + if (other.x_section) + x_section = retain_section_hash_entry (other.x_section); + else + x_section = NULL; +} + +/* Workers for set_section. */ bool -symtab_node::set_section (symtab_node *n, void *s) +symtab_node::set_section_from_string (symtab_node *n, void *s) { n->set_section_for_node ((char *)s); return false; } +bool +symtab_node::set_section_from_node (symtab_node *n, void *o) +{ + const symtab_node &other = *static_cast (o); + n->set_section_for_node (other); + return false; +} + /* Set section of symbol and its aliases. */ void @@ -1612,15 +1634,14 @@ symtab_node::set_section (const char *section) { gcc_assert (!this->alias || !this->analyzed); call_for_symbol_and_aliases - (symtab_node::set_section, const_cast(section), true); + (symtab_node::set_section_from_string, const_cast(section), true); } void symtab_node::set_section (const symtab_node &other) { - const char *section = other.get_section (); call_for_symbol_and_aliases - (symtab_node::set_section, const_cast(section), true); + (symtab_node::set_section_from_node, const_cast(&other), true); }