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); }