Patchwork [AArch64] Fix behaviour of -mcpu option to match ARM.

login
register
mail settings
Submitter James Greenhalgh
Date Jan. 16, 2014, 5:32 p.m.
Message ID <1389893527-12594-1-git-send-email-james.greenhalgh@arm.com>
Download mbox | patch
Permalink /patch/311797/
State New
Headers show

Comments

James Greenhalgh - Jan. 16, 2014, 5:32 p.m.
Hi,

While clarifying the documentation of the -mcpu, -march and -mtune
options for AArch64 and ARM I spotted that their behaviour is not
consistent.

This patch fixes that in the AArch64 port.

Now, -mcpu=$CPU is treated as a shorthand for -march=arch_of_$CPU and
 -mtune=$CPU. -march and -mtune therefore override only their respective
components of -mcpu. If the architecture picked by -march does not match
that given by -mcpu, a warning is given.

Regression tested on aarch64-none-elf and checked manually to
ensure things are working as expected.

OK?

Thanks,
James

---
gcc/

2014-01-16  James Greenhalgh  <james.greenhalgh@arm.com>

	* common/config/aarch64/aarch64-common.c
	(aarch64_handle_option): Don't handle any option order logic here.
	* config/aarch64/aarch64.c (aarch64_parse_arch): Do not override
	selected_cpu, warn on architecture version mismatch.
	(aarch64_override_options): Fix parsing order for option strings.
Richard Earnshaw - Jan. 20, 2014, 11:15 a.m.
On 16/01/14 17:32, James Greenhalgh wrote:
> 
> Hi,
> 
> While clarifying the documentation of the -mcpu, -march and -mtune
> options for AArch64 and ARM I spotted that their behaviour is not
> consistent.
> 
> This patch fixes that in the AArch64 port.
> 
> Now, -mcpu=$CPU is treated as a shorthand for -march=arch_of_$CPU and
>  -mtune=$CPU. -march and -mtune therefore override only their respective
> components of -mcpu. If the architecture picked by -march does not match
> that given by -mcpu, a warning is given.
> 
> Regression tested on aarch64-none-elf and checked manually to
> ensure things are working as expected.
> 
> OK?
> 
> Thanks,
> James
> 
> ---
> gcc/
> 
> 2014-01-16  James Greenhalgh  <james.greenhalgh@arm.com>
> 
> 	* common/config/aarch64/aarch64-common.c
> 	(aarch64_handle_option): Don't handle any option order logic here.
> 	* config/aarch64/aarch64.c (aarch64_parse_arch): Do not override
> 	selected_cpu, warn on architecture version mismatch.
> 	(aarch64_override_options): Fix parsing order for option strings.
> 
> 

OK.

R.

Patch

diff --git a/gcc/common/config/aarch64/aarch64-common.c b/gcc/common/config/aarch64/aarch64-common.c
index 135a9bc..6107007 100644
--- a/gcc/common/config/aarch64/aarch64-common.c
+++ b/gcc/common/config/aarch64/aarch64-common.c
@@ -52,10 +52,10 @@  static const struct default_options aarch_option_optimization_table[] =
 /* Implement TARGET_HANDLE_OPTION.
    This function handles the target specific options for CPU/target selection.
 
-   march wins over mcpu, so when march is defined, mcpu takes the same value,
-   otherwise march remains undefined. mtune can be used with either march or
-   mcpu. If march and mcpu are used together, the rightmost option wins.
-   mtune can be used with either march or mcpu.  */
+   -mcpu=CPU is shorthand for -march=ARCH_FOR_CPU, -mtune=CPU.
+   If either of -march or -mtune is given, they override their
+   respective component of -mcpu.  This logic is implemented
+   in config/aarch64/aarch64.c:aarch64_override_options.  */
 
 static bool
 aarch64_handle_option (struct gcc_options *opts,
@@ -70,12 +70,10 @@  aarch64_handle_option (struct gcc_options *opts,
     {
     case OPT_march_:
       opts->x_aarch64_arch_string = arg;
-      opts->x_aarch64_cpu_string = arg;
       return true;
 
     case OPT_mcpu_:
       opts->x_aarch64_cpu_string = arg;
-      opts->x_aarch64_arch_string = NULL;
       return true;
 
     case OPT_mtune_:
diff --git a/gcc/config/aarch64/aarch64.c b/gcc/config/aarch64/aarch64.c
index 89f2b9b..59e9dd1 100644
--- a/gcc/config/aarch64/aarch64.c
+++ b/gcc/config/aarch64/aarch64.c
@@ -5099,7 +5099,9 @@  aarch64_parse_arch (void)
 	{
 	  selected_arch = arch;
 	  aarch64_isa_flags = selected_arch->flags;
-	  selected_cpu = &all_cores[selected_arch->core];
+
+	  if (!selected_cpu)
+	    selected_cpu = &all_cores[selected_arch->core];
 
 	  if (ext != NULL)
 	    {
@@ -5107,6 +5109,12 @@  aarch64_parse_arch (void)
 	      aarch64_parse_extension (ext);
 	    }
 
+	  if (strcmp (selected_arch->arch, selected_cpu->arch))
+	    {
+	      warning (0, "switch -mcpu=%s conflicts with -march=%s switch",
+		       selected_cpu->name, selected_arch->name);
+	    }
+
 	  return;
 	}
     }
@@ -5195,20 +5203,21 @@  aarch64_parse_tune (void)
 static void
 aarch64_override_options (void)
 {
-  /* march wins over mcpu, so when march is defined, mcpu takes the same value,
-     otherwise march remains undefined.  mtune can be used with either march or
-     mcpu.  */
+  /* -mcpu=CPU is shorthand for -march=ARCH_FOR_CPU, -mtune=CPU.
+     If either of -march or -mtune is given, they override their
+     respective component of -mcpu.
 
-  if (aarch64_arch_string)
+     So, first parse AARCH64_CPU_STRING, then the others, be careful
+     with -march as, if -mcpu is not present on the command line, march
+     must set a sensible default CPU.  */
+  if (aarch64_cpu_string)
     {
-      aarch64_parse_arch ();
-      aarch64_cpu_string = NULL;
+      aarch64_parse_cpu ();
     }
 
-  if (aarch64_cpu_string)
+  if (aarch64_arch_string)
     {
-      aarch64_parse_cpu ();
-      selected_arch = NULL;
+      aarch64_parse_arch ();
     }
 
   if (aarch64_tune_string)