aboutsummaryrefslogtreecommitdiff
path: root/gcc/common/config/aarch64
diff options
context:
space:
mode:
authorAndrew Carlotti <andrew.carlotti@arm.com>2025-01-23 19:07:09 +0000
committerAndrew Carlotti <andrew.carlotti@arm.com>2025-01-24 19:09:09 +0000
commitc6ef35b4c3c092bf5e0171827ed918d4249575ca (patch)
tree39cd16135c743bd63edd6103a78c2be3a977a805 /gcc/common/config/aarch64
parent15e07e14372cfeb53cbdfb7cf96a8a49e402da68 (diff)
downloadgcc-c6ef35b4c3c092bf5e0171827ed918d4249575ca.zip
gcc-c6ef35b4c3c092bf5e0171827ed918d4249575ca.tar.gz
gcc-c6ef35b4c3c092bf5e0171827ed918d4249575ca.tar.bz2
aarch64: Refactor aarch64_rewrite_mcpu
Use aarch64_validate_cpu instead of the existing duplicate (and worse) version of the -mcpu parsing code. The original code used fatal_error; I'm guessing that using error instead should be ok. gcc/ChangeLog: * common/config/aarch64/aarch64-common.cc (aarch64_rewrite_selected_cpu): Refactor and inline into... (aarch64_rewrite_mcpu): this. * config/aarch64/aarch64-protos.h (aarch64_rewrite_selected_cpu): Delete.
Diffstat (limited to 'gcc/common/config/aarch64')
-rw-r--r--gcc/common/config/aarch64/aarch64-common.cc78
1 files changed, 17 insertions, 61 deletions
diff --git a/gcc/common/config/aarch64/aarch64-common.cc b/gcc/common/config/aarch64/aarch64-common.cc
index abb9565..427a193 100644
--- a/gcc/common/config/aarch64/aarch64-common.cc
+++ b/gcc/common/config/aarch64/aarch64-common.cc
@@ -732,60 +732,29 @@ aarch64_rewrite_march (int argc, const char **argv)
return xstrdup (outstr.c_str ());
}
-/* Attempt to rewrite NAME, which has been passed on the command line
- as a -mcpu option to an equivalent -march value. If we can do so,
- return the new string, otherwise return an error. */
+/* Called by the driver to rewrite a name passed to the -mcpu argument
+ to an equivalent -march value to be passed to the assembler. The
+ names passed from the commend line will be in ARGV, we want
+ to use the right-most argument, which should be in
+ ARGV[ARGC - 1]. ARGC should always be greater than 0. */
const char *
-aarch64_rewrite_selected_cpu (const char *name)
+aarch64_rewrite_mcpu (int argc, const char **argv)
{
- std::string original_string (name);
- std::string extension_str;
- std::string processor;
- size_t extension_pos = original_string.find_first_of ('+');
-
- /* Strip and save the extension string. */
- if (extension_pos != std::string::npos)
- {
- processor = original_string.substr (0, extension_pos);
- extension_str = original_string.substr (extension_pos,
- std::string::npos);
- }
- else
- {
- /* No extensions. */
- processor = original_string;
- }
-
- const struct aarch64_processor_info* p_to_a;
- for (p_to_a = all_cores;
- p_to_a->arch != aarch64_no_arch;
- p_to_a++)
- {
- if (p_to_a->name == processor)
- break;
- }
-
- const struct aarch64_arch_info* a_to_an;
- for (a_to_an = all_architectures;
- a_to_an->arch != aarch64_no_arch;
- a_to_an++)
- {
- if (a_to_an->arch == p_to_a->arch)
- break;
- }
+ gcc_assert (argc);
+ const char *name = argv[argc - 1];
+ aarch64_cpu cpu;
+ aarch64_feature_flags flags;
- /* We couldn't find that processor name, or the processor name we
- found does not map to an architecture we understand. */
- if (p_to_a->arch == aarch64_no_arch
- || a_to_an->arch == aarch64_no_arch)
- fatal_error (input_location, "unknown value %qs for %<-mcpu%>", name);
+ aarch64_validate_mcpu (name, &cpu, &flags);
- aarch64_feature_flags extensions = p_to_a->flags;
- aarch64_parse_extension (extension_str.c_str (), &extensions, NULL);
+ const struct aarch64_processor_info *entry;
+ for (entry = all_cores; entry->processor != aarch64_no_cpu; entry++)
+ if (entry->processor == cpu)
+ break;
- std::string outstr = aarch64_get_arch_string_for_assembler (a_to_an->arch,
- extensions);
+ std::string outstr = aarch64_get_arch_string_for_assembler (entry->arch,
+ flags);
/* We are going to memory leak here, nobody elsewhere
in the callchain is going to clean up after us. The alternative is
@@ -794,19 +763,6 @@ aarch64_rewrite_selected_cpu (const char *name)
return xstrdup (outstr.c_str ());
}
-/* Called by the driver to rewrite a name passed to the -mcpu
- argument in preparation to be passed to the assembler. The
- names passed from the commend line will be in ARGV, we want
- to use the right-most argument, which should be in
- ARGV[ARGC - 1]. ARGC should always be greater than 0. */
-
-const char *
-aarch64_rewrite_mcpu (int argc, const char **argv)
-{
- gcc_assert (argc);
- return aarch64_rewrite_selected_cpu (argv[argc - 1]);
-}
-
/* Checks to see if the host CPU may not be Cortex-A53 or an unknown Armv8-a
baseline CPU. */