diff mbox series

[1/2] arm: Allow -mcpu and -march options to be unset

Message ID 20240912151113.4079992-2-rearnsha@arm.com
State New
Headers show
Series arm: Allow -mcpu and -march options to be unset | expand

Commit Message

Richard Earnshaw Sept. 12, 2024, 3:11 p.m. UTC
The compiler will warn if the architectural specification derived from
a -mcpu option is not the same as that specified by -march.  This is
because it was never intended that the two should be used at the same
time: -mcpu=<name> is supposed to be shorthand for -mtune=<name>
-march=arch-of(<name>).

Unfortunately, there are times when the two options passed to the
compiler may come from distinct sources: one example is makefiles
which accumulate options; another is the testsuite itself, when some
tests require a particular architecture setting to be useful - only
running the tests when the compiler/testsuite configuration exactly
matched the requirements would make regression testing especially hard
(we have too many permutations).

So this patch allows a user to cancel any earlier setting of a
particular flag and to make the compiler behave as though it was never
passed.  The intended usecase is (sources of options are shown in
parenthesis, but that's just for grouping:

 (-march=armv7-a+simd) (-march=unset -mcpu=cortex-m33)

The option processing logic will now simplify this to:

 -mcpu=cortex-m33

A useful corollary of this is that

 -march=armv7-a -march=unset

will now cause the compiler to behave as though neither the
architecture nor the CPU was ever set and to default back to the
configure-time settings.

gcc/ChangeLog:

	* config/arm/arm.h (OPTION_DEFAULT_SPECS): Allow -mcpu and -march
	to be unset.
	(ARCH_CPU_CLEANUP_SPECS): Likewise
	(DRIVER_SELF_SPECS): Add ARCH_CPU_CLEANUP_SPECS
	* doc/invoke.texi (arm: -mcpu= and -march=): Document use of 'unset'.
---
 gcc/config/arm/arm.h | 14 +++++++++++---
 gcc/doc/invoke.texi  | 12 ++++++++++++
 2 files changed, 23 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/gcc/config/arm/arm.h b/gcc/config/arm/arm.h
index 0cd5d733952..b092ba6ffe0 100644
--- a/gcc/config/arm/arm.h
+++ b/gcc/config/arm/arm.h
@@ -394,9 +394,11 @@  emission of floating point pcs attributes.  */
    TARGET_MODE_CHECK that also takes into account the selected CPU and
    architecture.  */
 #define OPTION_DEFAULT_SPECS \
-  {"arch", "%{!march=*:%{!mcpu=*:-march=%(VALUE)}}" }, \
-  {"cpu", "%{!march=*:%{!mcpu=*:-mcpu=%(VALUE)}}" }, \
-  {"tune", "%{!mcpu=*:%{!mtune=*:-mtune=%(VALUE)}}" }, \
+  {"arch", "%{!march=*|march=unset:"\
+      "%{!mcpu=*|mcpu=unset:%<march=* %<mcpu=* -march=%(VALUE)}}" }, \
+  {"tune", "%{!mcpu=*|mcpu=unset:%{!mtune=*:-mtune=%(VALUE)}}" }, \
+  {"cpu", "%{!march=*|march=unset:"\
+      "%{!mcpu=*|mcpu=unset:%<march=* %<mcpu=* -mcpu=%(VALUE)}}" }, \
   {"float", "%{!mfloat-abi=*:-mfloat-abi=%(VALUE)}" }, \
   {"fpu", "%{!mfpu=*:-mfpu=%(VALUE)}"}, \
   {"abi", "%{!mabi=*:-mabi=%(VALUE)}"}, \
@@ -2538,6 +2540,11 @@  const char *arm_be8_option (int argc, const char **argv);
 #define TARGET_MODE_SPECS						\
   " %{!marm:%{!mthumb:%:target_mode_check(%{march=*:arch %*;mcpu=*:cpu %*;:})}}"
 
+/* Cleanup any stray -march=/-mcpu= if either is followed by "unset".  */
+#define ARCH_CPU_CLEANUP_SPECS	\
+  " %{march=unset:%<march=*} "	\
+  " %{mcpu=unset:%<mcpu=*} "
+
 /* Generate a canonical string to represent the architecture selected.  */
 #define ARCH_CANONICAL_SPECS				\
   " -march=%:canon_arch(%{mcpu=*: cpu %*} "		\
@@ -2559,6 +2566,7 @@  const char *arm_be8_option (int argc, const char **argv);
    individual rules so that any option suppression (%<opt...)is
    completed before starting subsequent rules.  */
 #define DRIVER_SELF_SPECS			\
+  ARCH_CPU_CLEANUP_SPECS,			\
   MCPU_MTUNE_NATIVE_SPECS,			\
   TARGET_MODE_SPECS,				\
   MULTILIB_ARCH_CANONICAL_SPECS,		\
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index c2078a7eef3..a6cd5111d47 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -23492,6 +23492,12 @@  of the build computer.  At present, this feature is only supported on
 GNU/Linux, and not all architectures are recognized.  If the auto-detect
 is unsuccessful the option has no effect.
 
+@option{-march=unset} causes the compiler to ignore any
+@option{-march=@dots{}} options that appear earlier on the command line
+and behave as if the option was never passed.  This is useful to avoid
+warnings about conflicting CPU and architecture options when the two
+produce different architecture specifications.
+
 @opindex mtune
 @item -mtune=@var{name}
 This option specifies the name of the target ARM processor for
@@ -23654,6 +23660,12 @@  of the build computer.  At present, this feature is only supported on
 GNU/Linux, and not all architectures are recognized.  If the auto-detect
 is unsuccessful the option has no effect.
 
+@option{-mcpu=unset} causes the compiler to ignore any
+@option{-mcpu=@dots{}} options that appear earlier on the command line
+and behave as if the option was never passed.  This is useful to avoid
+warnings about conflicting CPU and architecture options when the two
+produce different architecture specifications.
+
 @opindex mfpu
 @item -mfpu=@var{name}
 This specifies what floating-point hardware (or hardware emulation) is