Message ID | 20220607025120.1601-1-pc.wang@linux.alibaba.com |
---|---|
State | Deferred, archived |
Headers |
Return-Path: <gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org> 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 EB965382F0BB for <patchwork@sourceware.org>; Tue, 7 Jun 2022 02:53:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EB965382F0BB DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1654570413; bh=0lNyvjpaCav910KmsboFfY+Gfn8QwXFM5rRFDe3Nxis=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=HQzZWLFAImrLPXmZ4R8qaP3JK2qy9kZGb55iEKGVSIc5jnHD/WdAssQxnOhbpDFRJ nJ7EOTJNQnagqPHH7rV8hcmDvXowyeh67/KqqC4qvbjF+Na2x/MXrIWsbrAjwWchEz HxDIdYk/wmacOkBy4BmeobdIWalcd8SrHIrTenVM= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from out199-10.us.a.mail.aliyun.com (out199-10.us.a.mail.aliyun.com [47.90.199.10]) by sourceware.org (Postfix) with ESMTPS id 61BE1386F0FD for <gcc-patches@gcc.gnu.org>; Tue, 7 Jun 2022 02:53:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 61BE1386F0FD X-Alimail-AntiSpam: AC=PASS; BC=-1|-1; BR=01201311R121e4; CH=green; DM=||false|; DS=||; FP=0|-1|-1|-1|0|-1|-1|-1; HT=e01e04357; MF=pc.wang@linux.alibaba.com; NM=1; PH=DS; RN=2; SR=0; TI=SMTPD_---0VFbXKIq_1654570328; Received: from localhost.localdomain(mailfrom:pc.wang@linux.alibaba.com fp:SMTPD_---0VFbXKIq_1654570328) by smtp.aliyun-inc.com; Tue, 07 Jun 2022 10:52:57 +0800 To: gcc-patches@gcc.gnu.org Subject: [PATCH] RISC-V: Compute default ABI from -mcpu or -march Date: Tue, 7 Jun 2022 10:51:20 +0800 Message-Id: <20220607025120.1601-1-pc.wang@linux.alibaba.com> X-Mailer: git-send-email 2.34.1.windows.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-21.7 required=5.0 tests=BAYES_00, ENV_AND_HDR_SPF_MATCH, GIT_PATCH_0, KAM_DMARC_STATUS, KAM_SHORT, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE, UNPARSEABLE_RELAY, USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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 <gcc-patches.gcc.gnu.org> List-Unsubscribe: <https://gcc.gnu.org/mailman/options/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe> List-Archive: <https://gcc.gnu.org/pipermail/gcc-patches/> List-Post: <mailto:gcc-patches@gcc.gnu.org> List-Help: <mailto:gcc-patches-request@gcc.gnu.org?subject=help> List-Subscribe: <https://gcc.gnu.org/mailman/listinfo/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe> From: wangpc via Gcc-patches <gcc-patches@gcc.gnu.org> Reply-To: wangpc <pc.wang@linux.alibaba.com> Cc: wangpc <pc.wang@linux.alibaba.com> Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" <gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org> |
Series |
RISC-V: Compute default ABI from -mcpu or -march
|
|
Commit Message
pc.wang
June 7, 2022, 2:51 a.m. UTC
If -mcpu or -march is specified and there is no -mabi, we will calculate default ABI from arch string provided by -march or defined in CPU info. gcc/ChangeLog: * common/config/riscv/riscv-common.cc (compute_default_abi): Implementation to calculate -mabi from arch string. (riscv_expand_abi_from_arch): New spec function to calcalute -mabi from arch string provided by -march option. (riscv_expand_abi_from_cpu): New spec function to find CPU info and calculate -mabi from arch string defined in CPU info. * config/riscv/riscv.h (EXTRA_SPEC_FUNCTIONS): Add above spec functions. (OPTION_DEFAULT_SPECS): Use new spec functions to calculate -mabi and -march has higher priority than -mcpu. gcc/testsuite/ChangeLog: * gcc.target/riscv/mabi-1.c: ilp32e test. * gcc.target/riscv/mabi-2.c: ilp32 test. * gcc.target/riscv/mabi-3.c: ilp32f test. * gcc.target/riscv/mabi-4.c: ilp32d test. * gcc.target/riscv/mabi-5.c: lp64 test. * gcc.target/riscv/mabi-6.c: lp64f test. * gcc.target/riscv/mabi-7.c: lp64d test. * gcc.target/riscv/mabi-8.c: -march override -mcpu. --- gcc/common/config/riscv/riscv-common.cc | 66 +++++++++++++++++++++++++ gcc/config/riscv/riscv.h | 15 ++++-- gcc/testsuite/gcc.target/riscv/mabi-1.c | 7 +++ gcc/testsuite/gcc.target/riscv/mabi-2.c | 7 +++ gcc/testsuite/gcc.target/riscv/mabi-3.c | 7 +++ gcc/testsuite/gcc.target/riscv/mabi-4.c | 7 +++ gcc/testsuite/gcc.target/riscv/mabi-5.c | 7 +++ gcc/testsuite/gcc.target/riscv/mabi-6.c | 7 +++ gcc/testsuite/gcc.target/riscv/mabi-7.c | 7 +++ gcc/testsuite/gcc.target/riscv/mabi-8.c | 7 +++ 10 files changed, 134 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/gcc.target/riscv/mabi-1.c create mode 100644 gcc/testsuite/gcc.target/riscv/mabi-2.c create mode 100644 gcc/testsuite/gcc.target/riscv/mabi-3.c create mode 100644 gcc/testsuite/gcc.target/riscv/mabi-4.c create mode 100644 gcc/testsuite/gcc.target/riscv/mabi-5.c create mode 100644 gcc/testsuite/gcc.target/riscv/mabi-6.c create mode 100644 gcc/testsuite/gcc.target/riscv/mabi-7.c create mode 100644 gcc/testsuite/gcc.target/riscv/mabi-8.c
Comments
On Mon, 06 Jun 2022 19:51:20 PDT (-0700), gcc-patches@gcc.gnu.org wrote: > If -mcpu or -march is specified and there is no -mabi, we will calculate > default ABI from arch string provided by -march or defined in CPU info. IMO this is generally a good idea and we've talked about it before, but just setting the ABI from the ISA isn't quite the right way to go. IIRC we came up with something slightly more complicated, like picking the closest supported multilib. That's probably more in line with what users are asking for, which IIUC is sort of just "I don't care that much about ABI, just make my stuff build". Whatever we do here, we should document in the RISC-V specs as we'll want to make sure LLVM does the same thing. We probably also want some sort of "-mabi=auto" argument, as it's always best to have an argument that changes back to the no-argument behavior. > > gcc/ChangeLog: > > * common/config/riscv/riscv-common.cc (compute_default_abi): Implementation > to calculate -mabi from arch string. > (riscv_expand_abi_from_arch): New spec function to calcalute -mabi from arch > string provided by -march option. > (riscv_expand_abi_from_cpu): New spec function to find CPU info and calculate > -mabi from arch string defined in CPU info. > * config/riscv/riscv.h (EXTRA_SPEC_FUNCTIONS): Add above spec functions. > (OPTION_DEFAULT_SPECS): Use new spec functions to calculate -mabi and -march > has higher priority than -mcpu. > > gcc/testsuite/ChangeLog: > > * gcc.target/riscv/mabi-1.c: ilp32e test. > * gcc.target/riscv/mabi-2.c: ilp32 test. > * gcc.target/riscv/mabi-3.c: ilp32f test. > * gcc.target/riscv/mabi-4.c: ilp32d test. > * gcc.target/riscv/mabi-5.c: lp64 test. > * gcc.target/riscv/mabi-6.c: lp64f test. > * gcc.target/riscv/mabi-7.c: lp64d test. > * gcc.target/riscv/mabi-8.c: -march override -mcpu. > --- > gcc/common/config/riscv/riscv-common.cc | 66 +++++++++++++++++++++++++ > gcc/config/riscv/riscv.h | 15 ++++-- > gcc/testsuite/gcc.target/riscv/mabi-1.c | 7 +++ > gcc/testsuite/gcc.target/riscv/mabi-2.c | 7 +++ > gcc/testsuite/gcc.target/riscv/mabi-3.c | 7 +++ > gcc/testsuite/gcc.target/riscv/mabi-4.c | 7 +++ > gcc/testsuite/gcc.target/riscv/mabi-5.c | 7 +++ > gcc/testsuite/gcc.target/riscv/mabi-6.c | 7 +++ > gcc/testsuite/gcc.target/riscv/mabi-7.c | 7 +++ > gcc/testsuite/gcc.target/riscv/mabi-8.c | 7 +++ > 10 files changed, 134 insertions(+), 3 deletions(-) > create mode 100644 gcc/testsuite/gcc.target/riscv/mabi-1.c > create mode 100644 gcc/testsuite/gcc.target/riscv/mabi-2.c > create mode 100644 gcc/testsuite/gcc.target/riscv/mabi-3.c > create mode 100644 gcc/testsuite/gcc.target/riscv/mabi-4.c > create mode 100644 gcc/testsuite/gcc.target/riscv/mabi-5.c > create mode 100644 gcc/testsuite/gcc.target/riscv/mabi-6.c > create mode 100644 gcc/testsuite/gcc.target/riscv/mabi-7.c > create mode 100644 gcc/testsuite/gcc.target/riscv/mabi-8.c > > diff --git a/gcc/common/config/riscv/riscv-common.cc b/gcc/common/config/riscv/riscv-common.cc > index 0e5be2ce105..f8e40549d18 100644 > --- a/gcc/common/config/riscv/riscv-common.cc > +++ b/gcc/common/config/riscv/riscv-common.cc > @@ -1266,6 +1266,72 @@ riscv_default_mtune (int argc, const char **argv) > return default_mtune; > } > > +/* Compute default -mabi option from arch string. */ > + > +static const char * > +compute_default_abi (const char* arch_str) > +{ > + location_t loc = UNKNOWN_LOCATION; > + > + riscv_parse_arch_string (arch_str, NULL, loc); > + > + if (current_subset_list->xlen () == 64) > + { > + if (current_subset_list->lookup ("d", RISCV_DONT_CARE_VERSION, > + RISCV_DONT_CARE_VERSION)) > + return "lp64d"; > + if (current_subset_list->lookup ("f", RISCV_DONT_CARE_VERSION, > + RISCV_DONT_CARE_VERSION)) > + return "lp64f"; > + return "lp64"; > + } > + else > + { > + if (current_subset_list->lookup ("e", RISCV_DONT_CARE_VERSION, > + RISCV_DONT_CARE_VERSION)) > + return "ilp32e"; > + if (current_subset_list->lookup ("d", RISCV_DONT_CARE_VERSION, > + RISCV_DONT_CARE_VERSION)) > + return "ilp32d"; > + if (current_subset_list->lookup ("f", RISCV_DONT_CARE_VERSION, > + RISCV_DONT_CARE_VERSION)) > + return "ilp32f"; > + return "ilp32"; > + } > +} > + > +/* Expand default -mabi option from -march option. */ > + > +const char * > +riscv_expand_abi_from_arch (int argc, const char **argv) > +{ > + gcc_assert (argc == 1); > + return xasprintf ("-mabi=%s", compute_default_abi (argv[0])); > +} > + > +/* Expand default -mabi option from -mcpu option. */ > + > +const char * > +riscv_expand_abi_from_cpu (int argc, const char **argv) > +{ > + gcc_assert (argc > 0 && argc <= 2); > + const char *default_abi_str = NULL; > + if (argc >= 2) > + default_abi_str = argv[1]; > + > + const riscv_cpu_info *cpu = riscv_find_cpu (argv[0]); > + > + if (cpu == NULL) > + { > + if (default_abi_str == NULL) > + return ""; > + else > + return xasprintf ("-mabi=%s", default_abi_str); > + } > + else > + return xasprintf ("-mabi=%s", compute_default_abi (cpu->arch)); > +} > + > /* Expand arch string with implied extensions from -mcpu option. */ > > const char * > diff --git a/gcc/config/riscv/riscv.h b/gcc/config/riscv/riscv.h > index 6f7f4d3fbdc..14cd695f37f 100644 > --- a/gcc/config/riscv/riscv.h > +++ b/gcc/config/riscv/riscv.h > @@ -50,15 +50,20 @@ along with GCC; see the file COPYING3. If not see > extern const char *riscv_expand_arch (int argc, const char **argv); > extern const char *riscv_expand_arch_from_cpu (int argc, const char **argv); > extern const char *riscv_default_mtune (int argc, const char **argv); > +extern const char *riscv_expand_abi_from_arch (int argc, const char **argv); > +extern const char *riscv_expand_abi_from_cpu (int argc, const char **argv); > > # define EXTRA_SPEC_FUNCTIONS \ > { "riscv_expand_arch", riscv_expand_arch }, \ > { "riscv_expand_arch_from_cpu", riscv_expand_arch_from_cpu }, \ > - { "riscv_default_mtune", riscv_default_mtune }, > + { "riscv_default_mtune", riscv_default_mtune }, \ > + { "riscv_expand_abi_from_arch", riscv_expand_abi_from_arch }, \ > + { "riscv_expand_abi_from_cpu", riscv_expand_abi_from_cpu }, > > /* Support for a compile-time default CPU, et cetera. The rules are: > --with-arch is ignored if -march or -mcpu is specified. > - --with-abi is ignored if -mabi is specified. > + --with-abi is ignored if -mabi is specified. If -mcpu or -march is > + specified, suitable -mabi will be selected from arch string. > --with-tune is ignored if -mtune or -mcpu is specified. > --with-isa-spec is ignored if -misa-spec is specified. > > @@ -70,7 +75,11 @@ extern const char *riscv_default_mtune (int argc, const char **argv); > {"arch", "%{!march=*:" \ > " %{!mcpu=*:-march=%(VALUE)}" \ > " %{mcpu=*:%:riscv_expand_arch_from_cpu(%* %(VALUE))}}" }, \ > - {"abi", "%{!mabi=*:-mabi=%(VALUE)}" }, \ > + {"abi", "%{!mabi=*:" \ > + " %{!march=*:" \ > + " %{!mcpu=*:-mabi=%(VALUE)}" \ > + " %{mcpu=*:%:riscv_expand_abi_from_cpu(%* %(VALUE))}}" \ > + " %{march=*:%:riscv_expand_abi_from_arch(%*)}}" }, \ > {"isa_spec", "%{!misa-spec=*:-misa-spec=%(VALUE)}" }, \ > > #ifdef IN_LIBGCC2 > diff --git a/gcc/testsuite/gcc.target/riscv/mabi-1.c b/gcc/testsuite/gcc.target/riscv/mabi-1.c > new file mode 100644 > index 00000000000..83bc343f8d8 > --- /dev/null > +++ b/gcc/testsuite/gcc.target/riscv/mabi-1.c > @@ -0,0 +1,7 @@ > +/* { dg-do compile } */ > +/* { dg-skip-if "-mabi given" { *-*-* } { "-mabi=*" } } */ > +/* { dg-options "-march=rv32e" } */ > + > +#if !((__riscv_xlen == 32) && defined(__riscv_abi_rve)) > +#error "unexpected abi" > +#endif > diff --git a/gcc/testsuite/gcc.target/riscv/mabi-2.c b/gcc/testsuite/gcc.target/riscv/mabi-2.c > new file mode 100644 > index 00000000000..6a97c2ae2a3 > --- /dev/null > +++ b/gcc/testsuite/gcc.target/riscv/mabi-2.c > @@ -0,0 +1,7 @@ > +/* { dg-do compile } */ > +/* { dg-skip-if "-mabi given" { *-*-* } { "-mabi=*" } } */ > +/* { dg-options "-march=rv32ima" } */ > + > +#if !((__riscv_xlen == 32) && defined(__riscv_float_abi_soft)) > +#error "unexpected abi" > +#endif > diff --git a/gcc/testsuite/gcc.target/riscv/mabi-3.c b/gcc/testsuite/gcc.target/riscv/mabi-3.c > new file mode 100644 > index 00000000000..cef04313e19 > --- /dev/null > +++ b/gcc/testsuite/gcc.target/riscv/mabi-3.c > @@ -0,0 +1,7 @@ > +/* { dg-do compile } */ > +/* { dg-skip-if "-mabi given" { *-*-* } { "-mabi=*" } } */ > +/* { dg-options "-march=rv32imaf" } */ > + > +#if !((__riscv_xlen == 32) && defined(__riscv_float_abi_single)) > +#error "unexpected abi" > +#endif > diff --git a/gcc/testsuite/gcc.target/riscv/mabi-4.c b/gcc/testsuite/gcc.target/riscv/mabi-4.c > new file mode 100644 > index 00000000000..d62dcf6ed75 > --- /dev/null > +++ b/gcc/testsuite/gcc.target/riscv/mabi-4.c > @@ -0,0 +1,7 @@ > +/* { dg-do compile } */ > +/* { dg-skip-if "-mabi given" { *-*-* } { "-mabi=*" } } */ > +/* { dg-options "-march=rv32imafd" } */ > + > +#if !((__riscv_xlen == 32) && defined(__riscv_float_abi_double)) > +#error "unexpected abi" > +#endif > diff --git a/gcc/testsuite/gcc.target/riscv/mabi-5.c b/gcc/testsuite/gcc.target/riscv/mabi-5.c > new file mode 100644 > index 00000000000..000e5e282c2 > --- /dev/null > +++ b/gcc/testsuite/gcc.target/riscv/mabi-5.c > @@ -0,0 +1,7 @@ > +/* { dg-do compile } */ > +/* { dg-skip-if "-mabi given" { *-*-* } { "-mabi=*" } } */ > +/* { dg-options "-march=rv64ima" } */ > + > +#if !((__riscv_xlen == 64) && defined(__riscv_float_abi_soft)) > +#error "unexpected abi" > +#endif > diff --git a/gcc/testsuite/gcc.target/riscv/mabi-6.c b/gcc/testsuite/gcc.target/riscv/mabi-6.c > new file mode 100644 > index 00000000000..ed1458d4158 > --- /dev/null > +++ b/gcc/testsuite/gcc.target/riscv/mabi-6.c > @@ -0,0 +1,7 @@ > +/* { dg-do compile } */ > +/* { dg-skip-if "-mabi given" { *-*-* } { "-mabi=*" } } */ > +/* { dg-options "-march=rv64imaf" } */ > + > +#if !((__riscv_xlen == 64) && defined(__riscv_float_abi_single)) > +#error "unexpected abi" > +#endif > diff --git a/gcc/testsuite/gcc.target/riscv/mabi-7.c b/gcc/testsuite/gcc.target/riscv/mabi-7.c > new file mode 100644 > index 00000000000..675fe359cfd > --- /dev/null > +++ b/gcc/testsuite/gcc.target/riscv/mabi-7.c > @@ -0,0 +1,7 @@ > +/* { dg-do compile } */ > +/* { dg-skip-if "-mabi given" { *-*-* } { "-mabi=*" } } */ > +/* { dg-options "-march=rv64imafd" } */ > + > +#if !((__riscv_xlen == 64) && defined(__riscv_float_abi_double)) > +#error "unexpected abi" > +#endif > diff --git a/gcc/testsuite/gcc.target/riscv/mabi-8.c b/gcc/testsuite/gcc.target/riscv/mabi-8.c > new file mode 100644 > index 00000000000..8c7e08e4289 > --- /dev/null > +++ b/gcc/testsuite/gcc.target/riscv/mabi-8.c > @@ -0,0 +1,7 @@ > +/* { dg-do compile } */ > +/* { dg-skip-if "-mabi given" { *-*-* } { "-mabi=*" } } */ > +/* { dg-options "-mcpu=sifive-s21 -march=rv64imafd" } */ > + > +#if !((__riscv_xlen == 64) && defined(__riscv_float_abi_double)) > +#error "unexpected abi" > +#endif
Thanks for your opinion! I did these just because LLVM has already done the same thing and I wanted to make GCC with the same behavior of LLVM. The only difference is that LLVM has no handling for ilp32f and lp64f and I have sent a patch to do it (sees https://reviews.llvm.org/D125947). As for RISC-V specs, there are some descriptions in https://github.com/riscv-non-isa/riscv-toolchain-conventions#specifying-the-target-isa-with--march: > A target -march which includes floating point instructions implies a hardfloat calling convention, but can be overridden using the -mabi flag (see the next section). But I think we can make it clearer. ------------------------------------------------------------------ Sender:Palmer Dabbelt <palmer@dabbelt.com> Sent At:2022 Jun. 8 (Wed.) 02:45 Recipient:gcc-patches <gcc-patches@gcc.gnu.org> Cc:pc.wang <pc.wang@linux.alibaba.com> Subject:Re: [PATCH] RISC-V: Compute default ABI from -mcpu or -march On Mon, 06 Jun 2022 19:51:20 PDT (-0700), gcc-patches@gcc.gnu.org wrote: > If -mcpu or -march is specified and there is no -mabi, we will calculate > default ABI from arch string provided by -march or defined in CPU info. IMO this is generally a good idea and we've talked about it before, but just setting the ABI from the ISA isn't quite the right way to go. IIRC we came up with something slightly more complicated, like picking the closest supported multilib. That's probably more in line with what users are asking for, which IIUC is sort of just "I don't care that much about ABI, just make my stuff build". Whatever we do here, we should document in the RISC-V specs as we'll want to make sure LLVM does the same thing. We probably also want some sort of "-mabi=auto" argument, as it's always best to have an argument that changes back to the no-argument behavior. > > gcc/ChangeLog: > > * common/config/riscv/riscv-common.cc (compute_default_abi): Implementation > to calculate -mabi from arch string. > (riscv_expand_abi_from_arch): New spec function to calcalute -mabi from arch > string provided by -march option. > (riscv_expand_abi_from_cpu): New spec function to find CPU info and calculate > -mabi from arch string defined in CPU info. > * config/riscv/riscv.h (EXTRA_SPEC_FUNCTIONS): Add above spec functions. > (OPTION_DEFAULT_SPECS): Use new spec functions to calculate -mabi and -march > has higher priority than -mcpu. > > gcc/testsuite/ChangeLog: > > * gcc.target/riscv/mabi-1.c: ilp32e test. > * gcc.target/riscv/mabi-2.c: ilp32 test. > * gcc.target/riscv/mabi-3.c: ilp32f test. > * gcc.target/riscv/mabi-4.c: ilp32d test. > * gcc.target/riscv/mabi-5.c: lp64 test. > * gcc.target/riscv/mabi-6.c: lp64f test. > * gcc.target/riscv/mabi-7.c: lp64d test. > * gcc.target/riscv/mabi-8.c: -march override -mcpu. > --- > gcc/common/config/riscv/riscv-common.cc | 66 +++++++++++++++++++++++++ > gcc/config/riscv/riscv.h | 15 ++++-- > gcc/testsuite/gcc.target/riscv/mabi-1.c | 7 +++ > gcc/testsuite/gcc.target/riscv/mabi-2.c | 7 +++ > gcc/testsuite/gcc.target/riscv/mabi-3.c | 7 +++ > gcc/testsuite/gcc.target/riscv/mabi-4.c | 7 +++ > gcc/testsuite/gcc.target/riscv/mabi-5.c | 7 +++ > gcc/testsuite/gcc.target/riscv/mabi-6.c | 7 +++ > gcc/testsuite/gcc.target/riscv/mabi-7.c | 7 +++ > gcc/testsuite/gcc.target/riscv/mabi-8.c | 7 +++ > 10 files changed, 134 insertions(+), 3 deletions(-) > create mode 100644 gcc/testsuite/gcc.target/riscv/mabi-1.c > create mode 100644 gcc/testsuite/gcc.target/riscv/mabi-2.c > create mode 100644 gcc/testsuite/gcc.target/riscv/mabi-3.c > create mode 100644 gcc/testsuite/gcc.target/riscv/mabi-4.c > create mode 100644 gcc/testsuite/gcc.target/riscv/mabi-5.c > create mode 100644 gcc/testsuite/gcc.target/riscv/mabi-6.c > create mode 100644 gcc/testsuite/gcc.target/riscv/mabi-7.c > create mode 100644 gcc/testsuite/gcc.target/riscv/mabi-8.c > > diff --git a/gcc/common/config/riscv/riscv-common.cc b/gcc/common/config/riscv/riscv-common.cc > index 0e5be2ce105..f8e40549d18 100644 > --- a/gcc/common/config/riscv/riscv-common.cc > +++ b/gcc/common/config/riscv/riscv-common.cc > @@ -1266,6 +1266,72 @@ riscv_default_mtune (int argc, const char **argv) > return default_mtune; > } > > +/* Compute default -mabi option from arch string. */ > + > +static const char * > +compute_default_abi (const char* arch_str) > +{ > + location_t loc = UNKNOWN_LOCATION; > + > + riscv_parse_arch_string (arch_str, NULL, loc); > + > + if (current_subset_list->xlen () == 64) > + { > + if (current_subset_list->lookup ("d", RISCV_DONT_CARE_VERSION, > + RISCV_DONT_CARE_VERSION)) > + return "lp64d"; > + if (current_subset_list->lookup ("f", RISCV_DONT_CARE_VERSION, > + RISCV_DONT_CARE_VERSION)) > + return "lp64f"; > + return "lp64"; > + } > + else > + { > + if (current_subset_list->lookup ("e", RISCV_DONT_CARE_VERSION, > + RISCV_DONT_CARE_VERSION)) > + return "ilp32e"; > + if (current_subset_list->lookup ("d", RISCV_DONT_CARE_VERSION, > + RISCV_DONT_CARE_VERSION)) > + return "ilp32d"; > + if (current_subset_list->lookup ("f", RISCV_DONT_CARE_VERSION, > + RISCV_DONT_CARE_VERSION)) > + return "ilp32f"; > + return "ilp32"; > + } > +} > + > +/* Expand default -mabi option from -march option. */ > + > +const char * > +riscv_expand_abi_from_arch (int argc, const char **argv) > +{ > + gcc_assert (argc == 1); > + return xasprintf ("-mabi=%s", compute_default_abi (argv[0])); > +} > + > +/* Expand default -mabi option from -mcpu option. */ > + > +const char * > +riscv_expand_abi_from_cpu (int argc, const char **argv) > +{ > + gcc_assert (argc > 0 && argc <= 2); > + const char *default_abi_str = NULL; > + if (argc >= 2) > + default_abi_str = argv[1]; > + > + const riscv_cpu_info *cpu = riscv_find_cpu (argv[0]); > + > + if (cpu == NULL) > + { > + if (default_abi_str == NULL) > + return ""; > + else > + return xasprintf ("-mabi=%s", default_abi_str); > + } > + else > + return xasprintf ("-mabi=%s", compute_default_abi (cpu->arch)); > +} > + > /* Expand arch string with implied extensions from -mcpu option. */ > > const char * > diff --git a/gcc/config/riscv/riscv.h b/gcc/config/riscv/riscv.h > index 6f7f4d3fbdc..14cd695f37f 100644 > --- a/gcc/config/riscv/riscv.h > +++ b/gcc/config/riscv/riscv.h > @@ -50,15 +50,20 @@ along with GCC; see the file COPYING3. If not see > extern const char *riscv_expand_arch (int argc, const char **argv); > extern const char *riscv_expand_arch_from_cpu (int argc, const char **argv); > extern const char *riscv_default_mtune (int argc, const char **argv); > +extern const char *riscv_expand_abi_from_arch (int argc, const char **argv); > +extern const char *riscv_expand_abi_from_cpu (int argc, const char **argv); > > # define EXTRA_SPEC_FUNCTIONS \ > { "riscv_expand_arch", riscv_expand_arch }, \ > { "riscv_expand_arch_from_cpu", riscv_expand_arch_from_cpu }, \ > - { "riscv_default_mtune", riscv_default_mtune }, > + { "riscv_default_mtune", riscv_default_mtune }, \ > + { "riscv_expand_abi_from_arch", riscv_expand_abi_from_arch }, \ > + { "riscv_expand_abi_from_cpu", riscv_expand_abi_from_cpu }, > > /* Support for a compile-time default CPU, et cetera. The rules are: > --with-arch is ignored if -march or -mcpu is specified. > - --with-abi is ignored if -mabi is specified. > + --with-abi is ignored if -mabi is specified. If -mcpu or -march is > + specified, suitable -mabi will be selected from arch string. > --with-tune is ignored if -mtune or -mcpu is specified. > --with-isa-spec is ignored if -misa-spec is specified. > > @@ -70,7 +75,11 @@ extern const char *riscv_default_mtune (int argc, const char **argv); > {"arch", "%{!march=*:" \ > " %{!mcpu=*:-march=%(VALUE)}" \ > " %{mcpu=*:%:riscv_expand_arch_from_cpu(%* %(VALUE))}}" }, \ > - {"abi", "%{!mabi=*:-mabi=%(VALUE)}" }, \ > + {"abi", "%{!mabi=*:" \ > + " %{!march=*:" \ > + " %{!mcpu=*:-mabi=%(VALUE)}" \ > + " %{mcpu=*:%:riscv_expand_abi_from_cpu(%* %(VALUE))}}" \ > + " %{march=*:%:riscv_expand_abi_from_arch(%*)}}" }, \ > {"isa_spec", "%{!misa-spec=*:-misa-spec=%(VALUE)}" }, \ > > #ifdef IN_LIBGCC2 > diff --git a/gcc/testsuite/gcc.target/riscv/mabi-1.c b/gcc/testsuite/gcc.target/riscv/mabi-1.c > new file mode 100644 > index 00000000000..83bc343f8d8 > --- /dev/null > +++ b/gcc/testsuite/gcc.target/riscv/mabi-1.c > @@ -0,0 +1,7 @@ > +/* { dg-do compile } */ > +/* { dg-skip-if "-mabi given" { *-*-* } { "-mabi=*" } } */ > +/* { dg-options "-march=rv32e" } */ > + > +#if !((__riscv_xlen == 32) && defined(__riscv_abi_rve)) > +#error "unexpected abi" > +#endif > diff --git a/gcc/testsuite/gcc.target/riscv/mabi-2.c b/gcc/testsuite/gcc.target/riscv/mabi-2.c > new file mode 100644 > index 00000000000..6a97c2ae2a3 > --- /dev/null > +++ b/gcc/testsuite/gcc.target/riscv/mabi-2.c > @@ -0,0 +1,7 @@ > +/* { dg-do compile } */ > +/* { dg-skip-if "-mabi given" { *-*-* } { "-mabi=*" } } */ > +/* { dg-options "-march=rv32ima" } */ > + > +#if !((__riscv_xlen == 32) && defined(__riscv_float_abi_soft)) > +#error "unexpected abi" > +#endif > diff --git a/gcc/testsuite/gcc.target/riscv/mabi-3.c b/gcc/testsuite/gcc.target/riscv/mabi-3.c > new file mode 100644 > index 00000000000..cef04313e19 > --- /dev/null > +++ b/gcc/testsuite/gcc.target/riscv/mabi-3.c > @@ -0,0 +1,7 @@ > +/* { dg-do compile } */ > +/* { dg-skip-if "-mabi given" { *-*-* } { "-mabi=*" } } */ > +/* { dg-options "-march=rv32imaf" } */ > + > +#if !((__riscv_xlen == 32) && defined(__riscv_float_abi_single)) > +#error "unexpected abi" > +#endif > diff --git a/gcc/testsuite/gcc.target/riscv/mabi-4.c b/gcc/testsuite/gcc.target/riscv/mabi-4.c > new file mode 100644 > index 00000000000..d62dcf6ed75 > --- /dev/null > +++ b/gcc/testsuite/gcc.target/riscv/mabi-4.c > @@ -0,0 +1,7 @@ > +/* { dg-do compile } */ > +/* { dg-skip-if "-mabi given" { *-*-* } { "-mabi=*" } } */ > +/* { dg-options "-march=rv32imafd" } */ > + > +#if !((__riscv_xlen == 32) && defined(__riscv_float_abi_double)) > +#error "unexpected abi" > +#endif > diff --git a/gcc/testsuite/gcc.target/riscv/mabi-5.c b/gcc/testsuite/gcc.target/riscv/mabi-5.c > new file mode 100644 > index 00000000000..000e5e282c2 > --- /dev/null > +++ b/gcc/testsuite/gcc.target/riscv/mabi-5.c > @@ -0,0 +1,7 @@ > +/* { dg-do compile } */ > +/* { dg-skip-if "-mabi given" { *-*-* } { "-mabi=*" } } */ > +/* { dg-options "-march=rv64ima" } */ > + > +#if !((__riscv_xlen == 64) && defined(__riscv_float_abi_soft)) > +#error "unexpected abi" > +#endif > diff --git a/gcc/testsuite/gcc.target/riscv/mabi-6.c b/gcc/testsuite/gcc.target/riscv/mabi-6.c > new file mode 100644 > index 00000000000..ed1458d4158 > --- /dev/null > +++ b/gcc/testsuite/gcc.target/riscv/mabi-6.c > @@ -0,0 +1,7 @@ > +/* { dg-do compile } */ > +/* { dg-skip-if "-mabi given" { *-*-* } { "-mabi=*" } } */ > +/* { dg-options "-march=rv64imaf" } */ > + > +#if !((__riscv_xlen == 64) && defined(__riscv_float_abi_single)) > +#error "unexpected abi" > +#endif > diff --git a/gcc/testsuite/gcc.target/riscv/mabi-7.c b/gcc/testsuite/gcc.target/riscv/mabi-7.c > new file mode 100644 > index 00000000000..675fe359cfd > --- /dev/null > +++ b/gcc/testsuite/gcc.target/riscv/mabi-7.c > @@ -0,0 +1,7 @@ > +/* { dg-do compile } */ > +/* { dg-skip-if "-mabi given" { *-*-* } { "-mabi=*" } } */ > +/* { dg-options "-march=rv64imafd" } */ > + > +#if !((__riscv_xlen == 64) && defined(__riscv_float_abi_double)) > +#error "unexpected abi" > +#endif > diff --git a/gcc/testsuite/gcc.target/riscv/mabi-8.c b/gcc/testsuite/gcc.target/riscv/mabi-8.c > new file mode 100644 > index 00000000000..8c7e08e4289 > --- /dev/null > +++ b/gcc/testsuite/gcc.target/riscv/mabi-8.c > @@ -0,0 +1,7 @@ > +/* { dg-do compile } */ > +/* { dg-skip-if "-mabi given" { *-*-* } { "-mabi=*" } } */ > +/* { dg-options "-mcpu=sifive-s21 -march=rv64imafd" } */ > + > +#if !((__riscv_xlen == 64) && defined(__riscv_float_abi_double)) > +#error "unexpected abi" > +#endif
I also prefer adding a -mabi=auto option rather than change existing behavior. On Wed, Jun 8, 2022 at 5:06 PM pc.wang via Gcc-patches <gcc-patches@gcc.gnu.org> wrote: > > Thanks for your opinion! I did these just because LLVM has already done the same thing and I wanted to make GCC with the same behavior of LLVM. The only difference is that LLVM has no handling for ilp32f and lp64f and I have sent a patch to do it (sees https://reviews.llvm.org/D125947). > As for RISC-V specs, there are some descriptions in https://github.com/riscv-non-isa/riscv-toolchain-conventions#specifying-the-target-isa-with--march: > > A target -march which includes floating point instructions implies a hardfloat calling convention, but can be overridden using the -mabi flag (see the next section). > But I think we can make it clearer. > ------------------------------------------------------------------ > Sender:Palmer Dabbelt <palmer@dabbelt.com> > Sent At:2022 Jun. 8 (Wed.) 02:45 > Recipient:gcc-patches <gcc-patches@gcc.gnu.org> > Cc:pc.wang <pc.wang@linux.alibaba.com> > Subject:Re: [PATCH] RISC-V: Compute default ABI from -mcpu or -march > > On Mon, 06 Jun 2022 19:51:20 PDT (-0700), gcc-patches@gcc.gnu.org wrote: > > If -mcpu or -march is specified and there is no -mabi, we will calculate > > default ABI from arch string provided by -march or defined in CPU info. > > IMO this is generally a good idea and we've talked about it before, but > just setting the ABI from the ISA isn't quite the right way to go. IIRC > we came up with something slightly more complicated, like picking the > closest supported multilib. That's probably more in line with what > users are asking for, which IIUC is sort of just "I don't care that much > about ABI, just make my stuff build". > > Whatever we do here, we should document in the RISC-V specs as we'll > want to make sure LLVM does the same thing. We probably also want some > sort of "-mabi=auto" argument, as it's always best to have an argument > that changes back to the no-argument behavior. > > > > > > gcc/ChangeLog: > > > > * common/config/riscv/riscv-common.cc (compute_default_abi): Implementation > > to calculate -mabi from arch string. > > (riscv_expand_abi_from_arch): New spec function to calcalute -mabi from arch > > string provided by -march option. > > (riscv_expand_abi_from_cpu): New spec function to find CPU info and calculate > > -mabi from arch string defined in CPU info. > > * config/riscv/riscv.h (EXTRA_SPEC_FUNCTIONS): Add above spec functions. > > (OPTION_DEFAULT_SPECS): Use new spec functions to calculate -mabi and -march > > has higher priority than -mcpu. > > > > gcc/testsuite/ChangeLog: > > > > * gcc.target/riscv/mabi-1.c: ilp32e test. > > * gcc.target/riscv/mabi-2.c: ilp32 test. > > * gcc.target/riscv/mabi-3.c: ilp32f test. > > * gcc.target/riscv/mabi-4.c: ilp32d test. > > * gcc.target/riscv/mabi-5.c: lp64 test. > > * gcc.target/riscv/mabi-6.c: lp64f test. > > * gcc.target/riscv/mabi-7.c: lp64d test. > > * gcc.target/riscv/mabi-8.c: -march override -mcpu. > > --- > > gcc/common/config/riscv/riscv-common.cc | 66 +++++++++++++++++++++++++ > > gcc/config/riscv/riscv.h | 15 ++++-- > > gcc/testsuite/gcc.target/riscv/mabi-1.c | 7 +++ > > gcc/testsuite/gcc.target/riscv/mabi-2.c | 7 +++ > > gcc/testsuite/gcc.target/riscv/mabi-3.c | 7 +++ > > gcc/testsuite/gcc.target/riscv/mabi-4.c | 7 +++ > > gcc/testsuite/gcc.target/riscv/mabi-5.c | 7 +++ > > gcc/testsuite/gcc.target/riscv/mabi-6.c | 7 +++ > > gcc/testsuite/gcc.target/riscv/mabi-7.c | 7 +++ > > gcc/testsuite/gcc.target/riscv/mabi-8.c | 7 +++ > > 10 files changed, 134 insertions(+), 3 deletions(-) > > create mode 100644 gcc/testsuite/gcc.target/riscv/mabi-1.c > > create mode 100644 gcc/testsuite/gcc.target/riscv/mabi-2.c > > create mode 100644 gcc/testsuite/gcc.target/riscv/mabi-3.c > > create mode 100644 gcc/testsuite/gcc.target/riscv/mabi-4.c > > create mode 100644 gcc/testsuite/gcc.target/riscv/mabi-5.c > > create mode 100644 gcc/testsuite/gcc.target/riscv/mabi-6.c > > create mode 100644 gcc/testsuite/gcc.target/riscv/mabi-7.c > > create mode 100644 gcc/testsuite/gcc.target/riscv/mabi-8.c > > > > diff --git a/gcc/common/config/riscv/riscv-common.cc b/gcc/common/config/riscv/riscv-common.cc > > index 0e5be2ce105..f8e40549d18 100644 > > --- a/gcc/common/config/riscv/riscv-common.cc > > +++ b/gcc/common/config/riscv/riscv-common.cc > > @@ -1266,6 +1266,72 @@ riscv_default_mtune (int argc, const char **argv) > > return default_mtune; > > } > > > > +/* Compute default -mabi option from arch string. */ > > + > > +static const char * > > +compute_default_abi (const char* arch_str) > > +{ > > + location_t loc = UNKNOWN_LOCATION; > > + > > + riscv_parse_arch_string (arch_str, NULL, loc); > > + > > + if (current_subset_list->xlen () == 64) > > + { > > + if (current_subset_list->lookup ("d", RISCV_DONT_CARE_VERSION, > > + RISCV_DONT_CARE_VERSION)) > > + return "lp64d"; > > + if (current_subset_list->lookup ("f", RISCV_DONT_CARE_VERSION, > > + RISCV_DONT_CARE_VERSION)) > > + return "lp64f"; > > + return "lp64"; > > + } > > + else > > + { > > + if (current_subset_list->lookup ("e", RISCV_DONT_CARE_VERSION, > > + RISCV_DONT_CARE_VERSION)) > > + return "ilp32e"; > > + if (current_subset_list->lookup ("d", RISCV_DONT_CARE_VERSION, > > + RISCV_DONT_CARE_VERSION)) > > + return "ilp32d"; > > + if (current_subset_list->lookup ("f", RISCV_DONT_CARE_VERSION, > > + RISCV_DONT_CARE_VERSION)) > > + return "ilp32f"; > > + return "ilp32"; > > + } > > +} > > + > > +/* Expand default -mabi option from -march option. */ > > + > > +const char * > > +riscv_expand_abi_from_arch (int argc, const char **argv) > > +{ > > + gcc_assert (argc == 1); > > + return xasprintf ("-mabi=%s", compute_default_abi (argv[0])); > > +} > > + > > +/* Expand default -mabi option from -mcpu option. */ > > + > > +const char * > > +riscv_expand_abi_from_cpu (int argc, const char **argv) > > +{ > > + gcc_assert (argc > 0 && argc <= 2); > > + const char *default_abi_str = NULL; > > + if (argc >= 2) > > + default_abi_str = argv[1]; > > + > > + const riscv_cpu_info *cpu = riscv_find_cpu (argv[0]); > > + > > + if (cpu == NULL) > > + { > > + if (default_abi_str == NULL) > > + return ""; > > + else > > + return xasprintf ("-mabi=%s", default_abi_str); > > + } > > + else > > + return xasprintf ("-mabi=%s", compute_default_abi (cpu->arch)); > > +} > > + > > /* Expand arch string with implied extensions from -mcpu option. */ > > > > const char * > > diff --git a/gcc/config/riscv/riscv.h b/gcc/config/riscv/riscv.h > > index 6f7f4d3fbdc..14cd695f37f 100644 > > --- a/gcc/config/riscv/riscv.h > > +++ b/gcc/config/riscv/riscv.h > > @@ -50,15 +50,20 @@ along with GCC; see the file COPYING3. If not see > > extern const char *riscv_expand_arch (int argc, const char **argv); > > extern const char *riscv_expand_arch_from_cpu (int argc, const char **argv); > > extern const char *riscv_default_mtune (int argc, const char **argv); > > +extern const char *riscv_expand_abi_from_arch (int argc, const char **argv); > > +extern const char *riscv_expand_abi_from_cpu (int argc, const char **argv); > > > > # define EXTRA_SPEC_FUNCTIONS \ > > { "riscv_expand_arch", riscv_expand_arch }, \ > > { "riscv_expand_arch_from_cpu", riscv_expand_arch_from_cpu }, \ > > - { "riscv_default_mtune", riscv_default_mtune }, > > + { "riscv_default_mtune", riscv_default_mtune }, \ > > + { "riscv_expand_abi_from_arch", riscv_expand_abi_from_arch }, \ > > + { "riscv_expand_abi_from_cpu", riscv_expand_abi_from_cpu }, > > > > /* Support for a compile-time default CPU, et cetera. The rules are: > > --with-arch is ignored if -march or -mcpu is specified. > > - --with-abi is ignored if -mabi is specified. > > + --with-abi is ignored if -mabi is specified. If -mcpu or -march is > > + specified, suitable -mabi will be selected from arch string. > > --with-tune is ignored if -mtune or -mcpu is specified. > > --with-isa-spec is ignored if -misa-spec is specified. > > > > @@ -70,7 +75,11 @@ extern const char *riscv_default_mtune (int argc, const char **argv); > > {"arch", "%{!march=*:" \ > > " %{!mcpu=*:-march=%(VALUE)}" \ > > " %{mcpu=*:%:riscv_expand_arch_from_cpu(%* %(VALUE))}}" }, \ > > - {"abi", "%{!mabi=*:-mabi=%(VALUE)}" }, \ > > + {"abi", "%{!mabi=*:" \ > > + " %{!march=*:" \ > > + " %{!mcpu=*:-mabi=%(VALUE)}" \ > > + " %{mcpu=*:%:riscv_expand_abi_from_cpu(%* %(VALUE))}}" \ > > + " %{march=*:%:riscv_expand_abi_from_arch(%*)}}" }, \ > > {"isa_spec", "%{!misa-spec=*:-misa-spec=%(VALUE)}" }, \ > > > > #ifdef IN_LIBGCC2 > > diff --git a/gcc/testsuite/gcc.target/riscv/mabi-1.c b/gcc/testsuite/gcc.target/riscv/mabi-1.c > > new file mode 100644 > > index 00000000000..83bc343f8d8 > > --- /dev/null > > +++ b/gcc/testsuite/gcc.target/riscv/mabi-1.c > > @@ -0,0 +1,7 @@ > > +/* { dg-do compile } */ > > +/* { dg-skip-if "-mabi given" { *-*-* } { "-mabi=*" } } */ > > +/* { dg-options "-march=rv32e" } */ > > + > > +#if !((__riscv_xlen == 32) && defined(__riscv_abi_rve)) > > +#error "unexpected abi" > > +#endif > > diff --git a/gcc/testsuite/gcc.target/riscv/mabi-2.c b/gcc/testsuite/gcc.target/riscv/mabi-2.c > > new file mode 100644 > > index 00000000000..6a97c2ae2a3 > > --- /dev/null > > +++ b/gcc/testsuite/gcc.target/riscv/mabi-2.c > > @@ -0,0 +1,7 @@ > > +/* { dg-do compile } */ > > +/* { dg-skip-if "-mabi given" { *-*-* } { "-mabi=*" } } */ > > +/* { dg-options "-march=rv32ima" } */ > > + > > +#if !((__riscv_xlen == 32) && defined(__riscv_float_abi_soft)) > > +#error "unexpected abi" > > +#endif > > diff --git a/gcc/testsuite/gcc.target/riscv/mabi-3.c b/gcc/testsuite/gcc.target/riscv/mabi-3.c > > new file mode 100644 > > index 00000000000..cef04313e19 > > --- /dev/null > > +++ b/gcc/testsuite/gcc.target/riscv/mabi-3.c > > @@ -0,0 +1,7 @@ > > +/* { dg-do compile } */ > > +/* { dg-skip-if "-mabi given" { *-*-* } { "-mabi=*" } } */ > > +/* { dg-options "-march=rv32imaf" } */ > > + > > +#if !((__riscv_xlen == 32) && defined(__riscv_float_abi_single)) > > +#error "unexpected abi" > > +#endif > > diff --git a/gcc/testsuite/gcc.target/riscv/mabi-4.c b/gcc/testsuite/gcc.target/riscv/mabi-4.c > > new file mode 100644 > > index 00000000000..d62dcf6ed75 > > --- /dev/null > > +++ b/gcc/testsuite/gcc.target/riscv/mabi-4.c > > @@ -0,0 +1,7 @@ > > +/* { dg-do compile } */ > > +/* { dg-skip-if "-mabi given" { *-*-* } { "-mabi=*" } } */ > > +/* { dg-options "-march=rv32imafd" } */ > > + > > +#if !((__riscv_xlen == 32) && defined(__riscv_float_abi_double)) > > +#error "unexpected abi" > > +#endif > > diff --git a/gcc/testsuite/gcc.target/riscv/mabi-5.c b/gcc/testsuite/gcc.target/riscv/mabi-5.c > > new file mode 100644 > > index 00000000000..000e5e282c2 > > --- /dev/null > > +++ b/gcc/testsuite/gcc.target/riscv/mabi-5.c > > @@ -0,0 +1,7 @@ > > +/* { dg-do compile } */ > > +/* { dg-skip-if "-mabi given" { *-*-* } { "-mabi=*" } } */ > > +/* { dg-options "-march=rv64ima" } */ > > + > > +#if !((__riscv_xlen == 64) && defined(__riscv_float_abi_soft)) > > +#error "unexpected abi" > > +#endif > > diff --git a/gcc/testsuite/gcc.target/riscv/mabi-6.c b/gcc/testsuite/gcc.target/riscv/mabi-6.c > > new file mode 100644 > > index 00000000000..ed1458d4158 > > --- /dev/null > > +++ b/gcc/testsuite/gcc.target/riscv/mabi-6.c > > @@ -0,0 +1,7 @@ > > +/* { dg-do compile } */ > > +/* { dg-skip-if "-mabi given" { *-*-* } { "-mabi=*" } } */ > > +/* { dg-options "-march=rv64imaf" } */ > > + > > +#if !((__riscv_xlen == 64) && defined(__riscv_float_abi_single)) > > +#error "unexpected abi" > > +#endif > > diff --git a/gcc/testsuite/gcc.target/riscv/mabi-7.c b/gcc/testsuite/gcc.target/riscv/mabi-7.c > > new file mode 100644 > > index 00000000000..675fe359cfd > > --- /dev/null > > +++ b/gcc/testsuite/gcc.target/riscv/mabi-7.c > > @@ -0,0 +1,7 @@ > > +/* { dg-do compile } */ > > +/* { dg-skip-if "-mabi given" { *-*-* } { "-mabi=*" } } */ > > +/* { dg-options "-march=rv64imafd" } */ > > + > > +#if !((__riscv_xlen == 64) && defined(__riscv_float_abi_double)) > > +#error "unexpected abi" > > +#endif > > diff --git a/gcc/testsuite/gcc.target/riscv/mabi-8.c b/gcc/testsuite/gcc.target/riscv/mabi-8.c > > new file mode 100644 > > index 00000000000..8c7e08e4289 > > --- /dev/null > > +++ b/gcc/testsuite/gcc.target/riscv/mabi-8.c > > @@ -0,0 +1,7 @@ > > +/* { dg-do compile } */ > > +/* { dg-skip-if "-mabi given" { *-*-* } { "-mabi=*" } } */ > > +/* { dg-options "-mcpu=sifive-s21 -march=rv64imafd" } */ > > + > > +#if !((__riscv_xlen == 64) && defined(__riscv_float_abi_double)) > > +#error "unexpected abi" > > +#endif
On Mon, Jun 6, 2022 at 7:53 PM wangpc via Gcc-patches <gcc-patches@gcc.gnu.org> wrote: > > If -mcpu or -march is specified and there is no -mabi, we will calculate > default ABI from arch string provided by -march or defined in CPU info. This is 100% wrong and goes against what all other targets do. All other targets have the following: a base ABI is selected and then add on to it via -march/-mcpu and only for the vector ABI (PowerPC backend used not even do that and required you to supply an option for the vector ABI but that might have changed in recent years). Basically the ABI should default to something (via either when configured with --with-abi= or just a default) and reject invalid combinations. That is if the ABI specified requires FPU and the arch/cpu does not have FPU reject it (same with 32bit vs 64bit). This is how other targets work in GCC and really it should be the same for RISC-V. Why make it any different and make it harder for people to convert from one target to another. Also I think the whole number of extensions of RISC-V makes life much harder, it would be easier if there was level of support like x86_64 and ARMv8/9 have moved to. It is past time to require these kind of levels really; otherwise you end up with so much fragmentation that RISC-V becomes the way of MIPS. Thanks, Andrew Pinski > > gcc/ChangeLog: > > * common/config/riscv/riscv-common.cc (compute_default_abi): Implementation > to calculate -mabi from arch string. > (riscv_expand_abi_from_arch): New spec function to calcalute -mabi from arch > string provided by -march option. > (riscv_expand_abi_from_cpu): New spec function to find CPU info and calculate > -mabi from arch string defined in CPU info. > * config/riscv/riscv.h (EXTRA_SPEC_FUNCTIONS): Add above spec functions. > (OPTION_DEFAULT_SPECS): Use new spec functions to calculate -mabi and -march > has higher priority than -mcpu. > > gcc/testsuite/ChangeLog: > > * gcc.target/riscv/mabi-1.c: ilp32e test. > * gcc.target/riscv/mabi-2.c: ilp32 test. > * gcc.target/riscv/mabi-3.c: ilp32f test. > * gcc.target/riscv/mabi-4.c: ilp32d test. > * gcc.target/riscv/mabi-5.c: lp64 test. > * gcc.target/riscv/mabi-6.c: lp64f test. > * gcc.target/riscv/mabi-7.c: lp64d test. > * gcc.target/riscv/mabi-8.c: -march override -mcpu. > --- > gcc/common/config/riscv/riscv-common.cc | 66 +++++++++++++++++++++++++ > gcc/config/riscv/riscv.h | 15 ++++-- > gcc/testsuite/gcc.target/riscv/mabi-1.c | 7 +++ > gcc/testsuite/gcc.target/riscv/mabi-2.c | 7 +++ > gcc/testsuite/gcc.target/riscv/mabi-3.c | 7 +++ > gcc/testsuite/gcc.target/riscv/mabi-4.c | 7 +++ > gcc/testsuite/gcc.target/riscv/mabi-5.c | 7 +++ > gcc/testsuite/gcc.target/riscv/mabi-6.c | 7 +++ > gcc/testsuite/gcc.target/riscv/mabi-7.c | 7 +++ > gcc/testsuite/gcc.target/riscv/mabi-8.c | 7 +++ > 10 files changed, 134 insertions(+), 3 deletions(-) > create mode 100644 gcc/testsuite/gcc.target/riscv/mabi-1.c > create mode 100644 gcc/testsuite/gcc.target/riscv/mabi-2.c > create mode 100644 gcc/testsuite/gcc.target/riscv/mabi-3.c > create mode 100644 gcc/testsuite/gcc.target/riscv/mabi-4.c > create mode 100644 gcc/testsuite/gcc.target/riscv/mabi-5.c > create mode 100644 gcc/testsuite/gcc.target/riscv/mabi-6.c > create mode 100644 gcc/testsuite/gcc.target/riscv/mabi-7.c > create mode 100644 gcc/testsuite/gcc.target/riscv/mabi-8.c > > diff --git a/gcc/common/config/riscv/riscv-common.cc b/gcc/common/config/riscv/riscv-common.cc > index 0e5be2ce105..f8e40549d18 100644 > --- a/gcc/common/config/riscv/riscv-common.cc > +++ b/gcc/common/config/riscv/riscv-common.cc > @@ -1266,6 +1266,72 @@ riscv_default_mtune (int argc, const char **argv) > return default_mtune; > } > > +/* Compute default -mabi option from arch string. */ > + > +static const char * > +compute_default_abi (const char* arch_str) > +{ > + location_t loc = UNKNOWN_LOCATION; > + > + riscv_parse_arch_string (arch_str, NULL, loc); > + > + if (current_subset_list->xlen () == 64) > + { > + if (current_subset_list->lookup ("d", RISCV_DONT_CARE_VERSION, > + RISCV_DONT_CARE_VERSION)) > + return "lp64d"; > + if (current_subset_list->lookup ("f", RISCV_DONT_CARE_VERSION, > + RISCV_DONT_CARE_VERSION)) > + return "lp64f"; > + return "lp64"; > + } > + else > + { > + if (current_subset_list->lookup ("e", RISCV_DONT_CARE_VERSION, > + RISCV_DONT_CARE_VERSION)) > + return "ilp32e"; > + if (current_subset_list->lookup ("d", RISCV_DONT_CARE_VERSION, > + RISCV_DONT_CARE_VERSION)) > + return "ilp32d"; > + if (current_subset_list->lookup ("f", RISCV_DONT_CARE_VERSION, > + RISCV_DONT_CARE_VERSION)) > + return "ilp32f"; > + return "ilp32"; > + } > +} > + > +/* Expand default -mabi option from -march option. */ > + > +const char * > +riscv_expand_abi_from_arch (int argc, const char **argv) > +{ > + gcc_assert (argc == 1); > + return xasprintf ("-mabi=%s", compute_default_abi (argv[0])); > +} > + > +/* Expand default -mabi option from -mcpu option. */ > + > +const char * > +riscv_expand_abi_from_cpu (int argc, const char **argv) > +{ > + gcc_assert (argc > 0 && argc <= 2); > + const char *default_abi_str = NULL; > + if (argc >= 2) > + default_abi_str = argv[1]; > + > + const riscv_cpu_info *cpu = riscv_find_cpu (argv[0]); > + > + if (cpu == NULL) > + { > + if (default_abi_str == NULL) > + return ""; > + else > + return xasprintf ("-mabi=%s", default_abi_str); > + } > + else > + return xasprintf ("-mabi=%s", compute_default_abi (cpu->arch)); > +} > + > /* Expand arch string with implied extensions from -mcpu option. */ > > const char * > diff --git a/gcc/config/riscv/riscv.h b/gcc/config/riscv/riscv.h > index 6f7f4d3fbdc..14cd695f37f 100644 > --- a/gcc/config/riscv/riscv.h > +++ b/gcc/config/riscv/riscv.h > @@ -50,15 +50,20 @@ along with GCC; see the file COPYING3. If not see > extern const char *riscv_expand_arch (int argc, const char **argv); > extern const char *riscv_expand_arch_from_cpu (int argc, const char **argv); > extern const char *riscv_default_mtune (int argc, const char **argv); > +extern const char *riscv_expand_abi_from_arch (int argc, const char **argv); > +extern const char *riscv_expand_abi_from_cpu (int argc, const char **argv); > > # define EXTRA_SPEC_FUNCTIONS \ > { "riscv_expand_arch", riscv_expand_arch }, \ > { "riscv_expand_arch_from_cpu", riscv_expand_arch_from_cpu }, \ > - { "riscv_default_mtune", riscv_default_mtune }, > + { "riscv_default_mtune", riscv_default_mtune }, \ > + { "riscv_expand_abi_from_arch", riscv_expand_abi_from_arch }, \ > + { "riscv_expand_abi_from_cpu", riscv_expand_abi_from_cpu }, > > /* Support for a compile-time default CPU, et cetera. The rules are: > --with-arch is ignored if -march or -mcpu is specified. > - --with-abi is ignored if -mabi is specified. > + --with-abi is ignored if -mabi is specified. If -mcpu or -march is > + specified, suitable -mabi will be selected from arch string. > --with-tune is ignored if -mtune or -mcpu is specified. > --with-isa-spec is ignored if -misa-spec is specified. > > @@ -70,7 +75,11 @@ extern const char *riscv_default_mtune (int argc, const char **argv); > {"arch", "%{!march=*:" \ > " %{!mcpu=*:-march=%(VALUE)}" \ > " %{mcpu=*:%:riscv_expand_arch_from_cpu(%* %(VALUE))}}" }, \ > - {"abi", "%{!mabi=*:-mabi=%(VALUE)}" }, \ > + {"abi", "%{!mabi=*:" \ > + " %{!march=*:" \ > + " %{!mcpu=*:-mabi=%(VALUE)}" \ > + " %{mcpu=*:%:riscv_expand_abi_from_cpu(%* %(VALUE))}}" \ > + " %{march=*:%:riscv_expand_abi_from_arch(%*)}}" }, \ > {"isa_spec", "%{!misa-spec=*:-misa-spec=%(VALUE)}" }, \ > > #ifdef IN_LIBGCC2 > diff --git a/gcc/testsuite/gcc.target/riscv/mabi-1.c b/gcc/testsuite/gcc.target/riscv/mabi-1.c > new file mode 100644 > index 00000000000..83bc343f8d8 > --- /dev/null > +++ b/gcc/testsuite/gcc.target/riscv/mabi-1.c > @@ -0,0 +1,7 @@ > +/* { dg-do compile } */ > +/* { dg-skip-if "-mabi given" { *-*-* } { "-mabi=*" } } */ > +/* { dg-options "-march=rv32e" } */ > + > +#if !((__riscv_xlen == 32) && defined(__riscv_abi_rve)) > +#error "unexpected abi" > +#endif > diff --git a/gcc/testsuite/gcc.target/riscv/mabi-2.c b/gcc/testsuite/gcc.target/riscv/mabi-2.c > new file mode 100644 > index 00000000000..6a97c2ae2a3 > --- /dev/null > +++ b/gcc/testsuite/gcc.target/riscv/mabi-2.c > @@ -0,0 +1,7 @@ > +/* { dg-do compile } */ > +/* { dg-skip-if "-mabi given" { *-*-* } { "-mabi=*" } } */ > +/* { dg-options "-march=rv32ima" } */ > + > +#if !((__riscv_xlen == 32) && defined(__riscv_float_abi_soft)) > +#error "unexpected abi" > +#endif > diff --git a/gcc/testsuite/gcc.target/riscv/mabi-3.c b/gcc/testsuite/gcc.target/riscv/mabi-3.c > new file mode 100644 > index 00000000000..cef04313e19 > --- /dev/null > +++ b/gcc/testsuite/gcc.target/riscv/mabi-3.c > @@ -0,0 +1,7 @@ > +/* { dg-do compile } */ > +/* { dg-skip-if "-mabi given" { *-*-* } { "-mabi=*" } } */ > +/* { dg-options "-march=rv32imaf" } */ > + > +#if !((__riscv_xlen == 32) && defined(__riscv_float_abi_single)) > +#error "unexpected abi" > +#endif > diff --git a/gcc/testsuite/gcc.target/riscv/mabi-4.c b/gcc/testsuite/gcc.target/riscv/mabi-4.c > new file mode 100644 > index 00000000000..d62dcf6ed75 > --- /dev/null > +++ b/gcc/testsuite/gcc.target/riscv/mabi-4.c > @@ -0,0 +1,7 @@ > +/* { dg-do compile } */ > +/* { dg-skip-if "-mabi given" { *-*-* } { "-mabi=*" } } */ > +/* { dg-options "-march=rv32imafd" } */ > + > +#if !((__riscv_xlen == 32) && defined(__riscv_float_abi_double)) > +#error "unexpected abi" > +#endif > diff --git a/gcc/testsuite/gcc.target/riscv/mabi-5.c b/gcc/testsuite/gcc.target/riscv/mabi-5.c > new file mode 100644 > index 00000000000..000e5e282c2 > --- /dev/null > +++ b/gcc/testsuite/gcc.target/riscv/mabi-5.c > @@ -0,0 +1,7 @@ > +/* { dg-do compile } */ > +/* { dg-skip-if "-mabi given" { *-*-* } { "-mabi=*" } } */ > +/* { dg-options "-march=rv64ima" } */ > + > +#if !((__riscv_xlen == 64) && defined(__riscv_float_abi_soft)) > +#error "unexpected abi" > +#endif > diff --git a/gcc/testsuite/gcc.target/riscv/mabi-6.c b/gcc/testsuite/gcc.target/riscv/mabi-6.c > new file mode 100644 > index 00000000000..ed1458d4158 > --- /dev/null > +++ b/gcc/testsuite/gcc.target/riscv/mabi-6.c > @@ -0,0 +1,7 @@ > +/* { dg-do compile } */ > +/* { dg-skip-if "-mabi given" { *-*-* } { "-mabi=*" } } */ > +/* { dg-options "-march=rv64imaf" } */ > + > +#if !((__riscv_xlen == 64) && defined(__riscv_float_abi_single)) > +#error "unexpected abi" > +#endif > diff --git a/gcc/testsuite/gcc.target/riscv/mabi-7.c b/gcc/testsuite/gcc.target/riscv/mabi-7.c > new file mode 100644 > index 00000000000..675fe359cfd > --- /dev/null > +++ b/gcc/testsuite/gcc.target/riscv/mabi-7.c > @@ -0,0 +1,7 @@ > +/* { dg-do compile } */ > +/* { dg-skip-if "-mabi given" { *-*-* } { "-mabi=*" } } */ > +/* { dg-options "-march=rv64imafd" } */ > + > +#if !((__riscv_xlen == 64) && defined(__riscv_float_abi_double)) > +#error "unexpected abi" > +#endif > diff --git a/gcc/testsuite/gcc.target/riscv/mabi-8.c b/gcc/testsuite/gcc.target/riscv/mabi-8.c > new file mode 100644 > index 00000000000..8c7e08e4289 > --- /dev/null > +++ b/gcc/testsuite/gcc.target/riscv/mabi-8.c > @@ -0,0 +1,7 @@ > +/* { dg-do compile } */ > +/* { dg-skip-if "-mabi given" { *-*-* } { "-mabi=*" } } */ > +/* { dg-options "-mcpu=sifive-s21 -march=rv64imafd" } */ > + > +#if !((__riscv_xlen == 64) && defined(__riscv_float_abi_double)) > +#error "unexpected abi" > +#endif > -- > 2.34.1.windows.1 >
diff --git a/gcc/common/config/riscv/riscv-common.cc b/gcc/common/config/riscv/riscv-common.cc index 0e5be2ce105..f8e40549d18 100644 --- a/gcc/common/config/riscv/riscv-common.cc +++ b/gcc/common/config/riscv/riscv-common.cc @@ -1266,6 +1266,72 @@ riscv_default_mtune (int argc, const char **argv) return default_mtune; } +/* Compute default -mabi option from arch string. */ + +static const char * +compute_default_abi (const char* arch_str) +{ + location_t loc = UNKNOWN_LOCATION; + + riscv_parse_arch_string (arch_str, NULL, loc); + + if (current_subset_list->xlen () == 64) + { + if (current_subset_list->lookup ("d", RISCV_DONT_CARE_VERSION, + RISCV_DONT_CARE_VERSION)) + return "lp64d"; + if (current_subset_list->lookup ("f", RISCV_DONT_CARE_VERSION, + RISCV_DONT_CARE_VERSION)) + return "lp64f"; + return "lp64"; + } + else + { + if (current_subset_list->lookup ("e", RISCV_DONT_CARE_VERSION, + RISCV_DONT_CARE_VERSION)) + return "ilp32e"; + if (current_subset_list->lookup ("d", RISCV_DONT_CARE_VERSION, + RISCV_DONT_CARE_VERSION)) + return "ilp32d"; + if (current_subset_list->lookup ("f", RISCV_DONT_CARE_VERSION, + RISCV_DONT_CARE_VERSION)) + return "ilp32f"; + return "ilp32"; + } +} + +/* Expand default -mabi option from -march option. */ + +const char * +riscv_expand_abi_from_arch (int argc, const char **argv) +{ + gcc_assert (argc == 1); + return xasprintf ("-mabi=%s", compute_default_abi (argv[0])); +} + +/* Expand default -mabi option from -mcpu option. */ + +const char * +riscv_expand_abi_from_cpu (int argc, const char **argv) +{ + gcc_assert (argc > 0 && argc <= 2); + const char *default_abi_str = NULL; + if (argc >= 2) + default_abi_str = argv[1]; + + const riscv_cpu_info *cpu = riscv_find_cpu (argv[0]); + + if (cpu == NULL) + { + if (default_abi_str == NULL) + return ""; + else + return xasprintf ("-mabi=%s", default_abi_str); + } + else + return xasprintf ("-mabi=%s", compute_default_abi (cpu->arch)); +} + /* Expand arch string with implied extensions from -mcpu option. */ const char * diff --git a/gcc/config/riscv/riscv.h b/gcc/config/riscv/riscv.h index 6f7f4d3fbdc..14cd695f37f 100644 --- a/gcc/config/riscv/riscv.h +++ b/gcc/config/riscv/riscv.h @@ -50,15 +50,20 @@ along with GCC; see the file COPYING3. If not see extern const char *riscv_expand_arch (int argc, const char **argv); extern const char *riscv_expand_arch_from_cpu (int argc, const char **argv); extern const char *riscv_default_mtune (int argc, const char **argv); +extern const char *riscv_expand_abi_from_arch (int argc, const char **argv); +extern const char *riscv_expand_abi_from_cpu (int argc, const char **argv); # define EXTRA_SPEC_FUNCTIONS \ { "riscv_expand_arch", riscv_expand_arch }, \ { "riscv_expand_arch_from_cpu", riscv_expand_arch_from_cpu }, \ - { "riscv_default_mtune", riscv_default_mtune }, + { "riscv_default_mtune", riscv_default_mtune }, \ + { "riscv_expand_abi_from_arch", riscv_expand_abi_from_arch }, \ + { "riscv_expand_abi_from_cpu", riscv_expand_abi_from_cpu }, /* Support for a compile-time default CPU, et cetera. The rules are: --with-arch is ignored if -march or -mcpu is specified. - --with-abi is ignored if -mabi is specified. + --with-abi is ignored if -mabi is specified. If -mcpu or -march is + specified, suitable -mabi will be selected from arch string. --with-tune is ignored if -mtune or -mcpu is specified. --with-isa-spec is ignored if -misa-spec is specified. @@ -70,7 +75,11 @@ extern const char *riscv_default_mtune (int argc, const char **argv); {"arch", "%{!march=*:" \ " %{!mcpu=*:-march=%(VALUE)}" \ " %{mcpu=*:%:riscv_expand_arch_from_cpu(%* %(VALUE))}}" }, \ - {"abi", "%{!mabi=*:-mabi=%(VALUE)}" }, \ + {"abi", "%{!mabi=*:" \ + " %{!march=*:" \ + " %{!mcpu=*:-mabi=%(VALUE)}" \ + " %{mcpu=*:%:riscv_expand_abi_from_cpu(%* %(VALUE))}}" \ + " %{march=*:%:riscv_expand_abi_from_arch(%*)}}" }, \ {"isa_spec", "%{!misa-spec=*:-misa-spec=%(VALUE)}" }, \ #ifdef IN_LIBGCC2 diff --git a/gcc/testsuite/gcc.target/riscv/mabi-1.c b/gcc/testsuite/gcc.target/riscv/mabi-1.c new file mode 100644 index 00000000000..83bc343f8d8 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/mabi-1.c @@ -0,0 +1,7 @@ +/* { dg-do compile } */ +/* { dg-skip-if "-mabi given" { *-*-* } { "-mabi=*" } } */ +/* { dg-options "-march=rv32e" } */ + +#if !((__riscv_xlen == 32) && defined(__riscv_abi_rve)) +#error "unexpected abi" +#endif diff --git a/gcc/testsuite/gcc.target/riscv/mabi-2.c b/gcc/testsuite/gcc.target/riscv/mabi-2.c new file mode 100644 index 00000000000..6a97c2ae2a3 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/mabi-2.c @@ -0,0 +1,7 @@ +/* { dg-do compile } */ +/* { dg-skip-if "-mabi given" { *-*-* } { "-mabi=*" } } */ +/* { dg-options "-march=rv32ima" } */ + +#if !((__riscv_xlen == 32) && defined(__riscv_float_abi_soft)) +#error "unexpected abi" +#endif diff --git a/gcc/testsuite/gcc.target/riscv/mabi-3.c b/gcc/testsuite/gcc.target/riscv/mabi-3.c new file mode 100644 index 00000000000..cef04313e19 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/mabi-3.c @@ -0,0 +1,7 @@ +/* { dg-do compile } */ +/* { dg-skip-if "-mabi given" { *-*-* } { "-mabi=*" } } */ +/* { dg-options "-march=rv32imaf" } */ + +#if !((__riscv_xlen == 32) && defined(__riscv_float_abi_single)) +#error "unexpected abi" +#endif diff --git a/gcc/testsuite/gcc.target/riscv/mabi-4.c b/gcc/testsuite/gcc.target/riscv/mabi-4.c new file mode 100644 index 00000000000..d62dcf6ed75 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/mabi-4.c @@ -0,0 +1,7 @@ +/* { dg-do compile } */ +/* { dg-skip-if "-mabi given" { *-*-* } { "-mabi=*" } } */ +/* { dg-options "-march=rv32imafd" } */ + +#if !((__riscv_xlen == 32) && defined(__riscv_float_abi_double)) +#error "unexpected abi" +#endif diff --git a/gcc/testsuite/gcc.target/riscv/mabi-5.c b/gcc/testsuite/gcc.target/riscv/mabi-5.c new file mode 100644 index 00000000000..000e5e282c2 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/mabi-5.c @@ -0,0 +1,7 @@ +/* { dg-do compile } */ +/* { dg-skip-if "-mabi given" { *-*-* } { "-mabi=*" } } */ +/* { dg-options "-march=rv64ima" } */ + +#if !((__riscv_xlen == 64) && defined(__riscv_float_abi_soft)) +#error "unexpected abi" +#endif diff --git a/gcc/testsuite/gcc.target/riscv/mabi-6.c b/gcc/testsuite/gcc.target/riscv/mabi-6.c new file mode 100644 index 00000000000..ed1458d4158 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/mabi-6.c @@ -0,0 +1,7 @@ +/* { dg-do compile } */ +/* { dg-skip-if "-mabi given" { *-*-* } { "-mabi=*" } } */ +/* { dg-options "-march=rv64imaf" } */ + +#if !((__riscv_xlen == 64) && defined(__riscv_float_abi_single)) +#error "unexpected abi" +#endif diff --git a/gcc/testsuite/gcc.target/riscv/mabi-7.c b/gcc/testsuite/gcc.target/riscv/mabi-7.c new file mode 100644 index 00000000000..675fe359cfd --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/mabi-7.c @@ -0,0 +1,7 @@ +/* { dg-do compile } */ +/* { dg-skip-if "-mabi given" { *-*-* } { "-mabi=*" } } */ +/* { dg-options "-march=rv64imafd" } */ + +#if !((__riscv_xlen == 64) && defined(__riscv_float_abi_double)) +#error "unexpected abi" +#endif diff --git a/gcc/testsuite/gcc.target/riscv/mabi-8.c b/gcc/testsuite/gcc.target/riscv/mabi-8.c new file mode 100644 index 00000000000..8c7e08e4289 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/mabi-8.c @@ -0,0 +1,7 @@ +/* { dg-do compile } */ +/* { dg-skip-if "-mabi given" { *-*-* } { "-mabi=*" } } */ +/* { dg-options "-mcpu=sifive-s21 -march=rv64imafd" } */ + +#if !((__riscv_xlen == 64) && defined(__riscv_float_abi_double)) +#error "unexpected abi" +#endif