* Add a generic lhd_simulate_enum_decl
@ 2019-12-19 17:01 Richard Sandiford
2020-01-06 17:26 ` Jeff Law
0 siblings, 1 reply; 2+ messages in thread
From: Richard Sandiford @ 2019-12-19 17:01 UTC (permalink / raw)
To: gcc-patches
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.
Tested on aarch64-linux-gnu and x86_64-linux-gnu. OK for the
generic bits?
Richard
2019-12-19 Richard Sandiford <richard.sandiford@arm.com>
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.
Index: gcc/langhooks-def.h
===================================================================
--- gcc/langhooks-def.h 2019-11-11 19:43:29.268784653 +0000
+++ gcc/langhooks-def.h 2019-12-19 16:58:12.856690090 +0000
@@ -54,6 +54,8 @@ extern void lhd_print_error_function (di
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<string_int_pair>);
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 @@ #define LANG_HOOKS_TREE_DUMP_INITIALIZER
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
Index: gcc/langhooks.c
===================================================================
--- gcc/langhooks.c 2019-10-29 08:39:22.576014071 +0000
+++ gcc/langhooks.c 2019-12-19 16:58:12.856690090 +0000
@@ -35,6 +35,7 @@ the Free Software Foundation; either ver
#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<string_int_pair> 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. */
Index: gcc/config/aarch64/aarch64-sve-builtins.cc
===================================================================
--- gcc/config/aarch64/aarch64-sve-builtins.cc 2019-12-13 10:21:19.000000000 +0000
+++ gcc/config/aarch64/aarch64-sve-builtins.cc 2019-12-19 16:58:12.856690090 +0000
@@ -3025,6 +3025,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. */
@@ -3041,7 +3043,8 @@ register_vector_type (vector_type_index
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;
Index: gcc/testsuite/gcc.target/aarch64/sve/pcs/asm_4.c
===================================================================
--- /dev/null 2019-09-17 11:41:18.176664108 +0100
+++ gcc/testsuite/gcc.target/aarch64/sve/pcs/asm_4.c 2019-12-19 16:58:12.856690090 +0000
@@ -0,0 +1,4 @@
+/* { dg-do run { target aarch64_sve_hw } } */
+/* { dg-options "-O2 -flto -ffixed-z0 -ffixed-p0" } */
+
+#include "asm_3.c"
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Add a generic lhd_simulate_enum_decl
2019-12-19 17:01 Add a generic lhd_simulate_enum_decl Richard Sandiford
@ 2020-01-06 17:26 ` Jeff Law
0 siblings, 0 replies; 2+ messages in thread
From: Jeff Law @ 2020-01-06 17:26 UTC (permalink / raw)
To: Richard Sandiford, gcc-patches
On Thu, 2019-12-19 at 16:59 +0000, Richard Sandiford wrote:
> 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.
>
> Tested on aarch64-linux-gnu and x86_64-linux-gnu. OK for the
> generic bits?
>
> Richard
>
>
> 2019-12-19 Richard Sandiford <richard.sandiford@arm.com>
>
> 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.
OK
jeff
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-01-06 17:26 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-19 17:01 Add a generic lhd_simulate_enum_decl Richard Sandiford
2020-01-06 17:26 ` Jeff Law
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).