From patchwork Fri Jan 6 21:25:19 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 90234 Delivered-To: patch@linaro.org Received: by 10.140.20.101 with SMTP id 92csp9629042qgi; Fri, 6 Jan 2017 13:25:46 -0800 (PST) X-Received: by 10.84.167.168 with SMTP id d37mr170437081plb.71.1483737946403; Fri, 06 Jan 2017 13:25:46 -0800 (PST) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id 23si80725943pfy.91.2017.01.06.13.25.46 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 06 Jan 2017 13:25:46 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-return-445609-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org; spf=pass (google.com: domain of gcc-patches-return-445609-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-445609-patch=linaro.org@gcc.gnu.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to:cc :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=HzJXWwLixpmic/cxmNRVxRo9kRgDl2l/IjIOhoR9EcU2Wv4s1e n7R/+dsfhzU2W/654FyAkRnubsYQb/n3n5eHypgN2zAO5AlfI7zS2TkxjSGFZeSC 0/09p9j5QcLBE/FETGBjqW8KSd15qPiq+0Pte/ApslAgOGhG/WRoqCrr4= 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:to:cc :from:subject:message-id:date:mime-version:content-type; s= default; bh=HqUFTYFuOy8jOytb4xvxa2/dRtE=; b=a/SMgtAISw26n5pd4aCs q2SUVSKQClFg8M3FLsnSyk7dlpV7ZCDDEc3e4VY1SiOov4vJWHjzklbrj5aSnQoW pbzV4l18+4fL0V5E9K/qMz6RfH2GkyBQze2PsUNB6ZE3T0ywQhqxOF9bNfxTlT0I tRwXVeHntr6qnR2uL9PcjhU= Received: (qmail 61352 invoked by alias); 6 Jan 2017 21:25:33 -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 61343 invoked by uid 89); 6 Jan 2017 21:25:32 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=1.3 required=5.0 tests=BAYES_50, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=no version=3.3.2 spammy=nathan@acm.org, nathanacmorg, NODE, symtab_node X-HELO: mail-yw0-f174.google.com Received: from mail-yw0-f174.google.com (HELO mail-yw0-f174.google.com) (209.85.161.174) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 06 Jan 2017 21:25:22 +0000 Received: by mail-yw0-f174.google.com with SMTP id v81so278401780ywb.2 for ; Fri, 06 Jan 2017 13:25:22 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:to:cc:from:subject:message-id:date :user-agent:mime-version; bh=rW8GdjQ6SFtrvszW6ySkx4hgGYeQAozgXki5Yxr2cJ8=; b=cjV8BtzNymvFpBDXisC7J0jGqe/MGm1EBEAeI8T+cKJQ1GdYLCGaUUzMYadJlMxuqj G/sSDQJJLqVY4R/UcZFFT0AwNwnVACx3mtJEA+kg0ii8jSTxt2EcI0l+B9sEY/3OMhcV tYzUYRaTQ+GRQ0F977uymTEIQSOk47iH0mgDcKn7unlQVVbbCT6gxbfMBe+ofJK3HtW6 hz1+ReSmvH/cukLet1OuuyXcQxO6ZLPLD5VzUwpMSe3QndUv/KxG8u2CszWHBYf2IOxB tWEfrHFcOr9wcyBClv+dWnNeKsB5RIXI/cJVIjWHwyw6D3M3fmyCpiYDJFRcZQAPp4r8 xILA== X-Gm-Message-State: AIkVDXLBvExZ+TCl9ytFkLgE5eORiWJobfHht6Rpim+OPayFoO5Gbl43BvWFlwKwlhfV1w== X-Received: by 10.129.31.214 with SMTP id f205mr86021065ywf.267.1483737920844; Fri, 06 Jan 2017 13:25:20 -0800 (PST) Received: from ?IPv6:2620:10d:c0a3:20fb:f6d0:5ac5:64cd:f102? ([2620:10d:c091:200::10c]) by smtp.googlemail.com with ESMTPSA id n129sm204196ywn.1.2017.01.06.13.25.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 06 Jan 2017 13:25:20 -0800 (PST) To: Jan Hubicka Cc: GCC Patches From: Nathan Sidwell Subject: [IPA PATCH] Refactor decl localizing Message-ID: Date: Fri, 6 Jan 2017 16:25:19 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.6.0 MIME-Version: 1.0 This patch refactors the decl localizing that happens in function_and_variable_visibility. It doesn't fix the bug I'm working on (that's next). Both the FOR_EACH_FUNCTION and FOR_EACH_VARIABLE loops contain very similar, but not quite the same code for localizing a definition that it's determined need not be externally visible. It looks to me that the not-quite-the-sameness is erroneous, and this patch refactors that code into a common subroutine. If the differences need to be maintained (slight differences in when unique_name is updated and whether resolution is set to LDPR_PREVAILING_DEF_IRONLY), I think a flag to the new function would be best, rather than keep the duplicated code. booted & tested on x86_64-linux, ok? nathan -- Nathan Sidwell 2017-01-06 Nathan Sidwell * ipa-visibility.c (localize_node): New function, broken out of ... (function_and_variable_visibility): Call it. Index: ipa-visibility.c =================================================================== --- ipa-visibility.c (revision 244159) +++ ipa-visibility.c (working copy) @@ -529,6 +529,53 @@ optimize_weakref (symtab_node *node) gcc_assert (node->alias); } +/* NODE is an externally visible definition, which we've discovered is + not needed externally. Make it local to this compilation. */ + +static void +localize_node (bool whole_program, symtab_node *node) +{ + gcc_assert (whole_program || in_lto_p || !TREE_PUBLIC (node->decl)); + + if (node->same_comdat_group && TREE_PUBLIC (node->decl)) + { + for (symtab_node *next = node->same_comdat_group; + next != node; next = next->same_comdat_group) + { + next->set_comdat_group (NULL); + if (!next->alias) + next->set_section (NULL); + if (!next->transparent_alias) + next->make_decl_local (); + next->unique_name + |= ((next->resolution == LDPR_PREVAILING_DEF_IRONLY + || next->resolution == LDPR_PREVAILING_DEF_IRONLY_EXP) + && TREE_PUBLIC (next->decl) + && !flag_incremental_link); + } + + /* Now everything's localized, the grouping has no meaning, and + will cause crashes if we keep it around. */ + node->dissolve_same_comdat_group_list (); + } + + node->unique_name + |= ((node->resolution == LDPR_PREVAILING_DEF_IRONLY + || node->resolution == LDPR_PREVAILING_DEF_IRONLY_EXP) + && TREE_PUBLIC (node->decl) + && !flag_incremental_link); + + if (TREE_PUBLIC (node->decl)) + node->set_comdat_group (NULL); + if (DECL_COMDAT (node->decl) && !node->alias) + node->set_section (NULL); + if (!node->transparent_alias) + { + node->resolution = LDPR_PREVAILING_DEF_IRONLY; + node->make_decl_local (); + } +} + /* Decide on visibility of all symbols. */ static unsigned int @@ -606,48 +653,7 @@ function_and_variable_visibility (bool w if (!node->externally_visible && node->definition && !node->weakref && !DECL_EXTERNAL (node->decl)) - { - gcc_assert (whole_program || in_lto_p - || !TREE_PUBLIC (node->decl)); - node->unique_name - |= ((node->resolution == LDPR_PREVAILING_DEF_IRONLY - || node->resolution == LDPR_PREVAILING_DEF_IRONLY_EXP) - && TREE_PUBLIC (node->decl) - && !flag_incremental_link); - node->resolution = LDPR_PREVAILING_DEF_IRONLY; - if (node->same_comdat_group && TREE_PUBLIC (node->decl)) - { - symtab_node *next = node; - - /* Set all members of comdat group local. */ - for (next = node->same_comdat_group; - next != node; - next = next->same_comdat_group) - { - next->set_comdat_group (NULL); - if (!next->alias) - next->set_section (NULL); - if (!next->transparent_alias) - next->make_decl_local (); - next->unique_name - |= ((next->resolution == LDPR_PREVAILING_DEF_IRONLY - || next->resolution == LDPR_PREVAILING_DEF_IRONLY_EXP) - && TREE_PUBLIC (next->decl) - && !flag_incremental_link); - } - /* cgraph_externally_visible_p has already checked all - other nodes in the group and they will all be made - local. We need to dissolve the group at once so that - the predicate does not segfault though. */ - node->dissolve_same_comdat_group_list (); - } - if (TREE_PUBLIC (node->decl)) - node->set_comdat_group (NULL); - if (DECL_COMDAT (node->decl) && !node->alias) - node->set_section (NULL); - if (!node->transparent_alias) - node->make_decl_local (); - } + localize_node (whole_program, node); if (node->thunk.thunk_p && !node->thunk.add_pointer_bounds_args @@ -757,49 +763,11 @@ function_and_variable_visibility (bool w if (lookup_attribute ("no_reorder", DECL_ATTRIBUTES (vnode->decl))) vnode->no_reorder = 1; + if (!vnode->externally_visible && !vnode->transparent_alias) - { - gcc_assert (in_lto_p || whole_program || !TREE_PUBLIC (vnode->decl)); - vnode->unique_name |= ((vnode->resolution == LDPR_PREVAILING_DEF_IRONLY - || vnode->resolution - == LDPR_PREVAILING_DEF_IRONLY_EXP) - && TREE_PUBLIC (vnode->decl) - && !flag_incremental_link); - if (vnode->same_comdat_group && TREE_PUBLIC (vnode->decl)) - { - symtab_node *next = vnode; + localize_node (whole_program, vnode); - /* Set all members of comdat group local. */ - if (vnode->same_comdat_group) - for (next = vnode->same_comdat_group; - next != vnode; - next = next->same_comdat_group) - { - next->set_comdat_group (NULL); - if (!next->alias) - next->set_section (NULL); - if (!next->transparent_alias) - { - next->make_decl_local (); - next->unique_name |= ((next->resolution == LDPR_PREVAILING_DEF_IRONLY - || next->resolution == LDPR_PREVAILING_DEF_IRONLY_EXP) - && TREE_PUBLIC (next->decl) - && !flag_incremental_link); - } - } - vnode->dissolve_same_comdat_group_list (); - } - if (TREE_PUBLIC (vnode->decl)) - vnode->set_comdat_group (NULL); - if (DECL_COMDAT (vnode->decl) && !vnode->alias) - vnode->set_section (NULL); - if (!vnode->transparent_alias) - { - vnode->make_decl_local (); - vnode->resolution = LDPR_PREVAILING_DEF_IRONLY; - } - } update_visibility_by_resolution_info (vnode); /* Update virtual tables to point to local aliases where possible. */