From patchwork Sat Nov 13 14:44:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Hubicka X-Patchwork-Id: 1554718 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=lj+mzxwZ; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Hrytv6Dsgz9sCD for ; Sun, 14 Nov 2021 01:45:59 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C26893857C59 for ; Sat, 13 Nov 2021 14:45:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C26893857C59 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1636814757; bh=BsXAt8d6SWYNxUYJZUPn9lb7wl0ZDZzt+M4n6X6vfuw=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=lj+mzxwZjsdwwcpizw1iBzqE8GxodBpmFZhBb9HBa9GGF3kkdNtt2FTIR/M++6RmK LmbwdnMJ5u+Wy8TsJT7okJS8MBWB3KiVsd3FfgILkgEhozlyP+28m5Hu17+R2dvWrY eA6GzCWENHd6BYaCulXvNSFNenTvP/dg5zqrwOA8= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from nikam.ms.mff.cuni.cz (nikam.ms.mff.cuni.cz [195.113.20.16]) by sourceware.org (Postfix) with ESMTPS id 606643857C58; Sat, 13 Nov 2021 14:44:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 606643857C58 Received: by nikam.ms.mff.cuni.cz (Postfix, from userid 16202) id 2F6D1280872; Sat, 13 Nov 2021 15:44:38 +0100 (CET) Date: Sat, 13 Nov 2021 15:44:38 +0100 To: gcc-patches@gcc.gnu.org, msebor@gcc.gnu.org Subject: Enable more type attributes for signature changes Message-ID: <20211113144438.GA952@kam.mff.cuni.cz> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, GIT_PATCH_0, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jan Hubicka via Gcc-patches From: Jan Hubicka Reply-To: Jan Hubicka Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Hi, this patch whitelists attributes that are safe for attribute changes and also makes access attribute dropped if function sigunature is changed. We could do better by updating the attribute, but doing so seems to be bit snowballing since with LTO the warnings produced seems bit confused. We would also like to output original name of function instead of mangledname.constprop or so. I looked into what attributes are dorpped in bootstrap and it does not look too bad. Bootstrapped/regtested x86_64-linux, will commit it shortly. Honza gcc/ChangeLog: * ipa-fnsummary.c (compute_fn_summary): Use type_attribut_allowed_p * ipa-param-manipulation.c (ipa_param_adjustments::type_attribute_allowed_p): New member function. (drop_type_attribute_if_params_changed_p): New function. (build_adjusted_function_type): Use it. * ipa-param-manipulation.h: Add type_attribute_allowed_p. diff --git a/gcc/ipa-fnsummary.c b/gcc/ipa-fnsummary.c index 94a80d3ec90..7e9201a554a 100644 --- a/gcc/ipa-fnsummary.c +++ b/gcc/ipa-fnsummary.c @@ -3141,8 +3141,8 @@ compute_fn_summary (struct cgraph_node *node, bool early) modref summaries. */ for (tree list = TYPE_ATTRIBUTES (TREE_TYPE (node->decl)); list && !no_signature; list = TREE_CHAIN (list)) - if (!flag_ipa_modref - || !is_attribute_p ("fn spec", get_attribute_name (list))) + if (!ipa_param_adjustments::type_attribute_allowed_p + (get_attribute_name (list))) { if (dump_file) { diff --git a/gcc/ipa-param-manipulation.c b/gcc/ipa-param-manipulation.c index 991db0d9b1b..29268fa5a58 100644 --- a/gcc/ipa-param-manipulation.c +++ b/gcc/ipa-param-manipulation.c @@ -279,6 +279,32 @@ fill_vector_of_new_param_types (vec *new_types, vec *otypes, } } +/* Return false if given attribute should prevent type adjustments. */ + +bool +ipa_param_adjustments::type_attribute_allowed_p (tree name) +{ + if ((is_attribute_p ("fn spec", name) && flag_ipa_modref) + || is_attribute_p ("access", name) + || is_attribute_p ("returns_nonnull", name) + || is_attribute_p ("assume_aligned", name) + || is_attribute_p ("nocf_check", name) + || is_attribute_p ("warn_unused_result", name)) + return true; + return false; +} + +/* Return true if attribute should be dropped if parameter changed. */ + +static bool +drop_type_attribute_if_params_changed_p (tree name) +{ + if (is_attribute_p ("fn spec", name) + || is_attribute_p ("access", name)) + return true; + return false; +} + /* Build and return a function type just like ORIG_TYPE but with parameter types given in NEW_PARAM_TYPES - which can be NULL if, but only if, ORIG_TYPE itself has NULL TREE_ARG_TYPEs. If METHOD2FUNC is true, also make @@ -337,16 +363,19 @@ build_adjusted_function_type (tree orig_type, vec *new_param_types, if (skip_return) TREE_TYPE (new_type) = void_type_node; } - /* We only support one fn spec attribute on type. Be sure to remove it. - Once we support multiple attributes we will need to be able to unshare - the list. */ if (args_modified && TYPE_ATTRIBUTES (new_type)) { - gcc_checking_assert - (!TREE_CHAIN (TYPE_ATTRIBUTES (new_type)) - && (is_attribute_p ("fn spec", - get_attribute_name (TYPE_ATTRIBUTES (new_type))))); + tree t = TYPE_ATTRIBUTES (new_type); + tree *last = &TYPE_ATTRIBUTES (new_type); TYPE_ATTRIBUTES (new_type) = NULL; + for (;t; t = TREE_CHAIN (t)) + if (!drop_type_attribute_if_params_changed_p + (get_attribute_name (t))) + { + *last = copy_node (t); + TREE_CHAIN (*last) = NULL; + last = &TREE_CHAIN (*last); + } } return new_type; diff --git a/gcc/ipa-param-manipulation.h b/gcc/ipa-param-manipulation.h index 9440cbfc56c..5adf8a22356 100644 --- a/gcc/ipa-param-manipulation.h +++ b/gcc/ipa-param-manipulation.h @@ -254,6 +254,7 @@ public: /* If true, make the function not return any value. */ bool m_skip_return; + static bool type_attribute_allowed_p (tree); private: ipa_param_adjustments () {}