From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2093) id BCE8A3858C54; Fri, 2 Sep 2022 09:27:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BCE8A3858C54 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1662110828; bh=WjLBcIeacL8ZITkhomNbTsUoQH+0Y4HwS48pwIEFkKE=; h=From:To:Subject:Date:From; b=kZtm/qeUlvZibt0s6YQ+8q87k1Ufn0OcoiYh3fwE6fGU7/BuVXW35KWVnGBjgXYNd tsQ/HBqS0Uc++sjBC4UPwpDbeI3ak8gjRtWM4A//N6GRfy5wUcLHNrtviObFo/euo4 MUl+Qra6qxvJy22QKWOXpIc7y9+ndDGcdUoLl7HQ= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Kito Cheng To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-2373] Add TARGET_COMPUTE_MULTILIB hook to override multi-lib result. X-Act-Checkin: gcc X-Git-Author: Kito Cheng X-Git-Refname: refs/heads/master X-Git-Oldrev: 347dec125b662bdeb6d426ead3449e1209c2ce28 X-Git-Newrev: 5ca9980fc86242505ffdaaf62bca1fd5db26550b Message-Id: <20220902092708.BCE8A3858C54@sourceware.org> Date: Fri, 2 Sep 2022 09:27:08 +0000 (GMT) List-Id: https://gcc.gnu.org/g:5ca9980fc86242505ffdaaf62bca1fd5db26550b commit r13-2373-g5ca9980fc86242505ffdaaf62bca1fd5db26550b Author: Kito Cheng Date: Fri Nov 20 15:52:53 2020 +0800 Add TARGET_COMPUTE_MULTILIB hook to override multi-lib result. Create a new hook to let target could override the multi-lib result, the motivation is RISC-V might have very complicated multi-lib re-use rule*, which is hard to maintain and use current multi-lib scripts, we even hit the "argument list too long" error when we tried to add more multi-lib reuse rule. So I think it would be great to have a target specific way to determine the multi-lib re-use rule, then we could write those rule in C, instead of expand every possible case in MULTILIB_REUSE. * Here is an example for RISC-V multi-lib rules: https://gist.github.com/kito-cheng/0289cd42d9a756382e5afeb77b42b73b gcc/ChangeLog: * common/common-target.def (compute_multilib): New. * common/common-targhooks.h (default_compute_multilib): New. * common/common-targhooks.cc (default_compute_multilib): New. * doc/tm.texi.in (TARGET_COMPUTE_MULTILIB): New. * doc/tm.texi: Regen. * gcc.cc: Include common/common-target.h. (set_multilib_dir) Call targetm_common.compute_multilib. (SWITCH_LIVE): Move to opts.h. (SWITCH_FALSE): Ditto. (SWITCH_IGNORE): Ditto. (SWITCH_IGNORE_PERMANENTLY): Ditto. (SWITCH_KEEP_FOR_GCC): Ditto. (struct switchstr): Ditto. * opts.h (SWITCH_LIVE): Move from gcc.c. (SWITCH_FALSE): Ditto. (SWITCH_IGNORE): Ditto. (SWITCH_IGNORE_PERMANENTLY): Ditto. (SWITCH_KEEP_FOR_GCC): Ditto. (struct switchstr): Ditto. Diff: --- gcc/common/common-target.def | 25 ++++++++++++++++++++++ gcc/common/common-targhooks.cc | 15 +++++++++++++ gcc/common/common-targhooks.h | 11 ++++++++++ gcc/doc/tm.texi | 17 +++++++++++++++ gcc/doc/tm.texi.in | 3 +++ gcc/gcc.cc | 48 +++++++++++------------------------------- gcc/opts.h | 36 +++++++++++++++++++++++++++++++ 7 files changed, 119 insertions(+), 36 deletions(-) diff --git a/gcc/common/common-target.def b/gcc/common/common-target.def index c4d1144c4ce..c4c6230073a 100644 --- a/gcc/common/common-target.def +++ b/gcc/common/common-target.def @@ -84,6 +84,31 @@ The result will be pruned to cases with PREFIX if not NULL.", vec, (int option_code, const char *prefix), default_get_valid_option_values) +DEFHOOK +(compute_multilib, + "Some targets like RISC-V might have complicated multilib reuse rules which\n\ +are hard to implement with the current multilib scheme. This hook allows\n\ +targets to override the result from the built-in multilib mechanism.\n\ +@var{switches} is the raw option list with @var{n_switches} items;\n\ +@var{multilib_dir} is the multi-lib result which is computed by the built-in\n\ +multi-lib mechanism;\n\ +@var{multilib_defaults} is the default options list for multi-lib;\n\ +@var{multilib_select} is the string containing the list of supported\n\ +multi-libs, and the option checking list.\n\ +@var{multilib_matches}, @var{multilib_exclusions}, and @var{multilib_reuse}\n\ +are corresponding to @var{MULTILIB_MATCHES}, @var{MULTILIB_EXCLUSIONS},\n\ +and @var{MULTILIB_REUSE}.\n\ +The default definition does nothing but return @var{multilib_dir} directly.", + const char *, (const struct switchstr *switches, + int n_switches, + const char *multilib_dir, + const char *multilib_defaults, + const char *multilib_select, + const char *multilib_matches, + const char *multilib_exclusions, + const char *multilib_reuse), + default_compute_multilib) + /* Leave the boolean fields at the end. */ /* True if unwinding tables should be generated by default. */ diff --git a/gcc/common/common-targhooks.cc b/gcc/common/common-targhooks.cc index 46f5c61e462..7499be27b68 100644 --- a/gcc/common/common-targhooks.cc +++ b/gcc/common/common-targhooks.cc @@ -90,3 +90,18 @@ const struct default_options empty_optimization_table[] = { { OPT_LEVELS_NONE, 0, NULL, 0 } }; + +/* Default version of TARGET_COMPUTE_MULTILIB. */ +const char * +default_compute_multilib( + const struct switchstr *, + int, + const char *multilib, + const char *, + const char *, + const char *, + const char *, + const char *) +{ + return multilib; +} diff --git a/gcc/common/common-targhooks.h b/gcc/common/common-targhooks.h index cd49c7db139..1f034950103 100644 --- a/gcc/common/common-targhooks.h +++ b/gcc/common/common-targhooks.h @@ -32,4 +32,15 @@ extern vec default_get_valid_option_values (int, const char *); extern const struct default_options empty_optimization_table[]; +const char * +default_compute_multilib( + const struct switchstr *, + int, + const char *multilib, + const char *, + const char *, + const char *, + const char *, + const char *); + #endif diff --git a/gcc/doc/tm.texi b/gcc/doc/tm.texi index 431b414cf5d..11be5d0a54a 100644 --- a/gcc/doc/tm.texi +++ b/gcc/doc/tm.texi @@ -778,6 +778,23 @@ options are changed via @code{#pragma GCC optimize} or by using the Set target-dependent initial values of fields in @var{opts}. @end deftypefn +@deftypefn {Common Target Hook} {const char *} TARGET_COMPUTE_MULTILIB (const struct switchstr *@var{switches}, int @var{n_switches}, const char *@var{multilib_dir}, const char *@var{multilib_defaults}, const char *@var{multilib_select}, const char *@var{multilib_matches}, const char *@var{multilib_exclusions}, const char *@var{multilib_reuse}) +Some targets like RISC-V might have complicated multilib reuse rules which +are hard to implement with the current multilib scheme. This hook allows +targets to override the result from the built-in multilib mechanism. +@var{switches} is the raw option list with @var{n_switches} items; +@var{multilib_dir} is the multi-lib result which is computed by the built-in +multi-lib mechanism; +@var{multilib_defaults} is the default options list for multi-lib; +@var{multilib_select} is the string containing the list of supported +multi-libs, and the option checking list. +@var{multilib_matches}, @var{multilib_exclusions}, and @var{multilib_reuse} +are corresponding to @var{MULTILIB_MATCHES}, @var{MULTILIB_EXCLUSIONS}, +and @var{MULTILIB_REUSE}. +The default definition does nothing but return @var{multilib_dir} directly. +@end deftypefn + + @defmac SWITCHABLE_TARGET Some targets need to switch between substantially different subtargets during compilation. For example, the MIPS target has one subtarget for diff --git a/gcc/doc/tm.texi.in b/gcc/doc/tm.texi.in index de0414d6592..0d8cd2eba38 100644 --- a/gcc/doc/tm.texi.in +++ b/gcc/doc/tm.texi.in @@ -736,6 +736,9 @@ options are changed via @code{#pragma GCC optimize} or by using the @hook TARGET_OPTION_INIT_STRUCT +@hook TARGET_COMPUTE_MULTILIB + + @defmac SWITCHABLE_TARGET Some targets need to switch between substantially different subtargets during compilation. For example, the MIPS target has one subtarget for diff --git a/gcc/gcc.cc b/gcc/gcc.cc index c1f084bdf6b..15846116795 100644 --- a/gcc/gcc.cc +++ b/gcc/gcc.cc @@ -45,6 +45,7 @@ compilation is specified by a string called a "spec". */ #include "filenames.h" #include "spellcheck.h" #include "opts-jobserver.h" +#include "common/common-target.h" @@ -3563,42 +3564,6 @@ execute (void) } } -/* Find all the switches given to us - and make a vector describing them. - The elements of the vector are strings, one per switch given. - If a switch uses following arguments, then the `part1' field - is the switch itself and the `args' field - is a null-terminated vector containing the following arguments. - Bits in the `live_cond' field are: - SWITCH_LIVE to indicate this switch is true in a conditional spec. - SWITCH_FALSE to indicate this switch is overridden by a later switch. - SWITCH_IGNORE to indicate this switch should be ignored (used in %