aboutsummaryrefslogtreecommitdiff
path: root/gcc/c
diff options
context:
space:
mode:
authorRichard Sandiford <richard.sandiford@arm.com>2019-10-29 08:39:33 +0000
committerRichard Sandiford <rsandifo@gcc.gnu.org>2019-10-29 08:39:33 +0000
commit740785381ec9944c861dcc29b420c96aa933f040 (patch)
tree00a84533bfa0cdcce1c5eb24f16e6bfe9f0f54cf /gcc/c
parent891966480630f58f115825c31badc59dd18d5eb9 (diff)
downloadgcc-740785381ec9944c861dcc29b420c96aa933f040.zip
gcc-740785381ec9944c861dcc29b420c96aa933f040.tar.gz
gcc-740785381ec9944c861dcc29b420c96aa933f040.tar.bz2
Add a simulate_builin_function_decl langhook
Although it's possible to define the SVE intrinsics in a normal header file, it's much more convenient to define them directly in the compiler. This also speeds up compilation and gives better error messages. The idea is therefore for arm_sve.h (the main intrinsics header file) to have the pragma: #pragma GCC aarch64 "arm_sve.h" telling GCC to define (almost) everything arm_sve.h needs to define. The target then needs a way of injecting new built-in function declarations during compilation. The main hook for defining built-in functions is add_builtin_function. This is designed for use at start-up, and so has various features that are correct in that context but not for the pragma above: (1) the location is always BUILTINS_LOCATION, whereas for arm_sve.h it ought to be the location of the pragma. (2) the function is only immediately visible if it's in the implementation namespace, whereas the pragma is deliberately injecting functions into the general namespace. (3) there's no attempt to emulate a normal function declaration in C or C++, whereas functions declared by the pragma should be checked in the same way as an open-coded declaration would be. E.g. we should get an error if there was a previous incompatible declaration. (4) in C++, the function is treated as extern "C" and so can't be overloaded, whereas SVE intrinsics do use function overloading. This patch therefore adds a hook that targets can use to inject the equivalent of a source-level function declaration, but bound to a BUILT_IN_MD function. The main SVE intrinsic patch has tests to make sure that we report an error for conflicting definitions that appear either before or after including arm_sve.h. 2019-10-29 Richard Sandiford <richard.sandiford@arm.com> gcc/ * langhooks.h (lang_hooks::simulate_builtin_function_decl): New hook. (simulate_builtin_function_decl): Declare. * langhooks-def.h (LANG_HOOKS_SIMULATE_BUILTIN_FUNCTION_DECL): Define. (LANG_HOOKS_INITIALIZER): Include it. * langhooks.c (add_builtin_function_common): Rename to... (build_builtin_function): ...this. Add a location parameter and use it instead of BUILTINS_LOCATION. Remove the hook parameter and return the decl instead. (add_builtin_function): Update accordingly, passing the returned decl to the lang hook. (add_builtin_function_ext_scope): Likewise (simulate_builtin_function_decl): New function. gcc/c/ * c-tree.h (c_simulate_builtin_function_decl): Declare. * c-decl.c (c_simulate_builtin_function_decl): New function. * c-objc-common.h (LANG_HOOKS_SIMULATE_BUILTIN_FUNCTION_DECL): Define to the above. gcc/cp/ * cp-tree.h (cxx_simulate_builtin_function_decl): Declare. * decl.c (cxx_simulate_builtin_function_decl): New function. * cp-objcp-common.h (LANG_HOOKS_SIMULATE_BUILTIN_FUNCTION_DECL): Define to the above. From-SVN: r277554
Diffstat (limited to 'gcc/c')
-rw-r--r--gcc/c/ChangeLog7
-rw-r--r--gcc/c/c-decl.c10
-rw-r--r--gcc/c/c-objc-common.h3
-rw-r--r--gcc/c/c-tree.h1
4 files changed, 21 insertions, 0 deletions
diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog
index 087090f..3b0e3ba 100644
--- a/gcc/c/ChangeLog
+++ b/gcc/c/ChangeLog
@@ -1,3 +1,10 @@
+2019-10-29 Richard Sandiford <richard.sandiford@arm.com>
+
+ * c-tree.h (c_simulate_builtin_function_decl): Declare.
+ * c-decl.c (c_simulate_builtin_function_decl): New function.
+ * c-objc-common.h (LANG_HOOKS_SIMULATE_BUILTIN_FUNCTION_DECL): Define
+ to the above.
+
2019-10-28 Martin Sebor <msebor@redhat.com>
PR c/66970
diff --git a/gcc/c/c-decl.c b/gcc/c/c-decl.c
index e76ed26..1013996 100644
--- a/gcc/c/c-decl.c
+++ b/gcc/c/c-decl.c
@@ -4481,6 +4481,16 @@ c_builtin_function_ext_scope (tree decl)
return decl;
}
+
+/* Implement LANG_HOOKS_SIMULATE_BUILTIN_FUNCTION_DECL. */
+
+tree
+c_simulate_builtin_function_decl (tree decl)
+{
+ tree type = TREE_TYPE (decl);
+ C_DECL_BUILTIN_PROTOTYPE (decl) = prototype_p (type);
+ return pushdecl (decl);
+}
/* Called when a declaration is seen that contains no names to declare.
If its type is a reference to a structure, union or enum inherited
diff --git a/gcc/c/c-objc-common.h b/gcc/c/c-objc-common.h
index f5e8204..8d3bcc2 100644
--- a/gcc/c/c-objc-common.h
+++ b/gcc/c/c-objc-common.h
@@ -60,6 +60,9 @@ along with GCC; see the file COPYING3. If not see
#define LANG_HOOKS_BUILTIN_FUNCTION c_builtin_function
#undef LANG_HOOKS_BUILTIN_FUNCTION_EXT_SCOPE
#define LANG_HOOKS_BUILTIN_FUNCTION_EXT_SCOPE c_builtin_function_ext_scope
+#undef LANG_HOOKS_SIMULATE_BUILTIN_FUNCTION_DECL
+#define LANG_HOOKS_SIMULATE_BUILTIN_FUNCTION_DECL \
+ c_simulate_builtin_function_decl
#undef LANG_HOOKS_EMITS_BEGIN_STMT
#define LANG_HOOKS_EMITS_BEGIN_STMT true
diff --git a/gcc/c/c-tree.h b/gcc/c/c-tree.h
index dae2979..d01d422 100644
--- a/gcc/c/c-tree.h
+++ b/gcc/c/c-tree.h
@@ -579,6 +579,7 @@ extern struct c_declarator *set_array_declarator_inner (struct c_declarator *,
struct c_declarator *);
extern tree c_builtin_function (tree);
extern tree c_builtin_function_ext_scope (tree);
+extern tree c_simulate_builtin_function_decl (tree);
extern void shadow_tag (const struct c_declspecs *);
extern void shadow_tag_warned (const struct c_declspecs *, int);
extern tree start_enum (location_t, struct c_enum_contents *, tree);