This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [MIPS][LS2][5/5] Support for native MIPS GCC
- From: Maxim Kuvyrkov <maxim at codesourcery dot com>
- To: Maxim Kuvyrkov <maxim at codesourcery dot com>, gcc-patches <gcc-patches at gcc dot gnu dot org>, Zhang Le <r0bertz at gentoo dot org>, Eric Fisher <joefoxreal at gmail dot com>, rdsandiford at googlemail dot com
- Date: Mon, 16 Jun 2008 22:49:38 +0400
- Subject: Re: [MIPS][LS2][5/5] Support for native MIPS GCC
- References: <4835A9B4.9000709@codesourcery.com> <4835B68C.3020106@codesourcery.com> <873ao662hf.fsf@firetop.home>
Richard Sandiford wrote:
Maxim Kuvyrkov <maxim@codesourcery.com> writes:
This patch adds support for -march=native and -mtune=native options.
File driver-st.c contains a routine that checks "cpu model" line in
/proc/cpuinfo and appends a proper option to compiler command line.
This patch also specifies layout for Loongson multilibs.
OK, the obvious question here is: should the -march=native support
be specific to mips*-st*-linux* configurations, or should it apply
to all mips*-linux* configurations? I can imagine you discussed
this internally; if you did, why settle on the former?
The rationale was to avoid testing on all the different MIPSes out there.
My gut feeling was that -march=native ought to be supported for all
mips*-linux* configurations, and that mips*-st*-linux* ought simply to
specify a particular selection of multilibs (and associated multilib
layout). Thus driver-st.c would be called something more generic and
would be included by config/mips/linux.h. We could then add other
names to the list as the need arises.
Fixed thusly.
I think it would be worth adding a comment saying that, if we can't
detect a known processor, we simply discard the -march or -mtune option.
This is in contrast to x86, where we force a lowest common demoninator.
(For the record, I agree the behaviour you've got makes sense.)
You need to document the new option.
The implementation itself looks fine, thanks.
With help of Daniel Jacobowitz I updated the patch to be less
loongson-specific and provide -march/mtune=native for all processors (at
the moment, however, only Loongson 2E/2F CPUs can be detected). Does
the attached patch look ok to you?
Thanks,
Maxim
2008-06-16 Daniel Jacobowitz <dan@codesourcery.com>
Kazu Hirata <kazu@codesourcery.com>
Maxim Kuvyrkov <maxim@codesourcery.com
* config.gcc (mips64el-st-linux-gnu): Use mips/st.h and mips/t-st.
* config.host: Use driver-native.o and mips/x-native for mips*-linux*.
* config/mips/linux.h (host_detect_local_cpu): Declare, add to
EXTRA_SPEC_FUNCTIONS.
(MARCH_MTUNE_NATIVE_SPECS): New macro.
(DRIVER_SELF_SPECS): Adjust.
* config/mips/linux64.h (DRIVER_SELF_SPECS): Update.
* config/mips/st.h, config/mips/t-st: New.
* config/mips/driver-native.c, config/mips/x-native: New.
--- gcc/config.gcc (/local/gcc-4) (revision 613)
+++ gcc/config.gcc (/local/gcc-5) (revision 613)
@@ -1523,6 +1523,12 @@ mips64*-*-linux*)
tm_file="dbxelf.h elfos.h svr4.h linux.h ${tm_file} mips/linux.h mips/linux64.h"
tmake_file="${tmake_file} mips/t-linux64"
tm_defines="${tm_defines} MIPS_ABI_DEFAULT=ABI_N32"
+ case ${target} in
+ mips64el-st-linux-gnu)
+ tm_file="${tm_file} mips/st.h"
+ tmake_file="${tmake_file} mips/t-st"
+ ;;
+ esac
gnu_ld=yes
gas=yes
test x$with_llsc != x || with_llsc=yes
--- gcc/config.host (/local/gcc-4) (revision 613)
+++ gcc/config.host (/local/gcc-5) (revision 613)
@@ -104,6 +104,14 @@ case ${host} in
;;
esac
;;
+ mips*-*-linux*)
+ case ${target} in
+ mips*-*-linux*)
+ host_extra_gcc_objs="driver-native.o"
+ host_xmake_file="${host_xmake_file} mips/x-native"
+ ;;
+ esac
+ ;;
esac
case ${host} in
--- gcc/config/mips/linux.h (/local/gcc-4) (revision 613)
+++ gcc/config/mips/linux.h (/local/gcc-5) (revision 613)
@@ -149,3 +149,23 @@ along with GCC; see the file COPYING3.
#else
#define NO_SHARED_SPECS
#endif
+
+/* -march=native handling only makes sense with compiler running on
+ a MIPS chip. */
+#if defined(__mips__)
+extern const char *host_detect_local_cpu (int argc, const char **argv);
+# define EXTRA_SPEC_FUNCTIONS \
+ { "local_cpu_detect", host_detect_local_cpu },
+
+#define MARCH_MTUNE_NATIVE_SPECS \
+ " %{march=native:%<march=native %:local_cpu_detect(arch)" \
+ " %{!mtune=*:%<mtune=native %:local_cpu_detect(tune)}}" \
+ " %{mtune=native:%<mtune=native %:local_cpu_detect(tune)}"
+
+#undef DRIVER_SELF_SPECS
+#define DRIVER_SELF_SPECS \
+ NO_SHARED_SPECS \
+ MARCH_MTUNE_NATIVE_SPECS
+#else
+#define MARCH_MTUNE_NATIVE_SPECS
+#endif
--- gcc/config/mips/driver-native.c (/local/gcc-4) (revision 613)
+++ gcc/config/mips/driver-native.c (/local/gcc-5) (revision 613)
@@ -0,0 +1,73 @@
+/* Subroutines for the gcc driver.
+ Copyright (C) 2008 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"
+
+/* 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=loongson2f" on a Loongson 2F 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 *
+host_detect_local_cpu (int argc, const char **argv)
+{
+ const char *cpu = NULL;
+ char buf[128];
+ 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, "cpu model", sizeof ("cpu model") - 1) == 0)
+ {
+ if (strstr (buf, "Godson2 V0.2") != NULL
+ || strstr (buf, "Loongson-2 V0.2") != NULL)
+ cpu = "loongson2e";
+ else if (strstr (buf, "Godson2 V0.3") != NULL
+ || strstr (buf, "Loongson-2 V0.3") != NULL)
+ cpu = "loongson2f";
+ break;
+ }
+
+ fclose (f);
+
+ if (cpu == NULL)
+ return NULL;
+
+ return concat ("-m", argv[0], "=", cpu, NULL);
+}
--- gcc/config/mips/t-st (/local/gcc-4) (revision 613)
+++ gcc/config/mips/t-st (/local/gcc-5) (revision 613)
@@ -0,0 +1,14 @@
+MULTILIB_OPTIONS = march=loongson2e/march=loongson2f mabi=n32/mabi=32/mabi=64
+MULTILIB_DIRNAMES = 2e 2f lib32 lib lib64
+
+MULTILIB_OSDIRNAMES = march.loongson2e/mabi.n32=../lib32/2e
+MULTILIB_OSDIRNAMES += march.loongson2e/mabi.32=../lib/2e
+MULTILIB_OSDIRNAMES += march.loongson2e/mabi.64=../lib64/2e
+MULTILIB_OSDIRNAMES += march.loongson2f/mabi.n32=../lib32/2f
+MULTILIB_OSDIRNAMES += march.loongson2f/mabi.32=../lib/2f
+MULTILIB_OSDIRNAMES += march.loongson2f/mabi.64=../lib64/2f
+MULTILIB_OSDIRNAMES += mabi.n32=../lib32
+MULTILIB_OSDIRNAMES += mabi.32=../lib
+MULTILIB_OSDIRNAMES += mabi.64=../lib64
+
+EXTRA_MULTILIB_PARTS=crtbegin.o crtend.o crtbeginS.o crtendS.o crtbeginT.o
--- gcc/config/mips/x-native (/local/gcc-4) (revision 613)
+++ gcc/config/mips/x-native (/local/gcc-5) (revision 613)
@@ -0,0 +1,3 @@
+driver-native.o : $(srcdir)/config/mips/driver-native.c \
+ $(CONFIG_H) $(SYSTEM_H)
+ $(CC) -c $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) $<
--- gcc/config/mips/linux64.h (/local/gcc-4) (revision 613)
+++ gcc/config/mips/linux64.h (/local/gcc-5) (revision 613)
@@ -23,6 +23,7 @@ along with GCC; see the file COPYING3.
#undef DRIVER_SELF_SPECS
#define DRIVER_SELF_SPECS \
NO_SHARED_SPECS \
+MARCH_MTUNE_NATIVE_SPECS \
" %{!EB:%{!EL:%(endian_spec)}}" \
" %{!mabi=*: -mabi=n32}"
--- gcc/config/mips/st.h (/local/gcc-4) (revision 613)
+++ gcc/config/mips/st.h (/local/gcc-5) (revision 613)
@@ -0,0 +1,31 @@
+/* ST 2e / 2f GNU/Linux Configuration.
+ Copyright (C) 2008
+ 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/>. */
+
+/* The various C libraries each have their own subdirectory. */
+#undef SYSROOT_SUFFIX_SPEC
+#define SYSROOT_SUFFIX_SPEC \
+ "%{march=loongson2e:/2e ; \
+ march=loongson2f:/2f}"
+
+#undef STARTFILE_PREFIX_SPEC
+#define STARTFILE_PREFIX_SPEC \
+ "%{mabi=32: /usr/local/lib/ /lib/ /usr/lib/} \
+ %{mabi=n32: /usr/local/lib32/ /lib32/ /usr/lib32/} \
+ %{mabi=64: /usr/local/lib64/ /lib64/ /usr/lib64/}"
Property changes on:
___________________________________________________________________
Name: svk:merge
7dca8dba-45c1-47dc-8958-1a7301c5ed47:/local-gcc/md-constraint:113709
cd855902-26a6-11dd-a899-33fab5efdf21:/local/gcc-1:597
cd855902-26a6-11dd-a899-33fab5efdf21:/local/gcc-2:598
-cd855902-26a6-11dd-a899-33fab5efdf21:/local/gcc-3:604
+cd855902-26a6-11dd-a899-33fab5efdf21:/local/gcc-3:599
+cd855902-26a6-11dd-a899-33fab5efdf21:/local/gcc-4:600
cd855902-26a6-11dd-a899-33fab5efdf21:/local/gcc-trunk:596
f367781f-d768-471e-ba66-e306e17dff77:/local/gen-rework-20060122:110130