From patchwork Thu Sep 16 09:38:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kito Cheng X-Patchwork-Id: 45075 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 49F9A385782A for ; Thu, 16 Sep 2021 09:39:59 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pj1-x1036.google.com (mail-pj1-x1036.google.com [IPv6:2607:f8b0:4864:20::1036]) by sourceware.org (Postfix) with ESMTPS id E696C3857830 for ; Thu, 16 Sep 2021 09:38:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E696C3857830 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=sifive.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=sifive.com Received: by mail-pj1-x1036.google.com with SMTP id f3-20020a17090a638300b00199097ddf1aso7129354pjj.0 for ; Thu, 16 Sep 2021 02:38:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=HXGmzvra77ZhrjwNEyehx8ktBXOZzSIwmFFThgA3hTY=; b=GcLYrWfCcT6OjOP0qK0otQecPsjI/jF58jU7PHEX/XnYz4tu0fmYXq+wMt/KMUZ6A4 w7JIwwr77ff8qN1KgaP7cfvcBPBMGAp9gNny2dkzXonTYsd826GpwesPQlSP/A1HWpS4 Y/+qe4c7qkPJbXQpsI43hpd1ImtEs8hNokSmhlsc8Ke1dvO9lEP6Qa4qo1Rc0h3visP4 Y6kXcnx714EBbyRRqT/n4KNgTxaT5JMIg2rlP0vRCLkHe+SlMQ0I+iiOlhmVrSAp9jC0 F2EaEH5ze8fX8h2DVi+gBuxEAjGYhzNzYFElQ4HW+j5ejmeXWowA9+9N9pkLKq9sgW/N 7hWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=HXGmzvra77ZhrjwNEyehx8ktBXOZzSIwmFFThgA3hTY=; b=5GwT2MxgAgWeQwfzkVSu+CUjkPzI07N7jLaTFIPYsMoZaWyp4bGdkubK/HnU0zCo8N DMAy6rhA9EGY9u0JXKe7Wj2rTX2IQ6j5mJsrTnIHfk315lfYoDgvia72pnl/gxhGfh2I /p50C3y6iZVRnMiaFMwmFrL4yFALnRCL1Q4TwRenLFFHFi8kv/bWEwd2K5zrradojGD8 71cJKk1Z2r3YLWbsOy4V8OlDnu7Xkoxrh34ylfkS7hSj+pzYV5d0TTyxm7tANeJqAY5r /ejlq6Zss2L8xTosGEqhucatvx4OWmvVmGHBc73/zTmZtOC8R6s9GHcj3Drdm7SRrEYk wgzw== X-Gm-Message-State: AOAM533smrzmAvxDvqzMY80AL+ojTgg+q4i4SRjP7fADzVHu8c5PhXlu sTGbQ8elpAIEqPQJ+L3+8aYMJnriqainvw== X-Google-Smtp-Source: ABdhPJz2qoSCdz9lKGwd0EoXTRJ+A/oLNSueVZEwn7o36co6PUO7Vo5Nsqtm6bQVq83d5RjEHVA1Gg== X-Received: by 2002:a17:90b:124c:: with SMTP id gx12mr5146740pjb.106.1631785127542; Thu, 16 Sep 2021 02:38:47 -0700 (PDT) Received: from hsinchu02.internal.sifive.com (59-124-168-89.hinet-ip.hinet.net. [59.124.168.89]) by smtp.gmail.com with ESMTPSA id 77sm2407806pfu.219.2021.09.16.02.38.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Sep 2021 02:38:47 -0700 (PDT) From: Kito Cheng To: gcc-patches@gcc.gnu.org, kito.cheng@gmail.com, jimw@sifive.com, palmer@dabbelt.com, andrew@sifive.com Subject: [PATCH v3 1/2] Add TARGET_COMPUTE_MULTILIB hook to override multi-lib result. Date: Thu, 16 Sep 2021 17:38:37 +0800 Message-Id: <20210916093838.95184-2-kito.cheng@sifive.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210916093838.95184-1-kito.cheng@sifive.com> References: <20210916093838.95184-1-kito.cheng@sifive.com> MIME-Version: 1.0 X-Spam-Status: No, score=-13.6 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.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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+patchwork=sourceware.org@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 | 17 +++++++++++++ gcc/doc/tm.texi.in | 3 +++ gcc/gcc.c | 48 +++++++++-------------------------- gcc/opts.h | 36 ++++++++++++++++++++++++++ 6 files changed, 108 insertions(+), 36 deletions(-) diff --git a/gcc/common/common-target.def b/gcc/common/common-target.def index f54590a2a54..b7cf713770c 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.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 be8148583d8..6f1e0293b6c 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 d088eee4afe..ad78439ea61 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" @@ -3573,42 +3574,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 %