From ab341f5003f8ad9f5ee30ce566d68d8284a31f00 Mon Sep 17 00:00:00 2001 From: Richard Sandiford Date: Tue, 7 Jan 2020 10:21:26 +0000 Subject: [PATCH] Add a generic lhd_simulate_enum_decl Normally we only create SVE ACLE functions when arm_sve.h is included. But for LTO we need to do it at start-up, so that the functions are already defined when streaming in the LTO objects. One hitch with doing that is that LTO doesn't yet implement the simulate_enum_decl langhook. This patch adds a simple default implementation that it can use. 2020-01-07 Richard Sandiford gcc/ * langhooks-def.h (lhd_simulate_enum_decl): Declare. (LANG_HOOKS_SIMULATE_ENUM_DECL): Use it. * langhooks.c: Include stor-layout.h. (lhd_simulate_enum_decl): New function. * config/aarch64/aarch64-sve-builtins.cc (init_builtins): Call handle_arm_sve_h for the LTO frontend. (register_vector_type): Cope with null returns from pushdecl. gcc/testsuite/ * gcc.target/aarch64/sve/pcs/asm_4.c: New test. From-SVN: r279954 --- gcc/ChangeLog | 10 +++++ gcc/config/aarch64/aarch64-sve-builtins.cc | 5 ++- gcc/langhooks-def.h | 4 +- gcc/langhooks.c | 39 +++++++++++++++++++ gcc/testsuite/ChangeLog | 4 ++ .../gcc.target/aarch64/sve/pcs/asm_4.c | 4 ++ 6 files changed, 64 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.target/aarch64/sve/pcs/asm_4.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 3aa2061aee2..9924d74c783 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,13 @@ +2020-01-07 Richard Sandiford + + * langhooks-def.h (lhd_simulate_enum_decl): Declare. + (LANG_HOOKS_SIMULATE_ENUM_DECL): Use it. + * langhooks.c: Include stor-layout.h. + (lhd_simulate_enum_decl): New function. + * config/aarch64/aarch64-sve-builtins.cc (init_builtins): Call + handle_arm_sve_h for the LTO frontend. + (register_vector_type): Cope with null returns from pushdecl. + 2020-01-07 Richard Sandiford * config/aarch64/aarch64-protos.h (aarch64_sve::svbool_type_p) diff --git a/gcc/config/aarch64/aarch64-sve-builtins.cc b/gcc/config/aarch64/aarch64-sve-builtins.cc index 566ebae4866..6cdda30b32a 100644 --- a/gcc/config/aarch64/aarch64-sve-builtins.cc +++ b/gcc/config/aarch64/aarch64-sve-builtins.cc @@ -3044,6 +3044,8 @@ init_builtins () { sve_switcher sve; register_builtin_types (); + if (in_lto_p) + handle_arm_sve_h (); } /* Register vector type TYPE under its arm_sve.h name. */ @@ -3060,7 +3062,8 @@ register_vector_type (vector_type_index type) right form, even if it doesn't have the right name. This should give better error recovery behavior than installing error_mark_node or installing an incorrect type. */ - if (TREE_CODE (decl) == TYPE_DECL + if (decl + && TREE_CODE (decl) == TYPE_DECL && TYPE_MAIN_VARIANT (TREE_TYPE (decl)) == vectype) vectype = TREE_TYPE (decl); acle_vector_types[0][type] = vectype; diff --git a/gcc/langhooks-def.h b/gcc/langhooks-def.h index 2744000bdbb..82aeb653085 100644 --- a/gcc/langhooks-def.h +++ b/gcc/langhooks-def.h @@ -54,6 +54,8 @@ extern void lhd_print_error_function (diagnostic_context *, extern void lhd_set_decl_assembler_name (tree decl); extern void lhd_overwrite_decl_assembler_name (tree decl, tree name); extern bool lhd_warn_unused_global_decl (const_tree); +extern tree lhd_simulate_enum_decl (location_t, const char *, + vec); extern tree lhd_type_for_size (unsigned precision, int unsignedp); extern void lhd_incomplete_type_error (location_t, const_tree, const_tree); extern tree lhd_type_promotes_to (tree); @@ -171,7 +173,7 @@ extern tree lhd_make_node (enum tree_code); extern tree lhd_unit_size_without_reusable_padding (tree); #define LANG_HOOKS_MAKE_TYPE lhd_make_node -#define LANG_HOOKS_SIMULATE_ENUM_DECL NULL +#define LANG_HOOKS_SIMULATE_ENUM_DECL lhd_simulate_enum_decl #define LANG_HOOKS_CLASSIFY_RECORD NULL #define LANG_HOOKS_TYPE_FOR_SIZE lhd_type_for_size #define LANG_HOOKS_INCOMPLETE_TYPE_ERROR lhd_incomplete_type_error diff --git a/gcc/langhooks.c b/gcc/langhooks.c index e8295978ca4..640bd012d1c 100644 --- a/gcc/langhooks.c +++ b/gcc/langhooks.c @@ -35,6 +35,7 @@ along with GCC; see the file COPYING3. If not see #include "tree-diagnostic.h" #include "output.h" #include "timevar.h" +#include "stor-layout.h" /* Do nothing; in many cases the default hook. */ @@ -473,6 +474,44 @@ lhd_make_node (enum tree_code code) return make_node (code); } +/* Default implementation of LANG_HOOKS_SIMULATE_ENUM_DECL. Assume a + simple int-based enumerator (which is all the hook can be used for + at present) and push each decl individually without any decoration. + + This definition is suitable for LTO and is generic enough that it + might be reusable elsewhere. */ +tree +lhd_simulate_enum_decl (location_t loc, const char *name, + vec values) +{ + tree enumtype = lang_hooks.types.make_type (ENUMERAL_TYPE); + tree enumdecl = build_decl (loc, TYPE_DECL, get_identifier (name), enumtype); + TYPE_STUB_DECL (enumtype) = enumdecl; + + tree value_chain = NULL_TREE; + string_int_pair *value; + unsigned int i; + FOR_EACH_VEC_ELT (values, i, value) + { + tree value_decl = build_decl (loc, CONST_DECL, + get_identifier (value->first), enumtype); + DECL_INITIAL (value_decl) = build_int_cst (integer_type_node, + value->second); + lang_hooks.decls.pushdecl (value_decl); + value_chain = tree_cons (value_decl, DECL_INITIAL (value_decl), + value_chain); + } + + TYPE_MIN_VALUE (enumtype) = TYPE_MIN_VALUE (integer_type_node); + TYPE_MAX_VALUE (enumtype) = TYPE_MAX_VALUE (integer_type_node); + SET_TYPE_ALIGN (enumtype, TYPE_ALIGN (integer_type_node)); + TYPE_PRECISION (enumtype) = TYPE_PRECISION (integer_type_node); + layout_type (enumtype); + lang_hooks.decls.pushdecl (enumdecl); + + return enumtype; +} + /* Default implementation of LANG_HOOKS_TYPE_FOR_SIZE. Return an integer type with PRECISION bits of precision, that is unsigned if UNSIGNEDP is nonzero, otherwise signed. */ diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 9e694fa834e..e272d77202a 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2020-01-07 Richard Sandiford + + * gcc.target/aarch64/sve/pcs/asm_4.c: New test. + 2020-01-07 Richard Sandiford * g++.target/aarch64/sve/acle/general-c++/mangle_5.C: New test. diff --git a/gcc/testsuite/gcc.target/aarch64/sve/pcs/asm_4.c b/gcc/testsuite/gcc.target/aarch64/sve/pcs/asm_4.c new file mode 100644 index 00000000000..83827c20d05 --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/sve/pcs/asm_4.c @@ -0,0 +1,4 @@ +/* { dg-do run { target aarch64_sve_hw } } */ +/* { dg-options "-O2 -flto -ffixed-z0 -ffixed-p0" } */ + +#include "asm_3.c" -- 2.30.2