diff options
author | Andrew Carlotti <andrew.carlotti@arm.com> | 2024-11-11 12:20:25 +0000 |
---|---|---|
committer | Andrew Carlotti <andrew.carlotti@arm.com> | 2025-01-24 19:08:41 +0000 |
commit | 15e07e14372cfeb53cbdfb7cf96a8a49e402da68 (patch) | |
tree | 76f7f4b80ad090547cbc3416816972ef0bed9b07 /gcc/common | |
parent | 1edf47698a8204da74a6f154b7380f6016f2f78b (diff) | |
download | gcc-15e07e14372cfeb53cbdfb7cf96a8a49e402da68.zip gcc-15e07e14372cfeb53cbdfb7cf96a8a49e402da68.tar.gz gcc-15e07e14372cfeb53cbdfb7cf96a8a49e402da68.tar.bz2 |
aarch64: Rewrite architecture strings for assembler
Add infrastructure to allow rewriting the architecture strings passed to
the assembler (either as -march options or .arch directives). There was
already canonicalisation everywhere except for an -march driver option
passed directly to the compiler; this patch applies the same
canonicalisation there as well.
gcc/ChangeLog:
* common/config/aarch64/aarch64-common.cc
(aarch64_get_arch_string_for_assembler): New.
(aarch64_rewrite_march): New.
(aarch64_rewrite_selected_cpu): Call new function.
* config/aarch64/aarch64-elf.h (ASM_SPEC): Remove identity mapping.
* config/aarch64/aarch64-protos.h
(aarch64_get_arch_string_for_assembler): New.
* config/aarch64/aarch64.cc
(aarch64_declare_function_name): Call new function.
(aarch64_start_file): Ditto.
* config/aarch64/aarch64.h
(EXTRA_SPEC_FUNCTIONS): Use new macro name.
(MCPU_TO_MARCH_SPEC): Rename to...
(MARCH_REWRITE_SPEC): ...this, and extend the spec rule.
(aarch64_rewrite_march): New declaration.
(MCPU_TO_MARCH_SPEC_FUNCTIONS): Rename to...
(AARCH64_BASE_SPEC_FUNCTIONS): ...this, and add new function.
(ASM_CPU_SPEC): Use new macro name.
Diffstat (limited to 'gcc/common')
-rw-r--r-- | gcc/common/config/aarch64/aarch64-common.cc | 49 |
1 files changed, 45 insertions, 4 deletions
diff --git a/gcc/common/config/aarch64/aarch64-common.cc b/gcc/common/config/aarch64/aarch64-common.cc index 9923437..abb9565 100644 --- a/gcc/common/config/aarch64/aarch64-common.cc +++ b/gcc/common/config/aarch64/aarch64-common.cc @@ -690,6 +690,48 @@ aarch64_get_extension_string_for_isa_flags return outstr; } +/* Generate an arch string to be passed to the assembler. */ + +std::string +aarch64_get_arch_string_for_assembler (aarch64_arch arch, + aarch64_feature_flags flags) +{ + const struct aarch64_arch_info *entry; + for (entry = all_architectures; entry->arch != aarch64_no_arch; entry++) + if (entry->arch == arch) + break; + + std::string outstr = entry->name + + aarch64_get_extension_string_for_isa_flags (flags, entry->flags); + + return outstr; +} + +/* Called by the driver to rewrite a name passed to the -march + 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_march (int argc, const char **argv) +{ + gcc_assert (argc); + const char *name = argv[argc - 1]; + aarch64_arch arch; + aarch64_feature_flags flags; + + aarch64_validate_march (name, &arch, &flags); + + std::string outstr = aarch64_get_arch_string_for_assembler (arch, flags); + + /* We are going to memory leak here, nobody elsewhere + in the callchain is going to clean up after us. The alternative is + to allocate a static buffer, and assert that it is big enough for our + modified string, which seems much worse! */ + 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. */ @@ -733,7 +775,7 @@ aarch64_rewrite_selected_cpu (const char *name) break; } - /* We couldn't find that proceesor name, or the processor name we + /* 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) @@ -742,9 +784,8 @@ aarch64_rewrite_selected_cpu (const char *name) aarch64_feature_flags extensions = p_to_a->flags; aarch64_parse_extension (extension_str.c_str (), &extensions, NULL); - std::string outstr = a_to_an->name - + aarch64_get_extension_string_for_isa_flags (extensions, - a_to_an->flags); + std::string outstr = aarch64_get_arch_string_for_assembler (a_to_an->arch, + extensions); /* We are going to memory leak here, nobody elsewhere in the callchain is going to clean up after us. The alternative is |