S390: Support -mtune=native and -march=native.
authorDominik Vogt <vogt@linux.vnet.ibm.com>
Mon, 1 Jun 2015 11:38:44 +0000 (11:38 +0000)
committerAndreas Krebbel <krebbel@gcc.gnu.org>
Mon, 1 Jun 2015 11:38:44 +0000 (11:38 +0000)
gcc/ChangeLog

2015-06-01  Dominik Vogt  <vogt@linux.vnet.ibm.com>

    * config/s390/driver-native.c: New file.
    * config/s390/x-native: New file.
    * config.host: Add new files for s390.
    * config/s390/s390.h (DRIVER_SELF_SPECS): Add support for -mtune=native
    and -march=native
    * config.gcc: Likewise.
    * config/s390/s390.opt (march): Likewise; add PROCESSOR_NATIVE
    * config/s390/s390-opts.h (enum processor_type): Ditto.
    * config/s390/s390.c (s390_option_override): Catch unhandled
    PROCESSOR_NATIVE

From-SVN: r223934

gcc/ChangeLog
gcc/config.gcc
gcc/config.host
gcc/config/s390/driver-native.c [new file with mode: 0644]
gcc/config/s390/s390-opts.h
gcc/config/s390/s390.c
gcc/config/s390/s390.h
gcc/config/s390/s390.opt
gcc/config/s390/x-native [new file with mode: 0644]

index d61b465bdb2cf4ff5c35055ba60db76971de6dbc..72ef1e45d5c24e00b1a03d76fe2e8180f5b8ffa9 100644 (file)
@@ -1,3 +1,16 @@
+2015-06-01  Dominik Vogt  <vogt@linux.vnet.ibm.com>
+
+       * config/s390/driver-native.c: New file.
+       * config/s390/x-native: New file.
+       * config.host: Add new files for s390.
+       * config/s390/s390.h (DRIVER_SELF_SPECS): Add support for -mtune=native
+       and -march=native
+       * config.gcc: Likewise.
+       * config/s390/s390.opt (march): Likewise; add PROCESSOR_NATIVE
+       * config/s390/s390-opts.h (enum processor_type): Ditto.
+       * config/s390/s390.c (s390_option_override): Catch unhandled
+       PROCESSOR_NATIVE
+
 2015-06-01  Ilya Enkovich  <ilya.enkovich@intel.com>
 
        PR target/65527
index 1fcc290a95f619f54bdffb499a8556d527704f03..e23a34c2528911d9be6a4ee5cedfad08f38e28d3 100644 (file)
@@ -4099,7 +4099,7 @@ case "${target}" in
                for which in arch tune; do
                        eval "val=\$with_$which"
                        case ${val} in
-                       "" | g5 | g6 | z900 | z990 | z9-109 | z9-ec | z10 | z196 | zEC12 | z13)
+                       "" | native | g5 | g6 | z900 | z990 | z9-109 | z9-ec | z10 | z196 | zEC12 | z13)
                                # OK
                                ;;
                        *)
index a8896d1c382ea65e3101292b27b60e049094bec4..4e456a1b5390ad451d298e0c758925b133725490 100644 (file)
@@ -172,6 +172,10 @@ case ${host} in
        ;;
     esac
     ;;
+  s390-*-* | s390x-*-*)
+    host_extra_gcc_objs="driver-native.o"
+    host_xmake_file="${host_xmake_file} s390/x-native"
+    ;;
   sparc*-*-solaris2*)
     case ${target} in
       sparc*-*-solaris2*)
diff --git a/gcc/config/s390/driver-native.c b/gcc/config/s390/driver-native.c
new file mode 100644 (file)
index 0000000..88c76bd
--- /dev/null
@@ -0,0 +1,91 @@
+/* Subroutines for the gcc driver.
+   Copyright (C) 2015 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 3, or (at your option)
+any later version.
+
+GCC is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GCC; see the file COPYING3.  If not see
+<http://www.gnu.org/licenses/>.  */
+
+#include "config.h"
+#include "system.h"
+#include "coretypes.h"
+#include "tm.h"
+
+/* This will be called by the spec parser in gcc.c when it sees
+   a %:local_cpu_detect(args) construct.  Currently it will be called
+   with either "arch" or "tune" as argument depending on if -march=native
+   or -mtune=native is to be substituted.
+
+   It returns a string containing new command line parameters to be
+   put at the place of the above two options, depending on what CPU
+   this is executed.  E.g. "-march=zEC12" on a zEC12 for -march=native.
+   If the routine can't detect a known processor, the -march or -mtune
+   option is discarded.
+
+   ARGC and ARGV are set depending on the actual arguments given
+   in the spec.  */
+const char *
+s390_host_detect_local_cpu (int argc, const char **argv)
+{
+  const char *cpu = NULL;
+  char buf[256];
+  FILE *f;
+  bool arch;
+
+  if (argc < 1)
+    return NULL;
+
+  arch = strcmp (argv[0], "arch") == 0;
+  if (!arch && strcmp (argv[0], "tune"))
+    return NULL;
+
+  f = fopen ("/proc/cpuinfo", "r");
+  if (f == NULL)
+    return NULL;
+
+  while (fgets (buf, sizeof (buf), f) != NULL)
+    if (strncmp (buf, "processor", sizeof ("processor") - 1) == 0)
+      {
+       if (strstr (buf, "machine = 9672") != NULL)
+         cpu = "g5";
+       else if (strstr (buf, "machine = 2064") != NULL
+                || strstr (buf, "machine = 2066") != NULL)
+         cpu = "z900";
+       else if (strstr (buf, "machine = 2084") != NULL
+                || strstr (buf, "machine = 2086") != NULL)
+         cpu = "z990";
+       else if (strstr (buf, "machine = 2094") != NULL
+                || strstr (buf, "machine = 2096") != NULL)
+         cpu = "z9-109";
+       else if (strstr (buf, "machine = 2097") != NULL
+                || strstr (buf, "machine = 2098") != NULL)
+         cpu = "z10";
+       else if (strstr (buf, "machine = 2817") != NULL
+                || strstr (buf, "machine = 2818") != NULL)
+         cpu = "z196";
+       else if (strstr (buf, "machine = 2827") != NULL
+                || strstr (buf, "machine = 2828") != NULL)
+         cpu = "zEC12";
+       else if (strstr (buf, "machine = 2964") != NULL)
+         cpu = "z13";
+       break;
+      }
+
+  fclose (f);
+
+  if (cpu == NULL)
+    return NULL;
+
+  return concat ("-m", argv[0], "=", cpu, NULL);
+}
index 5bde33344d2cd20bc22c1ae1503f538ea274fb1c..f0ea532df2ca5a1491cf1f2a3918ca603c397a48 100644 (file)
@@ -36,6 +36,7 @@ enum processor_type
   PROCESSOR_2817_Z196,
   PROCESSOR_2827_ZEC12,
   PROCESSOR_2964_Z13,
+  PROCESSOR_NATIVE,
   PROCESSOR_max
 };
 
index 90d43b1498cccbc4de337775a5d1a2e0d44d7fea..47cb9e76eb25a4c311ef6c032e70ad1299fbd832 100644 (file)
@@ -13345,6 +13345,8 @@ s390_option_override (void)
     }
 
   /* Sanity checks.  */
+  if (s390_arch == PROCESSOR_NATIVE || s390_tune == PROCESSOR_NATIVE)
+    gcc_unreachable ();
   if (TARGET_ZARCH && !TARGET_CPU_ZARCH)
     error ("z/Architecture mode not supported on %s", s390_arch_string);
   if (TARGET_64BIT && !TARGET_ZARCH)
index a9bf9b5b1cbd0418edbc319c0af16e0e7243acba..85a0d1af65a2363e8eb2f9b7f3d9feea5cd00619 100644 (file)
@@ -126,17 +126,27 @@ enum processor_flags
   { "arch", "%{!march=*:-march=%(VALUE)}" },                   \
   { "tune", "%{!mtune=*:-mtune=%(VALUE)}" }
 
+extern const char *s390_host_detect_local_cpu (int argc, const char **argv);
+# define EXTRA_SPEC_FUNCTIONS \
+  { "local_cpu_detect", s390_host_detect_local_cpu },
+
+# define MARCH_MTUNE_NATIVE_SPECS                              \
+  " %{march=native:%<march=native %:local_cpu_detect(arch)}"   \
+  " %{mtune=native:%<mtune=native %:local_cpu_detect(tune)}"
+
 /* Defaulting rules.  */
 #ifdef DEFAULT_TARGET_64BIT
 #define DRIVER_SELF_SPECS                                      \
   "%{!m31:%{!m64:-m64}}",                                      \
   "%{!mesa:%{!mzarch:%{m31:-mesa}%{m64:-mzarch}}}",            \
-  "%{!march=*:%{mesa:-march=g5}%{mzarch:-march=z900}}"
+  "%{!march=*:%{mesa:-march=g5}%{mzarch:-march=z900}}",                \
+  MARCH_MTUNE_NATIVE_SPECS
 #else
 #define DRIVER_SELF_SPECS                                      \
   "%{!m31:%{!m64:-m31}}",                                      \
   "%{!mesa:%{!mzarch:%{m31:-mesa}%{m64:-mzarch}}}",            \
-  "%{!march=*:%{mesa:-march=g5}%{mzarch:-march=z900}}"
+  "%{!march=*:%{mesa:-march=g5}%{mzarch:-march=z900}}",                \
+  MARCH_MTUNE_NATIVE_SPECS
 #endif
 
 /* Constants needed to control the TEST DATA CLASS (TDC) instruction.  */
index b841c4dac4d287a6d2104299f7ffc3508b929809..b21dc365d334b7f5ac41ab056e2668a5778c9bb0 100644 (file)
@@ -79,6 +79,9 @@ Enum(processor_type) String(zEC12) Value(PROCESSOR_2827_ZEC12)
 EnumValue
 Enum(processor_type) String(z13) Value(PROCESSOR_2964_Z13)
 
+EnumValue
+Enum(processor_type) String(native) Value(PROCESSOR_NATIVE) DriverOnly
+
 mbackchain
 Target Report Mask(BACKCHAIN)
 Maintain backchain pointer
diff --git a/gcc/config/s390/x-native b/gcc/config/s390/x-native
new file mode 100644 (file)
index 0000000..b33c8b6
--- /dev/null
@@ -0,0 +1,3 @@
+driver-native.o : $(srcdir)/config/s390/driver-native.c \
+  $(CONFIG_H) $(SYSTEM_H)
+       $(COMPILER) -c $(ALL_COMPILERFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) $<