[FYI] zero-call-used-regs attr for ada
Commit Message
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
Comments
On Sep 15, 2021, Alexandre Oliva <oliva@adacore.com> wrote:
> Regstrapped on x86_64-linux-gnu. Patch pre-approved by Olivier Hainque.
Uhh, actually, Olivier had only seen and approved these changes:
> 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.
The trivial testcase went in without anyone's approval. Oops.
> for gcc/testsuite/ChangeLog
> * gnat.dg/zcur_attr.adb, gnat.dg/zcur_attr.ads: New.
Sorry about the slip. It's trivial enough that I suppose it can fit the
"obviously correct" rule. Please let me know in case you disagree.
> On 15 Sep 2021, at 18:45, Alexandre Oliva <oliva@adacore.com> wrote:
>
> On Sep 15, 2021, Alexandre Oliva <oliva@adacore.com> wrote:
>
>> Regstrapped on x86_64-linux-gnu. Patch pre-approved by Olivier Hainque.
>
> Uhh, actually, Olivier had only seen and approved these changes:
>
>> 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.
>
> The trivial testcase went in without anyone's approval. Oops.
>
>> for gcc/testsuite/ChangeLog
>
>> * gnat.dg/zcur_attr.adb, gnat.dg/zcur_attr.ads: New.
>
> Sorry about the slip. It's trivial enough that I suppose it can fit the
> "obviously correct" rule. Please let me know in case you disagree.
No problem at all Alex. Thanks for your work on this!
@@ -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 *
* ----------------------------------------------------------------------- */
new file mode 100644
@@ -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" } }
new file mode 100644
@@ -0,0 +1,4 @@
+package ZCUR_Attr is
+ function F return Integer;
+ pragma Machine_Attribute (F, "zero_call_used_regs", "all");
+end ZCUR_Attr;