[2/2] LoongArch: drop loongarch-driver

Message ID 20221209024349.845948-3-uwu@icenowy.me
State New
Headers
Series [1/2] LoongArch: respect the with values in config.gcc |

Commit Message

Icenowy Zheng Dec. 9, 2022, 2:43 a.m. UTC
  Currently the loongarch-driver code tries to parse the values of some -m
flags to numeric representation, and then output the strings
corresponding to the numeric representations. This is mostly an no-op,
and it leads to duplication of these flags' parse code, which makes
building libgccjit fail by having multiple copies of this code to link.
However, this driver code is previously used to generate default values
for these -m flags, which is now obsoleted by respecting the values of
--with-* build-time configure flags (or their default values determined
in config.gcc).

Some other architectures include driver code to handle
-m{arch,tune}=native by converting it to the current CPU type. However
as the LoongArch compiler itself can handle native value, such a driver
is not necessary on LoongArch.

Drop loongarch-driver now as it's mostly useless. The specs snippets
that handles -mabi values are moved to loongarch.h as they're still
useful and does not depend on the driver.

gcc/ChangeLog:

	* config/loongarch/loongarch.h (ABI_GRLEN_SPEC):
	Moved from loongarch-driver.h.
	* config/loongarch/loongarch.h (ABI_SPEC): Ditto.
	* config/loongarch/loongarch-driver.h: Removed.
	* config/loongarch/loongarch-driver.cc: Removed.

Signed-off-by: Icenowy Zheng <uwu@icenowy.me>
---
 gcc/config.gcc                           |   1 -
 gcc/config/loongarch/loongarch-driver.cc | 187 -----------------------
 gcc/config/loongarch/loongarch-driver.h  |  68 ---------
 gcc/config/loongarch/loongarch.h         |  10 +-
 4 files changed, 8 insertions(+), 258 deletions(-)
 delete mode 100644 gcc/config/loongarch/loongarch-driver.cc
 delete mode 100644 gcc/config/loongarch/loongarch-driver.h
  

Patch

diff --git a/gcc/config.gcc b/gcc/config.gcc
index b5eda046033..dc1b1cdaa9d 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -459,7 +459,6 @@  loongarch*-*-*)
 	cpu_type=loongarch
 	extra_headers="larchintrin.h"
 	extra_objs="loongarch-c.o loongarch-builtins.o loongarch-cpu.o loongarch-opts.o loongarch-def.o"
-	extra_gcc_objs="loongarch-driver.o loongarch-cpu.o loongarch-opts.o loongarch-def.o"
 	extra_options="${extra_options} g.opt fused-madd.opt"
 	;;
 nds32*)
diff --git a/gcc/config/loongarch/loongarch-driver.cc b/gcc/config/loongarch/loongarch-driver.cc
deleted file mode 100644
index 0adcc923b7d..00000000000
--- a/gcc/config/loongarch/loongarch-driver.cc
+++ /dev/null
@@ -1,187 +0,0 @@ 
-/* Subroutines for the gcc driver.
-   Copyright (C) 2021-2022 Free Software Foundation, Inc.
-   Contributed by Loongson Ltd.
-
-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/>.  */
-
-#define IN_TARGET_CODE 1
-
-#include "config.h"
-#include "system.h"
-#include "coretypes.h"
-#include "tm.h"
-#include "obstack.h"
-#include "diagnostic-core.h"
-
-#include "loongarch-opts.h"
-#include "loongarch-driver.h"
-
-static int
-  opt_arch_driver = M_OPTION_NOT_SEEN,
-  opt_tune_driver = M_OPTION_NOT_SEEN,
-  opt_fpu_driver = M_OPTION_NOT_SEEN,
-  opt_abi_base_driver = M_OPTION_NOT_SEEN,
-  opt_abi_ext_driver = M_OPTION_NOT_SEEN,
-  opt_cmodel_driver = M_OPTION_NOT_SEEN;
-
-int opt_switches = 0;
-
-/* This flag is set to 1 if we believe that the user might be avoiding
-   linking (implicitly) against something from the startfile search paths.  */
-static int no_link = 0;
-
-#define LARCH_DRIVER_SET_M_FLAG(OPTS_ARRAY, N_OPTS, FLAG, STR)	\
-  for (int i = 0; i < (N_OPTS); i++)				\
-  {								\
-    if ((OPTS_ARRAY)[i] != 0)					\
-      if (strcmp ((STR), (OPTS_ARRAY)[i]) == 0)			\
-	(FLAG) = i;						\
-  }
-
-/* Use the public obstack from the gcc driver (defined in gcc.c).
-   This is for allocating space for the returned string.  */
-extern struct obstack opts_obstack;
-
-#define APPEND_LTR(S)				      \
-  obstack_grow (&opts_obstack, (const void*) (S),     \
-		sizeof ((S)) / sizeof (char) -1)
-
-#define APPEND_VAL(S) \
-  obstack_grow (&opts_obstack, (const void*) (S), strlen ((S)))
-
-
-const char*
-driver_set_m_flag (int argc, const char **argv)
-{
-  int parm_off = 0;
-
-  if (argc != 1)
-    return "%eset_m_flag requires exactly 1 argument.";
-
-#undef PARM
-#define PARM (argv[0] + parm_off)
-
-/* Note: sizeof (OPTSTR_##NAME) equals the length of "<option>=".  */
-#undef MATCH_OPT
-#define MATCH_OPT(NAME) \
-  (strncmp (argv[0], OPTSTR_##NAME "=", \
-	    (parm_off = sizeof (OPTSTR_##NAME))) == 0)
-
-  if (strcmp (argv[0], "no_link") == 0)
-    {
-      no_link = 1;
-    }
-  else if (MATCH_OPT (ABI_BASE))
-    {
-      LARCH_DRIVER_SET_M_FLAG (
-	loongarch_abi_base_strings, N_ABI_BASE_TYPES,
-	opt_abi_base_driver, PARM)
-    }
-  else if (MATCH_OPT (ISA_EXT_FPU))
-    {
-      LARCH_DRIVER_SET_M_FLAG (loongarch_isa_ext_strings, N_ISA_EXT_FPU_TYPES,
-			       opt_fpu_driver, PARM)
-    }
-  else if (MATCH_OPT (ARCH))
-    {
-      LARCH_DRIVER_SET_M_FLAG (loongarch_cpu_strings, N_ARCH_TYPES,
-			       opt_arch_driver, PARM)
-    }
-  else if (MATCH_OPT (TUNE))
-    {
-      LARCH_DRIVER_SET_M_FLAG (loongarch_cpu_strings, N_TUNE_TYPES,
-			       opt_tune_driver, PARM)
-    }
-  else if (MATCH_OPT (CMODEL))
-    {
-      LARCH_DRIVER_SET_M_FLAG (loongarch_cmodel_strings, N_CMODEL_TYPES,
-			       opt_cmodel_driver, PARM)
-    }
-  else /* switches */
-    {
-      int switch_idx = M_OPTION_NOT_SEEN;
-
-      LARCH_DRIVER_SET_M_FLAG (loongarch_switch_strings, N_SWITCH_TYPES,
-			       switch_idx, argv[0])
-
-      if (switch_idx != M_OPTION_NOT_SEEN)
-	opt_switches |= loongarch_switch_mask[switch_idx];
-    }
-  return "";
-}
-
-const char*
-driver_get_normalized_m_opts (int argc, const char **argv)
-{
-  if (argc != 0)
-    {
-      (void) argv;  /* To make compiler shut up about unused argument.  */
-      return " %eget_normalized_m_opts requires no argument.\n";
-    }
-
-  loongarch_config_target (& la_target,
-			   opt_switches,
-			   opt_arch_driver,
-			   opt_tune_driver,
-			   opt_fpu_driver,
-			   opt_abi_base_driver,
-			   opt_abi_ext_driver,
-			   opt_cmodel_driver,
-			   !no_link /* follow_multilib_list */);
-
-  /* Output normalized option strings.  */
-  obstack_blank (&opts_obstack, 0);
-
-#undef APPEND_LTR
-#define APPEND_LTR(S) \
-  obstack_grow (&opts_obstack, (const void*) (S), \
-		sizeof ((S)) / sizeof (char) -1)
-
-#undef APPEND_VAL
-#define APPEND_VAL(S) \
-  obstack_grow (&opts_obstack, (const void*) (S), strlen ((S)))
-
-#undef APPEND_OPT
-#define APPEND_OPT(NAME) \
-   APPEND_LTR (" %<m" OPTSTR_##NAME "=* " \
-	       " -m" OPTSTR_##NAME "=")
-
-  for (int i = 0; i < N_SWITCH_TYPES; i++)
-    {
-      APPEND_LTR (" %<m");
-      APPEND_VAL (loongarch_switch_strings[i]);
-    }
-
-  APPEND_OPT (ABI_BASE);
-  APPEND_VAL (loongarch_abi_base_strings[la_target.abi.base]);
-
-  APPEND_OPT (ARCH);
-  APPEND_VAL (loongarch_cpu_strings[la_target.cpu_arch]);
-
-  APPEND_OPT (ISA_EXT_FPU);
-  APPEND_VAL (loongarch_isa_ext_strings[la_target.isa.fpu]);
-
-  APPEND_OPT (CMODEL);
-  APPEND_VAL (loongarch_cmodel_strings[la_target.cmodel]);
-
-  APPEND_OPT (TUNE);
-  APPEND_VAL (loongarch_cpu_strings[la_target.cpu_tune]);
-
-  obstack_1grow (&opts_obstack, '\0');
-
-  return XOBFINISH (&opts_obstack, const char *);
-}
diff --git a/gcc/config/loongarch/loongarch-driver.h b/gcc/config/loongarch/loongarch-driver.h
deleted file mode 100644
index 2e4a7a9c870..00000000000
--- a/gcc/config/loongarch/loongarch-driver.h
+++ /dev/null
@@ -1,68 +0,0 @@ 
-/* Subroutine headers for the gcc driver.
-   Copyright (C) 2021-2022 Free Software Foundation, Inc.
-   Contributed by Loongson Ltd.
-
-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/>.  */
-
-#ifndef LOONGARCH_DRIVER_H
-#define LOONGARCH_DRIVER_H
-
-#include "loongarch-str.h"
-
-extern const char*
-driver_set_m_flag (int argc, const char **argv);
-
-extern const char*
-driver_get_normalized_m_opts (int argc, const char **argv);
-
-#define EXTRA_SPEC_FUNCTIONS \
-  { "set_m_flag", driver_set_m_flag  }, \
-  { "get_normalized_m_opts", driver_get_normalized_m_opts  },
-
-/* Pre-process ABI-related options.  */
-#define LA_SET_PARM_SPEC(NAME) \
-  " %{m" OPTSTR_##NAME  "=*: %:set_m_flag(" OPTSTR_##NAME "=%*)}" \
-
-#define LA_SET_FLAG_SPEC(NAME) \
-  " %{m" OPTSTR_##NAME  ": %:set_m_flag(" OPTSTR_##NAME ")}" \
-
-#define DRIVER_HANDLE_MACHINE_OPTIONS			      \
-  " %{c|S|E|nostdlib: %:set_m_flag(no_link)}"		      \
-  " %{nostartfiles: %{nodefaultlibs: %:set_m_flag(no_link)}}" \
-  LA_SET_PARM_SPEC (ABI_BASE)				      \
-  LA_SET_PARM_SPEC (ARCH)				      \
-  LA_SET_PARM_SPEC (TUNE)				      \
-  LA_SET_PARM_SPEC (ISA_EXT_FPU)			      \
-  LA_SET_PARM_SPEC (CMODEL)				      \
-  LA_SET_FLAG_SPEC (SOFT_FLOAT)				      \
-  LA_SET_FLAG_SPEC (SINGLE_FLOAT)			      \
-  LA_SET_FLAG_SPEC (DOUBLE_FLOAT)			      \
-  " %:get_normalized_m_opts()"
-
-#define DRIVER_SELF_SPECS \
-  DRIVER_HANDLE_MACHINE_OPTIONS
-
-/* ABI spec strings.  */
-#define ABI_GRLEN_SPEC \
-  "%{mabi=lp64*:64}"   \
-
-#define ABI_SPEC \
-  "%{mabi=lp64d:lp64d}" \
-  "%{mabi=lp64f:lp64f}" \
-  "%{mabi=lp64s:lp64s}" \
-
-#endif /* LOONGARCH_DRIVER_H */
diff --git a/gcc/config/loongarch/loongarch.h b/gcc/config/loongarch/loongarch.h
index 5e2f4158f70..ea40c4fed72 100644
--- a/gcc/config/loongarch/loongarch.h
+++ b/gcc/config/loongarch/loongarch.h
@@ -47,8 +47,14 @@  along with GCC; see the file COPYING3.  If not see
 
 #define TARGET_LIBGCC_SDATA_SECTION ".sdata"
 
-/* Driver native functions for SPEC processing in the GCC driver.  */
-#include "loongarch-driver.h"
+/* ABI spec strings.  */
+#define ABI_GRLEN_SPEC \
+  "%{mabi=lp64*:64}"   \
+
+#define ABI_SPEC \
+  "%{mabi=lp64d:lp64d}" \
+  "%{mabi=lp64f:lp64f}" \
+  "%{mabi=lp64s:lp64s}" \
 
 /* Support for a compile-time default CPU, et cetera.  The rules are:
    --with-arch is ignored if -march is specified.