diff mbox series

[v2,05/11] aarch64: Define aarch64_get_{asm_|}isa_flags

Message ID 83b61b47-7c57-0019-203a-ad33edd78754@e124511.cambridge.arm.com
State New
Headers show
Series aarch64: Extend aarch64_feature_flags to 128 bits | expand

Commit Message

Andrew Carlotti July 11, 2024, 12:13 p.m. UTC
Building an aarch64_feature_flags value from data within a gcc_options
or cl_target_option struct will get more complicated in a later commit.
Use a macro to avoid doing this manually in more than one location.

gcc/ChangeLog:

	* common/config/aarch64/aarch64-common.cc
	(aarch64_handle_option): Use new macro.
	* config/aarch64/aarch64.cc
	(aarch64_override_options_internal): Ditto.
	(aarch64_option_print): Ditto.
	(aarch64_set_current_function): Ditto.
	(aarch64_can_inline_p): Ditto.
	(aarch64_declare_function_name): Ditto.
	(aarch64_start_file): Ditto.
	* config/aarch64/aarch64.h (aarch64_get_asm_isa_flags): New
	(aarch64_get_isa_flags): New.
	(aarch64_asm_isa_flags): Use new macro.
	(aarch64_isa_flags): Ditto.

Comments

Richard Sandiford July 11, 2024, 5:16 p.m. UTC | #1
Andrew Carlotti <andrew.carlotti@arm.com> writes:
> Building an aarch64_feature_flags value from data within a gcc_options
> or cl_target_option struct will get more complicated in a later commit.
> Use a macro to avoid doing this manually in more than one location.
>
> gcc/ChangeLog:
>
> 	* common/config/aarch64/aarch64-common.cc
> 	(aarch64_handle_option): Use new macro.
> 	* config/aarch64/aarch64.cc
> 	(aarch64_override_options_internal): Ditto.
> 	(aarch64_option_print): Ditto.
> 	(aarch64_set_current_function): Ditto.
> 	(aarch64_can_inline_p): Ditto.
> 	(aarch64_declare_function_name): Ditto.
> 	(aarch64_start_file): Ditto.
> 	* config/aarch64/aarch64.h (aarch64_get_asm_isa_flags): New
> 	(aarch64_get_isa_flags): New.
> 	(aarch64_asm_isa_flags): Use new macro.
> 	(aarch64_isa_flags): Ditto.

OK, thanks.

Richard

>
>
> diff --git a/gcc/common/config/aarch64/aarch64-common.cc b/gcc/common/config/aarch64/aarch64-common.cc
> index 951d041d3109b935e90a7cb5d714940414e81761..63c50189a09d5c7c713f57e23a8172f44bf6bec5 100644
> --- a/gcc/common/config/aarch64/aarch64-common.cc
> +++ b/gcc/common/config/aarch64/aarch64-common.cc
> @@ -111,7 +111,7 @@ aarch64_handle_option (struct gcc_options *opts,
>  
>      case OPT_mgeneral_regs_only:
>        opts->x_target_flags |= MASK_GENERAL_REGS_ONLY;
> -      aarch64_set_asm_isa_flags (opts, opts->x_aarch64_asm_isa_flags);
> +      aarch64_set_asm_isa_flags (opts, aarch64_get_asm_isa_flags (opts));
>        return true;
>  
>      case OPT_mfix_cortex_a53_835769:
> diff --git a/gcc/config/aarch64/aarch64.h b/gcc/config/aarch64/aarch64.h
> index dfb244307635a7aa1c552acd55a635cd0bdeeb39..193f2486176b6bac372a143e2f52041c5a28ebaf 100644
> --- a/gcc/config/aarch64/aarch64.h
> +++ b/gcc/config/aarch64/aarch64.h
> @@ -22,15 +22,18 @@
>  #ifndef GCC_AARCH64_H
>  #define GCC_AARCH64_H
>  
> +#define aarch64_get_asm_isa_flags(opts) \
> +  (aarch64_feature_flags ((opts)->x_aarch64_asm_isa_flags))
> +#define aarch64_get_isa_flags(opts) \
> +  (aarch64_feature_flags ((opts)->x_aarch64_isa_flags))
> +
>  /* Make these flags read-only so that all uses go via
>     aarch64_set_asm_isa_flags.  */
>  #ifndef GENERATOR_FILE
>  #undef aarch64_asm_isa_flags
> -#define aarch64_asm_isa_flags \
> -  ((aarch64_feature_flags) global_options.x_aarch64_asm_isa_flags)
> +#define aarch64_asm_isa_flags (aarch64_get_asm_isa_flags (&global_options))
>  #undef aarch64_isa_flags
> -#define aarch64_isa_flags \
> -  ((aarch64_feature_flags) global_options.x_aarch64_isa_flags)
> +#define aarch64_isa_flags (aarch64_get_isa_flags (&global_options))
>  #endif
>  
>  /* Target CPU builtins.  */
> diff --git a/gcc/config/aarch64/aarch64.cc b/gcc/config/aarch64/aarch64.cc
> index 726f769e708d09285a291472bda4babcc3241d00..69f481ecfc848e6c5b61516c2f7b8bff5cd4f8b8 100644
> --- a/gcc/config/aarch64/aarch64.cc
> +++ b/gcc/config/aarch64/aarch64.cc
> @@ -18331,10 +18331,11 @@ aarch64_override_options_internal (struct gcc_options *opts)
>        && !fixed_regs[R18_REGNUM])
>      error ("%<-fsanitize=shadow-call-stack%> requires %<-ffixed-x18%>");
>  
> -  if ((opts->x_aarch64_isa_flags & (AARCH64_FL_SM_ON | AARCH64_FL_ZA_ON))
> -      && !(opts->x_aarch64_isa_flags & AARCH64_FL_SME))
> +  aarch64_feature_flags isa_flags = aarch64_get_isa_flags (opts);
> +  if ((isa_flags & (AARCH64_FL_SM_ON | AARCH64_FL_ZA_ON))
> +      && !(isa_flags & AARCH64_FL_SME))
>      {
> -      if (opts->x_aarch64_isa_flags & AARCH64_FL_SM_ON)
> +      if (isa_flags & AARCH64_FL_SM_ON)
>  	error ("streaming functions require the ISA extension %qs", "sme");
>        else
>  	error ("functions with SME state require the ISA extension %qs",
> @@ -18343,8 +18344,7 @@ aarch64_override_options_internal (struct gcc_options *opts)
>  	      " option %<-march%>, or by using the %<target%>"
>  	      " attribute or pragma", "sme");
>        opts->x_target_flags &= ~MASK_GENERAL_REGS_ONLY;
> -      auto new_flags = (opts->x_aarch64_asm_isa_flags
> -			| feature_deps::SME ().enable);
> +      auto new_flags = isa_flags | feature_deps::SME ().enable;
>        aarch64_set_asm_isa_flags (opts, new_flags);
>      }
>  
> @@ -19038,9 +19038,9 @@ aarch64_option_print (FILE *file, int indent, struct cl_target_option *ptr)
>    const struct processor *cpu
>      = aarch64_get_tune_cpu (ptr->x_selected_tune);
>    const struct processor *arch = aarch64_get_arch (ptr->x_selected_arch);
> +  aarch64_feature_flags isa_flags = aarch64_get_asm_isa_flags(ptr);
>    std::string extension
> -    = aarch64_get_extension_string_for_isa_flags (ptr->x_aarch64_asm_isa_flags,
> -						  arch->flags);
> +    = aarch64_get_extension_string_for_isa_flags (isa_flags, arch->flags);
>  
>    fprintf (file, "%*sselected tune = %s\n", indent, "", cpu->name);
>    fprintf (file, "%*sselected arch = %s%s\n", indent, "",
> @@ -19100,7 +19100,7 @@ aarch64_set_current_function (tree fndecl)
>    auto new_isa_mode = (fndecl
>  		       ? aarch64_fndecl_isa_mode (fndecl)
>  		       : AARCH64_DEFAULT_ISA_MODE);
> -  auto isa_flags = TREE_TARGET_OPTION (new_tree)->x_aarch64_isa_flags;
> +  auto isa_flags = aarch64_get_isa_flags (TREE_TARGET_OPTION (new_tree));
>  
>    static bool reported_zt0_p;
>    if (!reported_zt0_p
> @@ -20701,16 +20701,16 @@ aarch64_can_inline_p (tree caller, tree callee)
>  					   : target_option_default_node);
>  
>    /* Callee's ISA flags should be a subset of the caller's.  */
> -  auto caller_asm_isa = (caller_opts->x_aarch64_asm_isa_flags
> +  auto caller_asm_isa = (aarch64_get_asm_isa_flags (caller_opts)
>  			 & ~AARCH64_FL_ISA_MODES);
> -  auto callee_asm_isa = (callee_opts->x_aarch64_asm_isa_flags
> +  auto callee_asm_isa = (aarch64_get_asm_isa_flags (callee_opts)
>  			 & ~AARCH64_FL_ISA_MODES);
>    if (callee_asm_isa & ~caller_asm_isa)
>      return false;
>  
> -  auto caller_isa = (caller_opts->x_aarch64_isa_flags
> +  auto caller_isa = (aarch64_get_isa_flags (caller_opts)
>  		     & ~AARCH64_FL_ISA_MODES);
> -  auto callee_isa = (callee_opts->x_aarch64_isa_flags
> +  auto callee_isa = (aarch64_get_isa_flags (callee_opts)
>  		     & ~AARCH64_FL_ISA_MODES);
>    if (callee_isa & ~caller_isa)
>      return false;
> @@ -20730,8 +20730,8 @@ aarch64_can_inline_p (tree caller, tree callee)
>       PSTATE.SM mode.  Otherwise the caller and callee must agree on
>       PSTATE.SM mode, unless we can prove that the callee is naturally
>       streaming-compatible.  */
> -  auto caller_sm = (caller_opts->x_aarch64_isa_flags & AARCH64_FL_SM_STATE);
> -  auto callee_sm = (callee_opts->x_aarch64_isa_flags & AARCH64_FL_SM_STATE);
> +  auto caller_sm = (aarch64_get_isa_flags (caller_opts) & AARCH64_FL_SM_STATE);
> +  auto callee_sm = (aarch64_get_isa_flags (callee_opts) & AARCH64_FL_SM_STATE);
>    if (callee_sm
>        && caller_sm != callee_sm
>        && callee_has_property (AARCH64_IPA_SM_FIXED))
> @@ -20744,8 +20744,8 @@ aarch64_can_inline_p (tree caller, tree callee)
>  
>       The only other problematic case for ZA is inlining a function that
>       directly clobbers ZA or ZT0 into a function that has ZA or ZT0 state.  */
> -  auto caller_za = (caller_opts->x_aarch64_isa_flags & AARCH64_FL_ZA_ON);
> -  auto callee_za = (callee_opts->x_aarch64_isa_flags & AARCH64_FL_ZA_ON);
> +  auto caller_za = (aarch64_get_isa_flags (caller_opts) & AARCH64_FL_ZA_ON);
> +  auto callee_za = (aarch64_get_isa_flags (callee_opts) & AARCH64_FL_ZA_ON);
>    if (!caller_za && callee_za)
>      return false;
>    if (!callee_za
> @@ -24480,7 +24480,7 @@ aarch64_declare_function_name (FILE *stream, const char* name,
>    const struct processor *this_arch
>      = aarch64_get_arch (targ_options->x_selected_arch);
>  
> -  auto isa_flags = targ_options->x_aarch64_asm_isa_flags;
> +  auto isa_flags = aarch64_get_asm_isa_flags (targ_options);
>    std::string extension
>      = aarch64_get_extension_string_for_isa_flags (isa_flags,
>  						  this_arch->flags);
> @@ -24610,7 +24610,7 @@ aarch64_start_file (void)
>  
>    const struct processor *default_arch
>      = aarch64_get_arch (default_options->x_selected_arch);
> -  auto default_isa_flags = default_options->x_aarch64_asm_isa_flags;
> +  auto default_isa_flags = aarch64_get_asm_isa_flags (default_options);
>    std::string extension
>      = aarch64_get_extension_string_for_isa_flags (default_isa_flags,
>  						  default_arch->flags);
diff mbox series

Patch

diff --git a/gcc/common/config/aarch64/aarch64-common.cc b/gcc/common/config/aarch64/aarch64-common.cc
index 951d041d3109b935e90a7cb5d714940414e81761..63c50189a09d5c7c713f57e23a8172f44bf6bec5 100644
--- a/gcc/common/config/aarch64/aarch64-common.cc
+++ b/gcc/common/config/aarch64/aarch64-common.cc
@@ -111,7 +111,7 @@  aarch64_handle_option (struct gcc_options *opts,
 
     case OPT_mgeneral_regs_only:
       opts->x_target_flags |= MASK_GENERAL_REGS_ONLY;
-      aarch64_set_asm_isa_flags (opts, opts->x_aarch64_asm_isa_flags);
+      aarch64_set_asm_isa_flags (opts, aarch64_get_asm_isa_flags (opts));
       return true;
 
     case OPT_mfix_cortex_a53_835769:
diff --git a/gcc/config/aarch64/aarch64.h b/gcc/config/aarch64/aarch64.h
index dfb244307635a7aa1c552acd55a635cd0bdeeb39..193f2486176b6bac372a143e2f52041c5a28ebaf 100644
--- a/gcc/config/aarch64/aarch64.h
+++ b/gcc/config/aarch64/aarch64.h
@@ -22,15 +22,18 @@ 
 #ifndef GCC_AARCH64_H
 #define GCC_AARCH64_H
 
+#define aarch64_get_asm_isa_flags(opts) \
+  (aarch64_feature_flags ((opts)->x_aarch64_asm_isa_flags))
+#define aarch64_get_isa_flags(opts) \
+  (aarch64_feature_flags ((opts)->x_aarch64_isa_flags))
+
 /* Make these flags read-only so that all uses go via
    aarch64_set_asm_isa_flags.  */
 #ifndef GENERATOR_FILE
 #undef aarch64_asm_isa_flags
-#define aarch64_asm_isa_flags \
-  ((aarch64_feature_flags) global_options.x_aarch64_asm_isa_flags)
+#define aarch64_asm_isa_flags (aarch64_get_asm_isa_flags (&global_options))
 #undef aarch64_isa_flags
-#define aarch64_isa_flags \
-  ((aarch64_feature_flags) global_options.x_aarch64_isa_flags)
+#define aarch64_isa_flags (aarch64_get_isa_flags (&global_options))
 #endif
 
 /* Target CPU builtins.  */
diff --git a/gcc/config/aarch64/aarch64.cc b/gcc/config/aarch64/aarch64.cc
index 726f769e708d09285a291472bda4babcc3241d00..69f481ecfc848e6c5b61516c2f7b8bff5cd4f8b8 100644
--- a/gcc/config/aarch64/aarch64.cc
+++ b/gcc/config/aarch64/aarch64.cc
@@ -18331,10 +18331,11 @@  aarch64_override_options_internal (struct gcc_options *opts)
       && !fixed_regs[R18_REGNUM])
     error ("%<-fsanitize=shadow-call-stack%> requires %<-ffixed-x18%>");
 
-  if ((opts->x_aarch64_isa_flags & (AARCH64_FL_SM_ON | AARCH64_FL_ZA_ON))
-      && !(opts->x_aarch64_isa_flags & AARCH64_FL_SME))
+  aarch64_feature_flags isa_flags = aarch64_get_isa_flags (opts);
+  if ((isa_flags & (AARCH64_FL_SM_ON | AARCH64_FL_ZA_ON))
+      && !(isa_flags & AARCH64_FL_SME))
     {
-      if (opts->x_aarch64_isa_flags & AARCH64_FL_SM_ON)
+      if (isa_flags & AARCH64_FL_SM_ON)
 	error ("streaming functions require the ISA extension %qs", "sme");
       else
 	error ("functions with SME state require the ISA extension %qs",
@@ -18343,8 +18344,7 @@  aarch64_override_options_internal (struct gcc_options *opts)
 	      " option %<-march%>, or by using the %<target%>"
 	      " attribute or pragma", "sme");
       opts->x_target_flags &= ~MASK_GENERAL_REGS_ONLY;
-      auto new_flags = (opts->x_aarch64_asm_isa_flags
-			| feature_deps::SME ().enable);
+      auto new_flags = isa_flags | feature_deps::SME ().enable;
       aarch64_set_asm_isa_flags (opts, new_flags);
     }
 
@@ -19038,9 +19038,9 @@  aarch64_option_print (FILE *file, int indent, struct cl_target_option *ptr)
   const struct processor *cpu
     = aarch64_get_tune_cpu (ptr->x_selected_tune);
   const struct processor *arch = aarch64_get_arch (ptr->x_selected_arch);
+  aarch64_feature_flags isa_flags = aarch64_get_asm_isa_flags(ptr);
   std::string extension
-    = aarch64_get_extension_string_for_isa_flags (ptr->x_aarch64_asm_isa_flags,
-						  arch->flags);
+    = aarch64_get_extension_string_for_isa_flags (isa_flags, arch->flags);
 
   fprintf (file, "%*sselected tune = %s\n", indent, "", cpu->name);
   fprintf (file, "%*sselected arch = %s%s\n", indent, "",
@@ -19100,7 +19100,7 @@  aarch64_set_current_function (tree fndecl)
   auto new_isa_mode = (fndecl
 		       ? aarch64_fndecl_isa_mode (fndecl)
 		       : AARCH64_DEFAULT_ISA_MODE);
-  auto isa_flags = TREE_TARGET_OPTION (new_tree)->x_aarch64_isa_flags;
+  auto isa_flags = aarch64_get_isa_flags (TREE_TARGET_OPTION (new_tree));
 
   static bool reported_zt0_p;
   if (!reported_zt0_p
@@ -20701,16 +20701,16 @@  aarch64_can_inline_p (tree caller, tree callee)
 					   : target_option_default_node);
 
   /* Callee's ISA flags should be a subset of the caller's.  */
-  auto caller_asm_isa = (caller_opts->x_aarch64_asm_isa_flags
+  auto caller_asm_isa = (aarch64_get_asm_isa_flags (caller_opts)
 			 & ~AARCH64_FL_ISA_MODES);
-  auto callee_asm_isa = (callee_opts->x_aarch64_asm_isa_flags
+  auto callee_asm_isa = (aarch64_get_asm_isa_flags (callee_opts)
 			 & ~AARCH64_FL_ISA_MODES);
   if (callee_asm_isa & ~caller_asm_isa)
     return false;
 
-  auto caller_isa = (caller_opts->x_aarch64_isa_flags
+  auto caller_isa = (aarch64_get_isa_flags (caller_opts)
 		     & ~AARCH64_FL_ISA_MODES);
-  auto callee_isa = (callee_opts->x_aarch64_isa_flags
+  auto callee_isa = (aarch64_get_isa_flags (callee_opts)
 		     & ~AARCH64_FL_ISA_MODES);
   if (callee_isa & ~caller_isa)
     return false;
@@ -20730,8 +20730,8 @@  aarch64_can_inline_p (tree caller, tree callee)
      PSTATE.SM mode.  Otherwise the caller and callee must agree on
      PSTATE.SM mode, unless we can prove that the callee is naturally
      streaming-compatible.  */
-  auto caller_sm = (caller_opts->x_aarch64_isa_flags & AARCH64_FL_SM_STATE);
-  auto callee_sm = (callee_opts->x_aarch64_isa_flags & AARCH64_FL_SM_STATE);
+  auto caller_sm = (aarch64_get_isa_flags (caller_opts) & AARCH64_FL_SM_STATE);
+  auto callee_sm = (aarch64_get_isa_flags (callee_opts) & AARCH64_FL_SM_STATE);
   if (callee_sm
       && caller_sm != callee_sm
       && callee_has_property (AARCH64_IPA_SM_FIXED))
@@ -20744,8 +20744,8 @@  aarch64_can_inline_p (tree caller, tree callee)
 
      The only other problematic case for ZA is inlining a function that
      directly clobbers ZA or ZT0 into a function that has ZA or ZT0 state.  */
-  auto caller_za = (caller_opts->x_aarch64_isa_flags & AARCH64_FL_ZA_ON);
-  auto callee_za = (callee_opts->x_aarch64_isa_flags & AARCH64_FL_ZA_ON);
+  auto caller_za = (aarch64_get_isa_flags (caller_opts) & AARCH64_FL_ZA_ON);
+  auto callee_za = (aarch64_get_isa_flags (callee_opts) & AARCH64_FL_ZA_ON);
   if (!caller_za && callee_za)
     return false;
   if (!callee_za
@@ -24480,7 +24480,7 @@  aarch64_declare_function_name (FILE *stream, const char* name,
   const struct processor *this_arch
     = aarch64_get_arch (targ_options->x_selected_arch);
 
-  auto isa_flags = targ_options->x_aarch64_asm_isa_flags;
+  auto isa_flags = aarch64_get_asm_isa_flags (targ_options);
   std::string extension
     = aarch64_get_extension_string_for_isa_flags (isa_flags,
 						  this_arch->flags);
@@ -24610,7 +24610,7 @@  aarch64_start_file (void)
 
   const struct processor *default_arch
     = aarch64_get_arch (default_options->x_selected_arch);
-  auto default_isa_flags = default_options->x_aarch64_asm_isa_flags;
+  auto default_isa_flags = aarch64_get_asm_isa_flags (default_options);
   std::string extension
     = aarch64_get_extension_string_for_isa_flags (default_isa_flags,
 						  default_arch->flags);