From patchwork Wed Sep 15 16:28:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Oliva X-Patchwork-Id: 45053 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9D7D93857411 for ; Wed, 15 Sep 2021 16:29:20 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from rock.gnat.com (rock.gnat.com [IPv6:2620:20:4000:0:a9e:1ff:fe9b:1d1]) by sourceware.org (Postfix) with ESMTPS id E89AC3858403 for ; Wed, 15 Sep 2021 16:29:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E89AC3858403 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 981C75602A; Wed, 15 Sep 2021 12:29:04 -0400 (EDT) X-Virus-Scanned: Debian amavisd-new at gnat.com Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id DgoCmtVQum0z; Wed, 15 Sep 2021 12:29:04 -0400 (EDT) Received: from free.home (tron.gnat.com [IPv6:2620:20:4000:0:46a8:42ff:fe0e:e294]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by rock.gnat.com (Postfix) with ESMTPS id 5ED9456029; Wed, 15 Sep 2021 12:29:04 -0400 (EDT) Received: from livre (livre.home [172.31.160.2]) by free.home (8.15.2/8.15.2) with ESMTPS id 18FGSteo121085 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 15 Sep 2021 13:28:56 -0300 From: Alexandre Oliva To: gcc-patches@gcc.gnu.org Subject: [FYI] zero-call-used-regs attr for ada Organization: Free thinker, does not speak for AdaCore Date: Wed, 15 Sep 2021 13:28:55 -0300 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_ASCII_DIVIDERS, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_PASS, 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: , Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Make the zero_call_used_regs attribute usable as a Machine_Attribute pragma. Regstrapped on x86_64-linux-gnu. Patch pre-approved by Olivier Hainque. for gcc/ada/ChangeLog * gcc-interface/utils.c: Include opts.h. (handle_zero_call_used_regs_attribute): New. (gnat_internal_attribute_table): Add zero_call_used_regs. for gcc/testsuite/ChangeLog * gnat.dg/zcur_attr.adb, gnat.dg/zcur_attr.ads: New. --- gcc/ada/gcc-interface/utils.c | 59 +++++++++++++++++++++++++++++++++++ gcc/testsuite/gnat.dg/zcur_attr.adb | 8 +++++ gcc/testsuite/gnat.dg/zcur_attr.ads | 4 ++ 3 files changed, 71 insertions(+) create mode 100644 gcc/testsuite/gnat.dg/zcur_attr.adb create mode 100644 gcc/testsuite/gnat.dg/zcur_attr.ads diff --git a/gcc/ada/gcc-interface/utils.c b/gcc/ada/gcc-interface/utils.c index 4190855b76394..be3f107926d7c 100644 --- a/gcc/ada/gcc-interface/utils.c +++ b/gcc/ada/gcc-interface/utils.c @@ -38,6 +38,7 @@ #include "attribs.h" #include "varasm.h" #include "toplev.h" +#include "opts.h" #include "output.h" #include "debug.h" #include "convert.h" @@ -109,6 +110,8 @@ static tree handle_target_attribute (tree *, tree, tree, int, bool *); static tree handle_target_clones_attribute (tree *, tree, tree, int, bool *); static tree handle_vector_size_attribute (tree *, tree, tree, int, bool *); static tree handle_vector_type_attribute (tree *, tree, tree, int, bool *); +static tree handle_zero_call_used_regs_attribute (tree *, tree, tree, int, + bool *); static const struct attribute_spec::exclusions attr_cold_hot_exclusions[] = { @@ -191,6 +194,9 @@ const struct attribute_spec gnat_internal_attribute_table[] = { "may_alias", 0, 0, false, true, false, false, NULL, NULL }, + { "zero_call_used_regs", 1, 1, true, false, false, false, + handle_zero_call_used_regs_attribute, NULL }, + /* ??? format and format_arg are heavy and not supported, which actually prevents support for stdio builtins, which we however declare as part of the common builtins.def contents. */ @@ -6987,6 +6993,59 @@ handle_vector_type_attribute (tree *node, tree name, tree ARG_UNUSED (args), return NULL_TREE; } +/* Handle a "zero_call_used_regs" attribute; arguments as in + struct attribute_spec.handler. */ + +static tree +handle_zero_call_used_regs_attribute (tree *node, tree name, tree args, + int ARG_UNUSED (flags), + bool *no_add_attrs) +{ + tree decl = *node; + tree id = TREE_VALUE (args); + + if (TREE_CODE (decl) != FUNCTION_DECL) + { + error_at (DECL_SOURCE_LOCATION (decl), + "%qE attribute applies only to functions", name); + *no_add_attrs = true; + return NULL_TREE; + } + + /* pragma Machine_Attribute turns string arguments into identifiers. + Reverse it. */ + if (TREE_CODE (id) == IDENTIFIER_NODE) + id = TREE_VALUE (args) = build_string + (IDENTIFIER_LENGTH (id), IDENTIFIER_POINTER (id)); + + if (TREE_CODE (id) != STRING_CST) + { + error_at (DECL_SOURCE_LOCATION (decl), + "%qE argument not a string", name); + *no_add_attrs = true; + return NULL_TREE; + } + + bool found = false; + for (unsigned int i = 0; zero_call_used_regs_opts[i].name != NULL; ++i) + if (strcmp (TREE_STRING_POINTER (id), + zero_call_used_regs_opts[i].name) == 0) + { + found = true; + break; + } + + if (!found) + { + error_at (DECL_SOURCE_LOCATION (decl), + "unrecognized %qE attribute argument %qs", + name, TREE_STRING_POINTER (id)); + *no_add_attrs = true; + } + + return NULL_TREE; +} + /* ----------------------------------------------------------------------- * * BUILTIN FUNCTIONS * * ----------------------------------------------------------------------- */ diff --git a/gcc/testsuite/gnat.dg/zcur_attr.adb b/gcc/testsuite/gnat.dg/zcur_attr.adb new file mode 100644 index 0000000000000..5d15f5e9d7324 --- /dev/null +++ b/gcc/testsuite/gnat.dg/zcur_attr.adb @@ -0,0 +1,8 @@ +-- { dg-do compile } +-- { dg-options "-fdump-tree-optimized" } + +package body ZCUR_Attr is + function F return Integer is (0); +end ZCUR_Attr; + +-- { dg-final { scan-tree-dump "zero_call_used_regs \[(\]\"all\"\[)\]" "optimized" } } diff --git a/gcc/testsuite/gnat.dg/zcur_attr.ads b/gcc/testsuite/gnat.dg/zcur_attr.ads new file mode 100644 index 0000000000000..b756cc838b8df --- /dev/null +++ b/gcc/testsuite/gnat.dg/zcur_attr.ads @@ -0,0 +1,4 @@ +package ZCUR_Attr is + function F return Integer; + pragma Machine_Attribute (F, "zero_call_used_regs", "all"); +end ZCUR_Attr;