From patchwork Tue Dec 1 09:29:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kito Cheng X-Patchwork-Id: 1408707 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=sifive.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=sifive.com header.i=@sifive.com header.a=rsa-sha256 header.s=google header.b=i59VvBJ5; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4ClcJF1Zd7z9sWS for ; Tue, 1 Dec 2020 20:29:46 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5D96B393D027; Tue, 1 Dec 2020 09:29:38 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pg1-x542.google.com (mail-pg1-x542.google.com [IPv6:2607:f8b0:4864:20::542]) by sourceware.org (Postfix) with ESMTPS id 6AD7C393D016 for ; Tue, 1 Dec 2020 09:29:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 6AD7C393D016 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=sifive.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=kito.cheng@sifive.com Received: by mail-pg1-x542.google.com with SMTP id f17so859002pge.6 for ; Tue, 01 Dec 2020 01:29:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=PgruoN381UFHLDNFfAuISqvoPcwvi+mtQmtO8mLZLAM=; b=i59VvBJ5FSY+lYn4ngT+c4TTYLjj3CopbFTnlGbOPVQ4IwNHpb9aI3Mr5uCluZoP9g X7Z0L2yMO9/95CaeSLKnUdHCN0Ycm2WG90Xq+ud0k0nVTWna8lonKm51Jw4VLV4RSbMX +QRIfosnoxbaIvI/b8X6PJB4aHYxQ6/+H5wbqY+R1um7NeIgdhuHNJiam0jlJnR3Kvwm ekLpGMTvF95RUKqbJQIYNRJujQDcbKovarsR2evJGCi374jGg1o8s+QBq860IyZuGq7g +kzXGZvjPIeAnKnXCg3pTh7o8jM/BSezEUj7hAT+6iRBhz8I1XUBvOWuT+nt6FyMy7GI CZLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=PgruoN381UFHLDNFfAuISqvoPcwvi+mtQmtO8mLZLAM=; b=Q0BTNKuQJ+dI6hh7PSFbcwBJ6tcJdF5Dm0ZewgMikorJvG2vHrMx09+qdhDFlA7P/l B+NbdOBddLTGhcXOeItpqek/Xfek9Nhg0DR/SE1L6bq1q3oOqzMD/UjS93C55TU80wYk cRXvbJbBbWzCGwJw89USfI9g+KghDilJHFsLonRThM6MalcO/ksaS28K0fDK21AsU8P/ 1tywHhy0uAR6+0FkhFKIdD+IrfbsFybPvArbSYPMvZj8bkAoy3tCwFNrF/sqMc/UpKp0 5KF5BDSdV+N0OaAWa4thG7D9tiyeSaMhxnQjWNZkWDs4/iXMAu3FXejTy0uqZjSBWBs5 +lPw== X-Gm-Message-State: AOAM532fQLcmm9CLMQEfFy/mk4eryt25uTdp3+lKqSLyDGQ8+YQhA9/G 8pAobaWt5pgf3xYwdNN/ajnu3RCTkt1TuTWH X-Google-Smtp-Source: ABdhPJyw6ve+fzr6AE7Hwxtc6z+62e+SVWs86vdVk2yDMzHC3emTztHcIgzRwV50RG2StBDNlR1vpA== X-Received: by 2002:a62:1887:0:b029:18c:234a:4640 with SMTP id 129-20020a6218870000b029018c234a4640mr1759202pfy.1.1606814973989; Tue, 01 Dec 2020 01:29:33 -0800 (PST) Received: from hsinchu02.internal.sifive.com (114-34-229-221.HINET-IP.hinet.net. [114.34.229.221]) by smtp.gmail.com with ESMTPSA id q35sm2037503pjh.38.2020.12.01.01.29.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Dec 2020 01:29:33 -0800 (PST) From: Kito Cheng To: gcc-patches@gcc.gnu.org, kito.cheng@gmail.com, jimw@sifive.com Subject: [PATCH 1/2] Add TARGET_COMPUTE_MULTILIB hook to override multi-lib result. Date: Tue, 1 Dec 2020 17:29:19 +0800 Message-Id: <20201201092920.8677-1-kito.cheng@sifive.com> X-Mailer: git-send-email 2.29.2 MIME-Version: 1.0 X-Spam-Status: No, score=-13.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kito Cheng Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" 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 2f64ebe55de..296de01177d 100644 --- a/gcc/common/common-target.def +++ b/gcc/common/common-target.def @@ -84,6 +84,31 @@ DEFHOOK vec, (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 554ed36c3d2..16a1a35e141 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 9f700b1c774..5d3015cb930 100644 --- a/gcc/doc/tm.texi +++ b/gcc/doc/tm.texi @@ -758,6 +758,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 012cb1c53f0..a33dd79d6c4 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 1d32375f648..9f8df9420aa 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" @@ -3535,42 +3536,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 %