aarch64: Add attributes for builtins specified in aarch64-builtins.c

Besides the builtins in aarch64-simd-builtins.def there are a number of builtins defined in aarch64-builtins.c itself.
They could also benefit from the attributes generated by aarch64_get_attributes.
However aarch64_get_attributes and its helpers are only set up to handle a aarch64_simd_builtin_datum.

This patch changes these functions to instead take a flag and mode value that are extracted from
aarch64_simd_builtin_datum.flags and aarch64_simd_builtin_datum.mode anyway.
Then the various builtin init functions in aarch64-builtins.c can pass down their own FLAG_* flags
that they want to derive attributes from.

gcc/ChangeLog:

	* config/aarch64/aarch64-builtins.c (aarch64_call_properties):
	Take a flag and mode value as arguments.
	(aarch64_modifies_global_state_p): Likewise.
	(aarch64_reads_global_state_p): Likewise.
	(aarch64_could_trap_p): Likewise.
	(aarch64_get_attributes): Likewise.
	(aarch64_init_simd_builtins): Adjust callsite of above.
	(aarch64_init_fcmla_laneq_builtins): Use aarch64_get_attributes to get
	function attributes to apply to builtins.
	(aarch64_init_crc32_builtins): Likewise.
	(aarch64_init_builtin_rsqrt): Likewise.
diff --git a/gcc/config/aarch64/aarch64-builtins.c b/gcc/config/aarch64/aarch64-builtins.c
index acdea2a..3cab3ec 100644
--- a/gcc/config/aarch64/aarch64-builtins.c
+++ b/gcc/config/aarch64/aarch64-builtins.c
@@ -906,14 +906,13 @@
 					     "__builtin_aarch64_simd_udi");
 }
 
-/* Return a set of FLAG_* flags that describe what the function could do,
+/* Return a set of FLAG_* flags derived from FLAGS
+   that describe what a function with result MODE could do,
    taking the command-line flags into account.  */
 static unsigned int
-aarch64_call_properties (aarch64_simd_builtin_datum *d)
+aarch64_call_properties (unsigned int flags, machine_mode mode)
 {
-  unsigned int flags = d->flags;
-
-  if (!(flags & FLAG_AUTO_FP) && FLOAT_MODE_P (d->mode))
+  if (!(flags & FLAG_AUTO_FP) && FLOAT_MODE_P (mode))
     flags |= FLAG_FP;
 
   /* -fno-trapping-math means that we can assume any FP exceptions
@@ -924,12 +923,12 @@
   return flags;
 }
 
-/* Return true if calls to the function could modify some form of
-   global state.  */
+/* Return true if calls to a function with flags F and mode MODE
+   could modify some form of global state.  */
 static bool
-aarch64_modifies_global_state_p (aarch64_simd_builtin_datum *d)
+aarch64_modifies_global_state_p (unsigned int f, machine_mode mode)
 {
-  unsigned int flags = aarch64_call_properties (d);
+  unsigned int flags = aarch64_call_properties (f, mode);
 
   if (flags & FLAG_RAISE_FP_EXCEPTIONS)
     return true;
@@ -940,12 +939,12 @@
   return flags & FLAG_WRITE_MEMORY;
 }
 
-/* Return true if calls to the function could read some form of
-   global state.  */
+/* Return true if calls to a function with flags F and mode MODE
+   could read some form of global state.  */
 static bool
-aarch64_reads_global_state_p (aarch64_simd_builtin_datum *d)
+aarch64_reads_global_state_p (unsigned int f, machine_mode mode)
 {
-  unsigned int flags = aarch64_call_properties (d);
+  unsigned int flags = aarch64_call_properties (f,  mode);
 
   if (flags & FLAG_READ_FPCR)
     return true;
@@ -953,11 +952,12 @@
   return flags & FLAG_READ_MEMORY;
 }
 
-/* Return true if calls to the function could raise a signal.  */
+/* Return true if calls to a function with flags F and mode MODE
+   could raise a signal.  */
 static bool
-aarch64_could_trap_p (aarch64_simd_builtin_datum *d)
+aarch64_could_trap_p (unsigned int f, machine_mode mode)
 {
-  unsigned int flags = aarch64_call_properties (d);
+  unsigned int flags = aarch64_call_properties (f, mode);
 
   if (flags & FLAG_RAISE_FP_EXCEPTIONS)
     return true;
@@ -975,21 +975,22 @@
   return tree_cons (get_identifier (name), NULL_TREE, attrs);
 }
 
-/* Return the appropriate function attributes.  */
+/* Return the appropriate attributes for a function that has
+   flags F and mode MODE.  */
 static tree
-aarch64_get_attributes (aarch64_simd_builtin_datum *d)
+aarch64_get_attributes (unsigned int f, machine_mode mode)
 {
   tree attrs = NULL_TREE;
 
-  if (!aarch64_modifies_global_state_p (d))
+  if (!aarch64_modifies_global_state_p (f, mode))
     {
-      if (aarch64_reads_global_state_p (d))
+      if (aarch64_reads_global_state_p (f, mode))
 	attrs = aarch64_add_attribute ("pure", attrs);
       else
 	attrs = aarch64_add_attribute ("const", attrs);
     }
 
-  if (!flag_non_call_exceptions || !aarch64_could_trap_p (d))
+  if (!flag_non_call_exceptions || !aarch64_could_trap_p (f, mode))
     attrs = aarch64_add_attribute ("nothrow", attrs);
 
   return aarch64_add_attribute ("leaf", attrs);
@@ -1018,7 +1019,9 @@
 	= aarch64_simd_builtin_std_type (SImode, qualifier_lane_pair_index);
       tree ftype = build_function_type_list (argtype, argtype, argtype,
 					     quadtype, lanetype, NULL_TREE);
-      tree fndecl = aarch64_general_add_builtin (d->name, ftype, d->fcode);
+      tree attrs = aarch64_get_attributes (FLAG_FP, d->mode);
+      tree fndecl
+	= aarch64_general_add_builtin (d->name, ftype, d->fcode, attrs);
 
       aarch64_builtin_decls[d->fcode] = fndecl;
     }
@@ -1148,7 +1151,7 @@
 	snprintf (namebuf, sizeof (namebuf), "__builtin_aarch64_%s",
 		  d->name);
 
-      tree attrs = aarch64_get_attributes (d);
+      tree attrs = aarch64_get_attributes (d->flags, d->mode);
 
       fndecl = aarch64_general_add_builtin (namebuf, ftype, fcode, attrs);
       aarch64_builtin_decls[fcode] = fndecl;
@@ -1170,7 +1173,9 @@
       tree argtype = aarch64_simd_builtin_std_type (d->mode,
 						    qualifier_unsigned);
       tree ftype = build_function_type_list (usi_type, usi_type, argtype, NULL_TREE);
-      tree fndecl = aarch64_general_add_builtin (d->name, ftype, d->fcode);
+      tree attrs = aarch64_get_attributes (FLAG_NONE, d->mode);
+      tree fndecl
+	= aarch64_general_add_builtin (d->name, ftype, d->fcode, attrs);
 
       aarch64_builtin_decls[d->fcode] = fndecl;
     }
@@ -1210,8 +1215,9 @@
   for (; bdd < bdd_end; bdd++)
   {
     ftype = build_function_type_list (bdd->type_node, bdd->type_node, NULL_TREE);
+    tree attrs = aarch64_get_attributes (FLAG_FP, TYPE_MODE (bdd->type_node));
     fndecl = aarch64_general_add_builtin (bdd->builtin_name,
-					  ftype, bdd->function_code);
+					  ftype, bdd->function_code, attrs);
     aarch64_builtin_decls[bdd->function_code] = fndecl;
   }
 }