Skip to content

Commit 15e07e1

Browse files
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.
1 parent 1edf476 commit 15e07e1

File tree

5 files changed

+68
-30
lines changed

5 files changed

+68
-30
lines changed

gcc/common/config/aarch64/aarch64-common.cc

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,48 @@ aarch64_get_extension_string_for_isa_flags
690690
return outstr;
691691
}
692692

693+
/* Generate an arch string to be passed to the assembler. */
694+
695+
std::string
696+
aarch64_get_arch_string_for_assembler (aarch64_arch arch,
697+
aarch64_feature_flags flags)
698+
{
699+
const struct aarch64_arch_info *entry;
700+
for (entry = all_architectures; entry->arch != aarch64_no_arch; entry++)
701+
if (entry->arch == arch)
702+
break;
703+
704+
std::string outstr = entry->name
705+
+ aarch64_get_extension_string_for_isa_flags (flags, entry->flags);
706+
707+
return outstr;
708+
}
709+
710+
/* Called by the driver to rewrite a name passed to the -march
711+
argument in preparation to be passed to the assembler. The
712+
names passed from the commend line will be in ARGV, we want
713+
to use the right-most argument, which should be in
714+
ARGV[ARGC - 1]. ARGC should always be greater than 0. */
715+
716+
const char *
717+
aarch64_rewrite_march (int argc, const char **argv)
718+
{
719+
gcc_assert (argc);
720+
const char *name = argv[argc - 1];
721+
aarch64_arch arch;
722+
aarch64_feature_flags flags;
723+
724+
aarch64_validate_march (name, &arch, &flags);
725+
726+
std::string outstr = aarch64_get_arch_string_for_assembler (arch, flags);
727+
728+
/* We are going to memory leak here, nobody elsewhere
729+
in the callchain is going to clean up after us. The alternative is
730+
to allocate a static buffer, and assert that it is big enough for our
731+
modified string, which seems much worse! */
732+
return xstrdup (outstr.c_str ());
733+
}
734+
693735
/* Attempt to rewrite NAME, which has been passed on the command line
694736
as a -mcpu option to an equivalent -march value. If we can do so,
695737
return the new string, otherwise return an error. */
@@ -733,7 +775,7 @@ aarch64_rewrite_selected_cpu (const char *name)
733775
break;
734776
}
735777

736-
/* We couldn't find that proceesor name, or the processor name we
778+
/* We couldn't find that processor name, or the processor name we
737779
found does not map to an architecture we understand. */
738780
if (p_to_a->arch == aarch64_no_arch
739781
|| a_to_an->arch == aarch64_no_arch)
@@ -742,9 +784,8 @@ aarch64_rewrite_selected_cpu (const char *name)
742784
aarch64_feature_flags extensions = p_to_a->flags;
743785
aarch64_parse_extension (extension_str.c_str (), &extensions, NULL);
744786

745-
std::string outstr = a_to_an->name
746-
+ aarch64_get_extension_string_for_isa_flags (extensions,
747-
a_to_an->flags);
787+
std::string outstr = aarch64_get_arch_string_for_assembler (a_to_an->arch,
788+
extensions);
748789

749790
/* We are going to memory leak here, nobody elsewhere
750791
in the callchain is going to clean up after us. The alternative is

gcc/config/aarch64/aarch64-elf.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@
136136
#define ASM_SPEC "\
137137
%{mbig-endian:-EB} \
138138
%{mlittle-endian:-EL} \
139-
%{march=*:-march=%*} \
140139
%(asm_cpu_spec)" \
141140
ASM_MABI_SPEC
142141
#endif

gcc/config/aarch64/aarch64-protos.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1213,6 +1213,8 @@ bool aarch64_validate_mtune (const char *, aarch64_cpu *);
12131213
const char *aarch64_rewrite_selected_cpu (const char *name);
12141214
std::string aarch64_get_extension_string_for_isa_flags (aarch64_feature_flags,
12151215
aarch64_feature_flags);
1216+
std::string aarch64_get_arch_string_for_assembler (aarch64_arch,
1217+
aarch64_feature_flags);
12161218

12171219
rtl_opt_pass *make_pass_aarch64_early_ra (gcc::context *);
12181220
rtl_opt_pass *make_pass_fma_steering (gcc::context *);

gcc/config/aarch64/aarch64.cc

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24850,16 +24850,12 @@ aarch64_declare_function_name (FILE *stream, const char* name,
2485024850
targ_options = TREE_TARGET_OPTION (target_option_current_node);
2485124851
gcc_assert (targ_options);
2485224852

24853-
const struct processor *this_arch
24854-
= aarch64_get_arch (targ_options->x_selected_arch);
24855-
2485624853
auto isa_flags = aarch64_get_asm_isa_flags (targ_options);
24857-
std::string extension
24858-
= aarch64_get_extension_string_for_isa_flags (isa_flags,
24859-
this_arch->flags);
24854+
aarch64_arch arch = targ_options->x_selected_arch;
24855+
std::string to_print
24856+
= aarch64_get_arch_string_for_assembler (arch, isa_flags);
2486024857
/* Only update the assembler .arch string if it is distinct from the last
2486124858
such string we printed. */
24862-
std::string to_print = this_arch->name + extension;
2486324859
if (to_print != aarch64_last_printed_arch_string)
2486424860
{
2486524861
asm_fprintf (asm_out_file, "\t.arch %s\n", to_print.c_str ());
@@ -24981,19 +24977,16 @@ aarch64_start_file (void)
2498124977
struct cl_target_option *default_options
2498224978
= TREE_TARGET_OPTION (target_option_default_node);
2498324979

24984-
const struct processor *default_arch
24985-
= aarch64_get_arch (default_options->x_selected_arch);
24980+
aarch64_arch default_arch = default_options->x_selected_arch;
2498624981
auto default_isa_flags = aarch64_get_asm_isa_flags (default_options);
24987-
std::string extension
24988-
= aarch64_get_extension_string_for_isa_flags (default_isa_flags,
24989-
default_arch->flags);
24990-
24991-
aarch64_last_printed_arch_string = default_arch->name + extension;
24992-
aarch64_last_printed_tune_string = "";
24993-
asm_fprintf (asm_out_file, "\t.arch %s\n",
24994-
aarch64_last_printed_arch_string.c_str ());
24995-
24996-
default_file_start ();
24982+
std::string arch_string
24983+
= aarch64_get_arch_string_for_assembler (default_arch, default_isa_flags);
24984+
aarch64_last_printed_arch_string = arch_string;
24985+
aarch64_last_printed_tune_string = "";
24986+
asm_fprintf (asm_out_file, "\t.arch %s\n",
24987+
arch_string.c_str ());
24988+
24989+
default_file_start ();
2499724990
}
2499824991

2499924992
/* Emit load exclusive. */

gcc/config/aarch64/aarch64.h

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1474,7 +1474,7 @@ extern const char *host_detect_local_cpu (int argc, const char **argv);
14741474
#define HAVE_LOCAL_CPU_DETECT
14751475
# define EXTRA_SPEC_FUNCTIONS \
14761476
{ "local_cpu_detect", host_detect_local_cpu }, \
1477-
MCPU_TO_MARCH_SPEC_FUNCTIONS
1477+
AARCH64_BASE_SPEC_FUNCTIONS
14781478

14791479
/* Rewrite -m{arch,cpu,tune}=native based on the host system information.
14801480
When rewriting -march=native convert it into an -mcpu option if no other
@@ -1491,7 +1491,7 @@ extern const char *host_detect_local_cpu (int argc, const char **argv);
14911491
{ "tune", "%{!mcpu=*:%{!mtune=*:%{!march=native:-mtune=%(VALUE)}}}" },
14921492
#else
14931493
# define MCPU_MTUNE_NATIVE_SPECS ""
1494-
# define EXTRA_SPEC_FUNCTIONS MCPU_TO_MARCH_SPEC_FUNCTIONS
1494+
# define EXTRA_SPEC_FUNCTIONS AARCH64_BASE_SPEC_FUNCTIONS
14951495
# define CONFIG_TUNE_SPEC \
14961496
{"tune", "%{!mcpu=*:%{!mtune=*:-mtune=%(VALUE)}}"},
14971497
#endif
@@ -1506,18 +1506,21 @@ extern const char *host_detect_local_cpu (int argc, const char **argv);
15061506
{"cpu", "%{!march=*:%{!mcpu=*:-mcpu=%(VALUE)}}" }, \
15071507
CONFIG_TUNE_SPEC
15081508

1509-
#define MCPU_TO_MARCH_SPEC \
1510-
"%{!march=*:%{mcpu=*:-march=%:rewrite_mcpu(%{mcpu=*:%*})}}"
1509+
#define MARCH_REWRITE_SPEC \
1510+
"%{march=*:-march=%:rewrite_march(%{march=*:%*});" \
1511+
"mcpu=*:-march=%:rewrite_mcpu(%{mcpu=*:%*})}"
15111512

1513+
extern const char *aarch64_rewrite_march (int argc, const char **argv);
15121514
extern const char *aarch64_rewrite_mcpu (int argc, const char **argv);
15131515
extern const char *is_host_cpu_not_armv8_base (int argc, const char **argv);
1514-
#define MCPU_TO_MARCH_SPEC_FUNCTIONS \
1516+
#define AARCH64_BASE_SPEC_FUNCTIONS \
1517+
{ "rewrite_march", aarch64_rewrite_march }, \
15151518
{ "rewrite_mcpu", aarch64_rewrite_mcpu }, \
15161519
{ "is_local_not_armv8_base", is_host_cpu_not_armv8_base },
15171520

15181521

15191522
#define ASM_CPU_SPEC \
1520-
MCPU_TO_MARCH_SPEC
1523+
MARCH_REWRITE_SPEC
15211524

15221525
#define EXTRA_SPECS \
15231526
{ "asm_cpu_spec", ASM_CPU_SPEC }

0 commit comments

Comments
 (0)