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.


diff --git a/gcc/common/config/aarch64/aarch64-common.cc 
b/gcc/common/config/aarch64/aarch64-common.cc
index 
abb9565e13e109099e88c8adb86fbaeab38588c7..427a1938902c0ea3412e4ab31170d164f0fab514
 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.  */
 
diff --git a/gcc/config/aarch64/aarch64-protos.h 
b/gcc/config/aarch64/aarch64-protos.h
index 
b27da1e25720da06712da0eff1d527e23408a59f..4235f4a0ca51af49c2852a420f1056727b24f345
 100644
--- a/gcc/config/aarch64/aarch64-protos.h
+++ b/gcc/config/aarch64/aarch64-protos.h
@@ -1210,7 +1210,6 @@ bool aarch64_validate_march (const char *, aarch64_arch *,
 bool aarch64_validate_mcpu (const char *, aarch64_cpu *,
                            aarch64_feature_flags *);
 bool aarch64_validate_mtune (const char *, aarch64_cpu *);
-const char *aarch64_rewrite_selected_cpu (const char *name);
 std::string aarch64_get_extension_string_for_isa_flags (aarch64_feature_flags,
                                                        aarch64_feature_flags);
 std::string aarch64_get_arch_string_for_assembler (aarch64_arch,

Reply via email to