summaryrefslogtreecommitdiffstats
path: root/gcc
diff options
context:
space:
mode:
authorWilco Dijkstra <wilco.dijkstra@arm.com>2022-05-18 16:02:12 +0100
committerWilco Dijkstra <wdijkstr@arm.com>2022-05-20 15:10:37 +0100
commit1be715f31605976d8e4336973d3b81c5b7cea79f (patch)
tree0adb70628d3362e551d54c5edb49a5f3b08116e7 /gcc
parentUse "final" and "override" directly, rather than via macros (diff)
downloadgcc-1be715f31605976d8e4336973d3b81c5b7cea79f.tar.gz
gcc-1be715f31605976d8e4336973d3b81c5b7cea79f.tar.bz2
gcc-1be715f31605976d8e4336973d3b81c5b7cea79f.tar.xz
AArch64: Cleanup CPU option processing code
The --with-cpu/--with-arch configure option processing not only checks valid arguments but also sets TARGET_CPU_DEFAULT with a CPU and extension bitmask. This isn't used however since a --with-cpu is translated into a -mcpu option which is processed as if written on the command-line (so TARGET_CPU_DEFAULT is never accessed). So remove all the complex processing and bitmask, and just validate the option. Fix a bug that always reports valid architecture extensions as invalid. As a result the CPU processing in aarch64.c can be simplified. gcc/ * config.gcc (aarch64*-*-*): Simplify --with-cpu and --with-arch processing. Add support for architectural extensions. * config/aarch64/aarch64.h (TARGET_CPU_DEFAULT): Remove AARCH64_CPU_DEFAULT_FLAGS. (TARGET_CPU_NBITS): Remove. (TARGET_CPU_MASK): Remove. * config/aarch64/aarch64.cc (AARCH64_CPU_DEFAULT_FLAGS): Remove define. (get_tune_cpu): Assert CPU is always valid. (get_arch): Assert architecture is always valid. (aarch64_override_options): Cleanup CPU selection code and simplify logic. (aarch64_option_restore): Remove unnecessary checks on tune.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/config.gcc43
-rw-r--r--gcc/config/aarch64/aarch64.cc115
-rw-r--r--gcc/config/aarch64/aarch64.h9
3 files changed, 32 insertions, 135 deletions
diff --git a/gcc/config.gcc b/gcc/config.gcc
index c5064dd3766..b48d5451e80 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -4178,8 +4178,6 @@ case "${target}" in
4178 pattern=AARCH64_CORE 4178 pattern=AARCH64_CORE
4179 fi 4179 fi
4180 4180
4181 ext_mask=AARCH64_CPU_DEFAULT_FLAGS
4182
4183 # Find the base CPU or ARCH id in aarch64-cores.def or 4181 # Find the base CPU or ARCH id in aarch64-cores.def or
4184 # aarch64-arches.def 4182 # aarch64-arches.def
4185 if [ x"$base_val" = x ] \ 4183 if [ x"$base_val" = x ] \
@@ -4187,23 +4185,6 @@ case "${target}" in
4187 ${srcdir}/config/aarch64/$def \ 4185 ${srcdir}/config/aarch64/$def \
4188 > /dev/null; then 4186 > /dev/null; then
4189 4187
4190 if [ $which = arch ]; then
4191 base_id=`grep "^$pattern(\"$base_val\"," \
4192 ${srcdir}/config/aarch64/$def | \
4193 sed -e 's/^[^,]*,[ ]*//' | \
4194 sed -e 's/,.*$//'`
4195 # Extract the architecture flags from aarch64-arches.def
4196 ext_mask=`grep "^$pattern(\"$base_val\"," \
4197 ${srcdir}/config/aarch64/$def | \
4198 sed -e 's/)$//' | \
4199 sed -e 's/^.*,//'`
4200 else
4201 base_id=`grep "^$pattern(\"$base_val\"," \
4202 ${srcdir}/config/aarch64/$def | \
4203 sed -e 's/^[^,]*,[ ]*//' | \
4204 sed -e 's/,.*$//'`
4205 fi
4206
4207 # Disallow extensions in --with-tune=cortex-a53+crc. 4188 # Disallow extensions in --with-tune=cortex-a53+crc.
4208 if [ $which = tune ] && [ x"$ext_val" != x ]; then 4189 if [ $which = tune ] && [ x"$ext_val" != x ]; then
4209 echo "Architecture extensions not supported in --with-$which=$val" 1>&2 4190 echo "Architecture extensions not supported in --with-$which=$val" 1>&2
@@ -4234,25 +4215,7 @@ case "${target}" in
4234 grep "^\"$base_ext\""` 4215 grep "^\"$base_ext\""`
4235 4216
4236 if [ x"$base_ext" = x ] \ 4217 if [ x"$base_ext" = x ] \
4237 || [[ -n $opt_line ]]; then 4218 || [ x"$opt_line" != x ]; then
4238
4239 # These regexp extract the elements based on
4240 # their group match index in the regexp.
4241 ext_canon=`echo -e "$opt_line" | \
4242 sed -e "s/$sed_patt/\2/"`
4243 ext_on=`echo -e "$opt_line" | \
4244 sed -e "s/$sed_patt/\3/"`
4245 ext_off=`echo -e "$opt_line" | \
4246 sed -e "s/$sed_patt/\4/"`
4247
4248 if [ $ext = $base_ext ]; then
4249 # Adding extension
4250 ext_mask="("$ext_mask") | ("$ext_on" | "$ext_canon")"
4251 else
4252 # Removing extension
4253 ext_mask="("$ext_mask") & ~("$ext_off" | "$ext_canon")"
4254 fi
4255
4256 true 4219 true
4257 else 4220 else
4258 echo "Unknown extension used in --with-$which=$val" 1>&2 4221 echo "Unknown extension used in --with-$which=$val" 1>&2
@@ -4261,10 +4224,6 @@ case "${target}" in
4261 ext_val=`echo $ext_val | sed -e 's/[a-z0-9]\+//'` 4224 ext_val=`echo $ext_val | sed -e 's/[a-z0-9]\+//'`
4262 done 4225 done
4263 4226
4264 ext_mask="(("$ext_mask") << TARGET_CPU_NBITS)"
4265 if [ x"$base_id" != x ]; then
4266 target_cpu_cname="TARGET_CPU_$base_id | $ext_mask"
4267 fi
4268 true 4227 true
4269 else 4228 else
4270 # Allow --with-$which=native. 4229 # Allow --with-$which=native.
diff --git a/gcc/config/aarch64/aarch64.cc b/gcc/config/aarch64/aarch64.cc
index 4aad14cc8d3..ba5b6be850a 100644
--- a/gcc/config/aarch64/aarch64.cc
+++ b/gcc/config/aarch64/aarch64.cc
@@ -2760,8 +2760,6 @@ static const struct attribute_spec aarch64_attribute_table[] =
2760 { NULL, 0, 0, false, false, false, false, NULL, NULL } 2760 { NULL, 0, 0, false, false, false, false, NULL, NULL }
2761}; 2761};
2762 2762
2763#define AARCH64_CPU_DEFAULT_FLAGS ((selected_cpu) ? selected_cpu->flags : 0)
2764
2765/* An ISA extension in the co-processor and main instruction set space. */ 2763/* An ISA extension in the co-processor and main instruction set space. */
2766struct aarch64_option_extension 2764struct aarch64_option_extension
2767{ 2765{
@@ -18067,39 +18065,24 @@ aarch64_validate_mtune (const char *str, const struct processor **res)
18067 return false; 18065 return false;
18068} 18066}
18069 18067
18070static_assert (TARGET_CPU_generic < TARGET_CPU_MASK, 18068/* Return the CPU corresponding to the enum CPU. */
18071 "TARGET_CPU_NBITS is big enough");
18072
18073/* Return the CPU corresponding to the enum CPU.
18074 If it doesn't specify a cpu, return the default. */
18075 18069
18076static const struct processor * 18070static const struct processor *
18077aarch64_get_tune_cpu (enum aarch64_processor cpu) 18071aarch64_get_tune_cpu (enum aarch64_processor cpu)
18078{ 18072{
18079 if (cpu != aarch64_none) 18073 gcc_assert (cpu != aarch64_none);
18080 return &all_cores[cpu];
18081 18074
18082 /* The & TARGET_CPU_MASK is to extract the bottom TARGET_CPU_NBITS bits that 18075 return &all_cores[cpu];
18083 encode the default cpu as selected by the --with-cpu GCC configure option
18084 in config.gcc.
18085 ???: The whole TARGET_CPU_DEFAULT and AARCH64_CPU_DEFAULT_FLAGS
18086 flags mechanism should be reworked to make it more sane. */
18087 return &all_cores[TARGET_CPU_DEFAULT & TARGET_CPU_MASK];
18088} 18076}
18089 18077
18090/* Return the architecture corresponding to the enum ARCH. 18078/* Return the architecture corresponding to the enum ARCH. */
18091 If it doesn't specify a valid architecture, return the default. */
18092 18079
18093static const struct processor * 18080static const struct processor *
18094aarch64_get_arch (enum aarch64_arch arch) 18081aarch64_get_arch (enum aarch64_arch arch)
18095{ 18082{
18096 if (arch != aarch64_no_arch) 18083 gcc_assert (arch != aarch64_no_arch);
18097 return &all_architectures[arch];
18098
18099 const struct processor *cpu
18100 = &all_cores[TARGET_CPU_DEFAULT & TARGET_CPU_MASK];
18101 18084
18102 return &all_architectures[cpu->arch]; 18085 return &all_architectures[arch];
18103} 18086}
18104 18087
18105/* Return the VG value associated with -msve-vector-bits= value VALUE. */ 18088/* Return the VG value associated with -msve-vector-bits= value VALUE. */
@@ -18137,10 +18120,6 @@ aarch64_override_options (void)
18137 uint64_t arch_isa = 0; 18120 uint64_t arch_isa = 0;
18138 aarch64_isa_flags = 0; 18121 aarch64_isa_flags = 0;
18139 18122
18140 bool valid_cpu = true;
18141 bool valid_tune = true;
18142 bool valid_arch = true;
18143
18144 selected_cpu = NULL; 18123 selected_cpu = NULL;
18145 selected_arch = NULL; 18124 selected_arch = NULL;
18146 selected_tune = NULL; 18125 selected_tune = NULL;
@@ -18155,77 +18134,56 @@ aarch64_override_options (void)
18155 If either of -march or -mtune is given, they override their 18134 If either of -march or -mtune is given, they override their
18156 respective component of -mcpu. */ 18135 respective component of -mcpu. */
18157 if (aarch64_cpu_string) 18136 if (aarch64_cpu_string)
18158 valid_cpu = aarch64_validate_mcpu (aarch64_cpu_string, &selected_cpu, 18137 aarch64_validate_mcpu (aarch64_cpu_string, &selected_cpu, &cpu_isa);
18159 &cpu_isa);
18160 18138
18161 if (aarch64_arch_string) 18139 if (aarch64_arch_string)
18162 valid_arch = aarch64_validate_march (aarch64_arch_string, &selected_arch, 18140 aarch64_validate_march (aarch64_arch_string, &selected_arch, &arch_isa);
18163 &arch_isa);
18164 18141
18165 if (aarch64_tune_string) 18142 if (aarch64_tune_string)
18166 valid_tune = aarch64_validate_mtune (aarch64_tune_string, &selected_tune); 18143 aarch64_validate_mtune (aarch64_tune_string, &selected_tune);
18167 18144
18168#ifdef SUBTARGET_OVERRIDE_OPTIONS 18145#ifdef SUBTARGET_OVERRIDE_OPTIONS
18169 SUBTARGET_OVERRIDE_OPTIONS; 18146 SUBTARGET_OVERRIDE_OPTIONS;
18170#endif 18147#endif
18171 18148
18172 /* If the user did not specify a processor, choose the default 18149 if (selected_cpu && selected_arch)
18173 one for them. This will be the CPU set during configuration using
18174 --with-cpu, otherwise it is "generic". */
18175 if (!selected_cpu)
18176 {
18177 if (selected_arch)
18178 {
18179 selected_cpu = &all_cores[selected_arch->ident];
18180 aarch64_isa_flags = arch_isa;
18181 explicit_arch = selected_arch->arch;
18182 }
18183 else
18184 {
18185 /* Get default configure-time CPU. */
18186 selected_cpu = aarch64_get_tune_cpu (aarch64_none);
18187 aarch64_isa_flags = TARGET_CPU_DEFAULT >> TARGET_CPU_NBITS;
18188 }
18189
18190 if (selected_tune)
18191 explicit_tune_core = selected_tune->ident;
18192 }
18193 /* If both -mcpu and -march are specified check that they are architecturally
18194 compatible, warn if they're not and prefer the -march ISA flags. */
18195 else if (selected_arch)
18196 { 18150 {
18151 /* If both -mcpu and -march are specified, warn if they are not
18152 architecturally compatible and prefer the -march ISA flags. */
18197 if (selected_arch->arch != selected_cpu->arch) 18153 if (selected_arch->arch != selected_cpu->arch)
18198 { 18154 {
18199 warning (0, "switch %<-mcpu=%s%> conflicts with %<-march=%s%> switch", 18155 warning (0, "switch %<-mcpu=%s%> conflicts with %<-march=%s%> switch",
18200 aarch64_cpu_string, 18156 aarch64_cpu_string,
18201 aarch64_arch_string); 18157 aarch64_arch_string);
18202 } 18158 }
18159
18203 aarch64_isa_flags = arch_isa; 18160 aarch64_isa_flags = arch_isa;
18204 explicit_arch = selected_arch->arch;
18205 explicit_tune_core = selected_tune ? selected_tune->ident
18206 : selected_cpu->ident;
18207 } 18161 }
18208 else 18162 else if (selected_cpu)
18209 { 18163 {
18210 /* -mcpu but no -march. */
18211 aarch64_isa_flags = cpu_isa;
18212 explicit_tune_core = selected_tune ? selected_tune->ident
18213 : selected_cpu->ident;
18214 gcc_assert (selected_cpu);
18215 selected_arch = &all_architectures[selected_cpu->arch]; 18164 selected_arch = &all_architectures[selected_cpu->arch];
18216 explicit_arch = selected_arch->arch; 18165 aarch64_isa_flags = cpu_isa;
18217 } 18166 }
18218 18167 else if (selected_arch)
18219 /* Set the arch as well as we will need it when outputing
18220 the .arch directive in assembly. */
18221 if (!selected_arch)
18222 { 18168 {
18223 gcc_assert (selected_cpu); 18169 selected_cpu = &all_cores[selected_arch->ident];
18170 aarch64_isa_flags = arch_isa;
18171 }
18172 else
18173 {
18174 /* No -mcpu or -march specified, so use the default CPU. */
18175 selected_cpu = &all_cores[TARGET_CPU_DEFAULT];
18224 selected_arch = &all_architectures[selected_cpu->arch]; 18176 selected_arch = &all_architectures[selected_cpu->arch];
18177 aarch64_isa_flags = selected_cpu->flags;
18225 } 18178 }
18226 18179
18180 explicit_arch = selected_arch->arch;
18227 if (!selected_tune) 18181 if (!selected_tune)
18228 selected_tune = selected_cpu; 18182 selected_tune = selected_cpu;
18183 explicit_tune_core = selected_tune->ident;
18184
18185 gcc_assert (explicit_tune_core != aarch64_none);
18186 gcc_assert (explicit_arch != aarch64_no_arch);
18229 18187
18230 if (aarch64_enable_bti == 2) 18188 if (aarch64_enable_bti == 2)
18231 { 18189 {
@@ -18261,15 +18219,6 @@ aarch64_override_options (void)
18261 if (aarch64_ra_sign_scope != AARCH64_FUNCTION_NONE && TARGET_ILP32) 18219 if (aarch64_ra_sign_scope != AARCH64_FUNCTION_NONE && TARGET_ILP32)
18262 sorry ("return address signing is only supported for %<-mabi=lp64%>"); 18220 sorry ("return address signing is only supported for %<-mabi=lp64%>");
18263 18221
18264 /* Make sure we properly set up the explicit options. */
18265 if ((aarch64_cpu_string && valid_cpu)
18266 || (aarch64_tune_string && valid_tune))
18267 gcc_assert (explicit_tune_core != aarch64_none);
18268
18269 if ((aarch64_cpu_string && valid_cpu)
18270 || (aarch64_arch_string && valid_arch))
18271 gcc_assert (explicit_arch != aarch64_no_arch);
18272
18273 /* The pass to insert speculation tracking runs before 18222 /* The pass to insert speculation tracking runs before
18274 shrink-wrapping and the latter does not know how to update the 18223 shrink-wrapping and the latter does not know how to update the
18275 tracking status. So disable it in this case. */ 18224 tracking status. So disable it in this case. */
@@ -18375,11 +18324,7 @@ aarch64_option_restore (struct gcc_options *opts,
18375 opts->x_explicit_arch = ptr->x_explicit_arch; 18324 opts->x_explicit_arch = ptr->x_explicit_arch;
18376 selected_arch = aarch64_get_arch (ptr->x_explicit_arch); 18325 selected_arch = aarch64_get_arch (ptr->x_explicit_arch);
18377 opts->x_explicit_tune_core = ptr->x_explicit_tune_core; 18326 opts->x_explicit_tune_core = ptr->x_explicit_tune_core;
18378 if (opts->x_explicit_tune_core == aarch64_none 18327 selected_tune = aarch64_get_tune_cpu (ptr->x_explicit_tune_core);
18379 && opts->x_explicit_arch != aarch64_no_arch)
18380 selected_tune = &all_cores[selected_arch->ident];
18381 else
18382 selected_tune = aarch64_get_tune_cpu (ptr->x_explicit_tune_core);
18383 opts->x_aarch64_override_tune_string = ptr->x_aarch64_override_tune_string; 18328 opts->x_aarch64_override_tune_string = ptr->x_aarch64_override_tune_string;
18384 opts->x_aarch64_branch_protection_string 18329 opts->x_aarch64_branch_protection_string
18385 = ptr->x_aarch64_branch_protection_string; 18330 = ptr->x_aarch64_branch_protection_string;
diff --git a/gcc/config/aarch64/aarch64.h b/gcc/config/aarch64/aarch64.h
index 359b6e8561f..f835da33b72 100644
--- a/gcc/config/aarch64/aarch64.h
+++ b/gcc/config/aarch64/aarch64.h
@@ -813,16 +813,9 @@ enum target_cpus
813 TARGET_CPU_generic 813 TARGET_CPU_generic
814}; 814};
815 815
816/* Define how many bits are used to represent the CPU in TARGET_CPU_DEFAULT.
817 This needs to be big enough to fit the value of TARGET_CPU_generic.
818 All bits after this are used to represent the AARCH64_CPU_DEFAULT_FLAGS. */
819#define TARGET_CPU_NBITS 8
820#define TARGET_CPU_MASK ((1 << TARGET_CPU_NBITS) - 1)
821
822/* If there is no CPU defined at configure, use generic as default. */ 816/* If there is no CPU defined at configure, use generic as default. */
823#ifndef TARGET_CPU_DEFAULT 817#ifndef TARGET_CPU_DEFAULT
824#define TARGET_CPU_DEFAULT \ 818# define TARGET_CPU_DEFAULT TARGET_CPU_generic
825 (TARGET_CPU_generic | (AARCH64_CPU_DEFAULT_FLAGS << TARGET_CPU_NBITS))
826#endif 819#endif
827 820
828/* If inserting NOP before a mult-accumulate insn remember to adjust the 821/* If inserting NOP before a mult-accumulate insn remember to adjust the