From: Kito Cheng <kito.cheng@sifive.com>
To: gcc-patches@gcc.gnu.org, kito.cheng@gmail.com, jimw@sifive.com
Cc: Kito Cheng <kito.cheng@sifive.com>
Subject: [PATCH 1/2] Add TARGET_COMPUTE_MULTILIB hook to override multi-lib result.
Date: Wed, 21 Jul 2021 17:28:10 +0800 [thread overview]
Message-ID: <20210721092810.66070-2-kito.cheng@sifive.com> (raw)
In-Reply-To: <20210721092810.66070-1-kito.cheng@sifive.com>
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.c (default_compute_multilib): New.
* doc/tm.texi.in (TARGET_COMPUTE_MULTILIB): New.
* doc/tm.texi: Regen.
* gcc.c: 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.
---
gcc/common/common-target.def | 25 ++++++++++++++++++
gcc/common/common-targhooks.c | 15 +++++++++++
gcc/doc/tm.texi | 5 ++++
gcc/doc/tm.texi.in | 3 +++
gcc/gcc.c | 48 +++++++++--------------------------
gcc/opts.h | 36 ++++++++++++++++++++++++++
6 files changed, 96 insertions(+), 36 deletions(-)
diff --git a/gcc/common/common-target.def b/gcc/common/common-target.def
index f54590a2a54..a720ecbea98 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<const char *>, (int option_code, const char *prefix),
default_get_valid_option_values)
+DEFHOOK
+(compute_multilib,
+ "Some target like RISC-V might have complicated multilib reuse rule which is\
+ hard to implemented on current multilib scheme, this hook allow target to\
+ override the result from 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 compute by the built-in\
+ multi-lib mechanism;\
+ @var{multilib_defaults} is the default options list for multi-lib; \
+ @var{multilib_select} is the string contain the list of supported multi-lib, \
+ and the option checking list. \
+ @var{multilib_matches}, @var{multilib_exclusions}, and @var{multilib_reuse} \
+ are corresponding to @var{MULTILIB_MATCHES}, @var{MULTILIB_EXCLUSIONS} \
+ @var{MULTILIB_REUSE}. \
+ 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.c b/gcc/common/common-targhooks.c
index 325f199bff3..1477aeeb536 100644
--- a/gcc/common/common-targhooks.c
+++ b/gcc/common/common-targhooks.c
@@ -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/doc/tm.texi b/gcc/doc/tm.texi
index c8f4abe3e41..0268ea77996 100644
--- a/gcc/doc/tm.texi
+++ b/gcc/doc/tm.texi
@@ -778,6 +778,11 @@ 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 target like RISC-V might have complicated multilib reuse rule which is hard to implemented on current multilib scheme, this hook allow target to override the result from 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 compute by the built-in multi-lib mechanism; @var{multilib_defaults} is the default options list for multi-lib; @var{multilib_select} is the string contain the list of supported multi-lib, and the option checking list. @var{multilib_matches}, @var{multilib_exclusions}, and @var{multilib_reuse} are corresponding to @var{MULTILIB_MATCHES}, @var{MULTILIB_EXCLUSIONS} @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 9c4b5016053..6f93edc15c0 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.c b/gcc/gcc.c
index 3e98bc7973e..dafe754267a 100644
--- a/gcc/gcc.c
+++ b/gcc/gcc.c
@@ -43,6 +43,7 @@ compilation is specified by a string called a "spec". */
#include "opts.h"
#include "filenames.h"
#include "spellcheck.h"
+#include "common/common-target.h"
\f
@@ -3573,42 +3574,6 @@ execute (void)
}
}
\f
-/* 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 %<S).
- SWITCH_IGNORE_PERMANENTLY to indicate this switch should be ignored.
- SWITCH_KEEP_FOR_GCC to indicate that this switch, otherwise ignored,
- should be included in COLLECT_GCC_OPTIONS.
- in all do_spec calls afterwards. Used for %<S from self specs.
- The `known' field describes whether this is an internal switch.
- The `validated' field describes whether any spec has looked at this switch;
- if it remains false at the end of the run, the switch must be meaningless.
- The `ordering' field is used to temporarily mark switches that have to be
- kept in a specific order. */
-
-#define SWITCH_LIVE (1 << 0)
-#define SWITCH_FALSE (1 << 1)
-#define SWITCH_IGNORE (1 << 2)
-#define SWITCH_IGNORE_PERMANENTLY (1 << 3)
-#define SWITCH_KEEP_FOR_GCC (1 << 4)
-
-struct switchstr
-{
- const char *part1;
- const char **args;
- unsigned int live_cond;
- bool known;
- bool validated;
- bool ordering;
-};
-
static struct switchstr *switches;
static int n_switches;
@@ -9855,6 +9820,17 @@ set_multilib_dir (void)
++p;
}
+ multilib_dir =
+ targetm_common.compute_multilib (
+ switches,
+ n_switches,
+ multilib_dir,
+ multilib_defaults,
+ multilib_select,
+ multilib_matches,
+ multilib_exclusions,
+ multilib_reuse);
+
if (multilib_dir == NULL && multilib_os_dir != NULL
&& strcmp (multilib_os_dir, ".") == 0)
{
diff --git a/gcc/opts.h b/gcc/opts.h
index bafc790112b..f99a469364c 100644
--- a/gcc/opts.h
+++ b/gcc/opts.h
@@ -500,4 +500,40 @@ extern char *gen_producer_string (const char *language_string,
} \
while (false)
+/* 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 %<S).
+ SWITCH_IGNORE_PERMANENTLY to indicate this switch should be ignored.
+ SWITCH_KEEP_FOR_GCC to indicate that this switch, otherwise ignored,
+ should be included in COLLECT_GCC_OPTIONS.
+ in all do_spec calls afterwards. Used for %<S from self specs.
+ The `known' field describes whether this is an internal switch.
+ The `validated' field describes whether any spec has looked at this switch;
+ if it remains false at the end of the run, the switch must be meaningless.
+ The `ordering' field is used to temporarily mark switches that have to be
+ kept in a specific order. */
+
+#define SWITCH_LIVE (1 << 0)
+#define SWITCH_FALSE (1 << 1)
+#define SWITCH_IGNORE (1 << 2)
+#define SWITCH_IGNORE_PERMANENTLY (1 << 3)
+#define SWITCH_KEEP_FOR_GCC (1 << 4)
+
+struct switchstr
+{
+ const char *part1;
+ const char **args;
+ unsigned int live_cond;
+ bool known;
+ bool validated;
+ bool ordering;
+};
+
#endif
--
2.31.1
next prev parent reply other threads:[~2021-07-21 9:28 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-21 9:28 [PATCH 0/2] New target hook TARGET_COMPUTE_MULTILIB and implementation for RISC-V Kito Cheng
2021-07-21 9:28 ` Kito Cheng [this message]
2021-09-01 0:16 ` [PATCH 1/2] Add TARGET_COMPUTE_MULTILIB hook to override multi-lib result Jim Wilson
2021-07-21 9:28 ` [PATCH 2/2] RISC-V: Implement TARGET_COMPUTE_MULTILIB Kito Cheng
2021-09-01 0:22 ` Jim Wilson
2021-09-01 0:23 ` Jim Wilson
2021-09-16 4:12 ` Kito Cheng
2022-09-09 7:20 ` Andreas Schwab
2022-09-09 9:58 ` Kito Cheng
2021-07-29 18:44 ` [PATCH 0/2] New target hook TARGET_COMPUTE_MULTILIB and implementation for RISC-V Kito Cheng
2021-07-29 19:00 ` Palmer Dabbelt
2022-09-02 9:28 ` Kito Cheng
-- strict thread matches above, loose matches on Subject: below --
2020-12-01 9:29 [PATCH 1/2] Add TARGET_COMPUTE_MULTILIB hook to override multi-lib result Kito Cheng
2020-12-02 5:27 ` Jeff Law
2020-12-02 5:39 ` Kito Cheng
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210721092810.66070-2-kito.cheng@sifive.com \
--to=kito.cheng@sifive.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=jimw@sifive.com \
--cc=kito.cheng@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).