public inbox for jit@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH 1/2] LoongArch: respect the with values in config.gcc
       [not found] <20221209024349.845948-1-uwu@icenowy.me>
@ 2022-12-09  2:43 ` Icenowy Zheng
  2022-12-09  2:43 ` [PATCH 2/2] LoongArch: drop loongarch-driver Icenowy Zheng
  2022-12-09  7:51 ` [PATCH 0/2] LoongArch: respect --with-* and " Xi Ruoyao
  2 siblings, 0 replies; 3+ messages in thread
From: Icenowy Zheng @ 2022-12-09  2:43 UTC (permalink / raw)
  To: gcc-patches; +Cc: Xi Ruoyao, jit, Icenowy Zheng

In config.gcc, there's a long code snippet that handles
--with-{arch,tune,abi,fpu} and give them default values; however these
"with" values are not used at all.

Use these "with" values to initialize these variables in specs.

gcc/ChangeLog:

	* config/loongarch/loongarch.h (OPTION_DEFAULT_SPECS):
	New macro that simply injects configure --with values.

Signed-off-by: Icenowy Zheng <uwu@icenowy.me>
---
 gcc/config/loongarch/loongarch.h | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/gcc/config/loongarch/loongarch.h b/gcc/config/loongarch/loongarch.h
index a402d3ba35a..5e2f4158f70 100644
--- a/gcc/config/loongarch/loongarch.h
+++ b/gcc/config/loongarch/loongarch.h
@@ -50,6 +50,17 @@ along with GCC; see the file COPYING3.  If not see
 /* Driver native functions for SPEC processing in the GCC driver.  */
 #include "loongarch-driver.h"
 
+/* Support for a compile-time default CPU, et cetera.  The rules are:
+   --with-arch is ignored if -march is specified.
+   --with-tune is ignored if -mtune is specified.
+   --with-abi is ignored if -mabi is specified.
+   --with-fpu is ignored if -mfpu is specified. */
+#define OPTION_DEFAULT_SPECS \
+  {"arch", "%{!march=*:-march=%(VALUE)}" }, \
+  {"tune", "%{!mtune=*:-mtune=%(VALUE)}" }, \
+  {"abi", "%{!mabi=*:-mabi=%(VALUE)}" }, \
+  {"fpu", "%{!mfpu=*:-mfpu=%(VALUE)}" }, \
+
 /* This definition replaces the formerly used 'm' constraint with a
    different constraint letter in order to avoid changing semantics of
    the 'm' constraint when accepting new address formats in
-- 
2.38.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 2/2] LoongArch: drop loongarch-driver
       [not found] <20221209024349.845948-1-uwu@icenowy.me>
  2022-12-09  2:43 ` [PATCH 1/2] LoongArch: respect the with values in config.gcc Icenowy Zheng
@ 2022-12-09  2:43 ` Icenowy Zheng
  2022-12-09  7:51 ` [PATCH 0/2] LoongArch: respect --with-* and " Xi Ruoyao
  2 siblings, 0 replies; 3+ messages in thread
From: Icenowy Zheng @ 2022-12-09  2:43 UTC (permalink / raw)
  To: gcc-patches; +Cc: Xi Ruoyao, jit, Icenowy Zheng

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

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.
-- 
2.38.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH 0/2] LoongArch: respect --with-* and drop loongarch-driver
       [not found] <20221209024349.845948-1-uwu@icenowy.me>
  2022-12-09  2:43 ` [PATCH 1/2] LoongArch: respect the with values in config.gcc Icenowy Zheng
  2022-12-09  2:43 ` [PATCH 2/2] LoongArch: drop loongarch-driver Icenowy Zheng
@ 2022-12-09  7:51 ` Xi Ruoyao
  2 siblings, 0 replies; 3+ messages in thread
From: Xi Ruoyao @ 2022-12-09  7:51 UTC (permalink / raw)
  To: Icenowy Zheng, gcc-patches; +Cc: jit, Lulu Cheng

On Fri, 2022-12-09 at 10:43 +0800, Icenowy Zheng wrote:
> This patchset tries to fix the object duplication between the driver and
> the real compiler, which makes libgccjit building fail because of
> linking this two parts together.

Hmm, I think the issue is already fixed by https://gcc.gnu.org/r13-1010
but maybe I'm wrong here...

This looks like a good code clean-up anyway.  But if libgccjit builds
fine with GCC trunk I'd postpone the clean-up to GCC 14 stage 1.

> First, the build-time --with-* values are now respected by being the
> default -m* values in the driver, and then loongarch-driver, which is
> mostly doing no-op now, is dropped.
> 
> This patchset is bootstrapped on a native LoongArch device (without
> any
> --with-* flags). In addition, on a x86 device, cross compilers are
> built
> with --with-{arch,abi} and without any --with-* flags; all these
> configurations can correctly build all supported shipped libraries
> with
> GCC.
> 
> Icenowy Zheng (2):
>   LoongArch: respect the with values in config.gcc
>   LoongArch: drop loongarch-driver
> 
>  gcc/config.gcc                           |   1 -
>  gcc/config/loongarch/loongarch-driver.cc | 187 ----------------------
> -
>  gcc/config/loongarch/loongarch-driver.h  |  68 ---------
>  gcc/config/loongarch/loongarch.h         |  21 ++-
>  4 files changed, 19 insertions(+), 258 deletions(-)
>  delete mode 100644 gcc/config/loongarch/loongarch-driver.cc
>  delete mode 100644 gcc/config/loongarch/loongarch-driver.h
> 

-- 
Xi Ruoyao <xry111@xry111.site>
School of Aerospace Science and Technology, Xidian University

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-12-09  7:51 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20221209024349.845948-1-uwu@icenowy.me>
2022-12-09  2:43 ` [PATCH 1/2] LoongArch: respect the with values in config.gcc Icenowy Zheng
2022-12-09  2:43 ` [PATCH 2/2] LoongArch: drop loongarch-driver Icenowy Zheng
2022-12-09  7:51 ` [PATCH 0/2] LoongArch: respect --with-* and " Xi Ruoyao

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).