From patchwork Fri Apr 10 09:20:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kito Cheng X-Patchwork-Id: 1268998 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=ZSc9Ucby; 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 48zCD46TrYz9sSX for ; Fri, 10 Apr 2020 19:20:36 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2E1CA385DC10; Fri, 10 Apr 2020 09:20:34 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pg1-x535.google.com (mail-pg1-x535.google.com [IPv6:2607:f8b0:4864:20::535]) by sourceware.org (Postfix) with ESMTPS id 8099A385B835 for ; Fri, 10 Apr 2020 09:20:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 8099A385B835 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-x535.google.com with SMTP id n13so750656pgp.11 for ; Fri, 10 Apr 2020 02:20:30 -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:mime-version :content-transfer-encoding; bh=YVeWxGZ5/wg7UHb9nXjTBEKkMHxh6wH3SPiDdvOgsbE=; b=ZSc9UcbyTKTRkIMyh3YOksGv8otBmS49BhpKS4Juc7xjdK9eP97g4ZPBUixuF8qKvz Fb7bnq8iQlzK4LPrNok8/jrmhAwx4FGufGFmFbuIULbDjyiHMA+Wcumqw4YYYKrqVCeN bdw4EIhPQIbN9tj7iw3QVbrrVID9sMN3beke0dJo6iPZ7tweOhRlQY58zomSyAhSPfn5 zOWl8GJFO8vNd8J2aVCkIBf72N1xdB236ggUsdSr2XcTkPMFFI6MbK15vyZy353mkmaa KluI7QcbGyZPCknP3V0G+m6mgoNDC5NcblUT+Ap2AlEyeYVoDiDkUwjJ6G3bO+YuwOwG WXKw== 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=YVeWxGZ5/wg7UHb9nXjTBEKkMHxh6wH3SPiDdvOgsbE=; b=K3pSSoPZFTRdNqVbjkxE8XjyPOI3ja2h5io8KEIFOplvEesbO1N2P4lGM7IrbFevnm kUod7ow97xWtr6umZJHvMcWkaaZ2UxNW1bZygdvXFv5vbciT3ibbz03EvtMW5yiYt20q IPNFV1MyCHCGGXcwOvJzgGj4l0F0hIXWX+KPUx4GO9zZECydQ2/zOPJ2NYkfcMw0p0UP Wqw2EjXJN5d2wnbJ3Obvt0edGN0cM5zEsbqoen0ZA4qmosunGfy3jvo8wMd+zTEDB1aE CsTpO3KrgLBPEQZcDmaY60ufhIalaeg+SlPMB0rnOBN44IBaadVioojssjLlLgkI9hlm i0KA== X-Gm-Message-State: AGi0Pub3tSp9q1NRPw7CCQ8X+HqL9Np3A9ujaGa/BIc3HxzI1MyjuHC+ X1Y2XPrdPIGzKZFkX2F91X/w5KoqkI0= X-Google-Smtp-Source: APiQypJQxP+ReB9wR/+N/pak+kuauN+R76637kMLbbNwAgwdaFxUerXQgW1DfQ4OarDOQC5XKQNYfA== X-Received: by 2002:aa7:9a4b:: with SMTP id x11mr4103840pfj.73.1586510429058; Fri, 10 Apr 2020 02:20:29 -0700 (PDT) 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 a1sm1265277pfl.188.2020.04.10.02.20.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Apr 2020 02:20:28 -0700 (PDT) From: Kito Cheng To: gcc-patches@gcc.gnu.org, kito.cheng@gmail.com, jimw@sifive.com Subject: [PATCH v2 1/2] RISC-V: Update march parser Date: Fri, 10 Apr 2020 17:20:18 +0800 Message-Id: <20200410092019.98521-1-kito.cheng@sifive.com> X-Mailer: git-send-email 2.26.0 MIME-Version: 1.0 X-Spam-Status: No, score=-26.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, 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" - The arch string rule has changed in latest spec, it introduced new multi-letter extension prefix with 'h' and 'z', and drop `sx`. also adjust parsing order for 's' and 'x'. gcc/ChangeLog * riscv-common.c (parse_sv_or_non_std_ext): Rename to parse_multiletter_ext. (parse_multiletter_ext): Add parsing `h` and `z`, drop `sx`, adjust parsing order for 's' and 'x'. gcc/testsuite/ChangeLog * gcc.target/riscv/arch-3.c: Adjust option. * gcc.target/riscv/arch-5.c: New. * gcc.target/riscv/attribute-9.c: Adjust option and test condition. --- gcc/common/config/riscv/riscv-common.c | 40 ++++++++++---------- gcc/testsuite/gcc.target/riscv/arch-3.c | 2 +- gcc/testsuite/gcc.target/riscv/arch-5.c | 5 +++ gcc/testsuite/gcc.target/riscv/attribute-9.c | 4 +- 4 files changed, 28 insertions(+), 23 deletions(-) create mode 100644 gcc/testsuite/gcc.target/riscv/arch-5.c diff --git a/gcc/common/config/riscv/riscv-common.c b/gcc/common/config/riscv/riscv-common.c index d2ef83b1971..a2e8d7003cc 100644 --- a/gcc/common/config/riscv/riscv-common.c +++ b/gcc/common/config/riscv/riscv-common.c @@ -70,8 +70,8 @@ private: const char *parse_std_ext (const char *); - const char *parse_sv_or_non_std_ext (const char *, const char *, - const char *); + const char *parse_multiletter_ext (const char *, const char *, + const char *); public: ~riscv_subset_list (); @@ -357,7 +357,7 @@ riscv_subset_list::parse_std_ext (const char *p) { char subset[2] = {0, 0}; - if (*p == 'x' || *p == 's') + if (*p == 'x' || *p == 's' || *p == 'h' || *p == 'z') break; if (*p == '_') @@ -399,20 +399,20 @@ riscv_subset_list::parse_std_ext (const char *p) return p; } -/* Parsing function for non-standard and supervisor extensions. +/* Parsing function for multi-letter extensions. Return Value: Points to the end of extensions. Arguments: `p`: Current parsing position. - `ext_type`: What kind of extensions, 'x', 's' or 'sx'. + `ext_type`: What kind of extensions, 's', 'h', 'z' or 'x'. `ext_type_str`: Full name for kind of extension. */ const char * -riscv_subset_list::parse_sv_or_non_std_ext (const char *p, - const char *ext_type, - const char *ext_type_str) +riscv_subset_list::parse_multiletter_ext (const char *p, + const char *ext_type, + const char *ext_type_str) { unsigned major_version = 0; unsigned minor_version = 0; @@ -429,11 +429,6 @@ riscv_subset_list::parse_sv_or_non_std_ext (const char *p, if (strncmp (p, ext_type, ext_type_len) != 0) break; - /* It's non-standard supervisor extension if it prefix with sx. */ - if ((ext_type[0] == 's') && (ext_type_len == 1) - && (*(p + 1) == 'x')) - break; - char *subset = xstrdup (p); char *q = subset; const char *end_of_version; @@ -494,21 +489,26 @@ riscv_subset_list::parse (const char *arch, location_t loc) if (p == NULL) goto fail; - /* Parsing non-standard extension. */ - p = subset_list->parse_sv_or_non_std_ext (p, "x", "non-standard extension"); + /* Parsing supervisor extension. */ + p = subset_list->parse_multiletter_ext (p, "s", "supervisor extension"); if (p == NULL) goto fail; - /* Parsing supervisor extension. */ - p = subset_list->parse_sv_or_non_std_ext (p, "s", "supervisor extension"); + /* Parsing hypervisor extension. */ + p = subset_list->parse_multiletter_ext (p, "h", "hypervisor extension"); if (p == NULL) goto fail; - /* Parsing non-standard supervisor extension. */ - p = subset_list->parse_sv_or_non_std_ext - (p, "sx", "non-standard supervisor extension"); + /* Parsing sub-extensions. */ + p = subset_list->parse_multiletter_ext (p, "z", "sub-extension"); + + if (p == NULL) + goto fail; + + /* Parsing non-standard extension. */ + p = subset_list->parse_multiletter_ext (p, "x", "non-standard extension"); if (p == NULL) goto fail; diff --git a/gcc/testsuite/gcc.target/riscv/arch-3.c b/gcc/testsuite/gcc.target/riscv/arch-3.c index 6aaa0a650fa..124699405c5 100644 --- a/gcc/testsuite/gcc.target/riscv/arch-3.c +++ b/gcc/testsuite/gcc.target/riscv/arch-3.c @@ -1,5 +1,5 @@ /* { dg-do compile } */ -/* { dg-options "-O -march=rv32ixbar_sabc_sxfoo -mabi=ilp32" } */ +/* { dg-options "-O -march=rv32isabc_xbar -mabi=ilp32" } */ int foo() { } diff --git a/gcc/testsuite/gcc.target/riscv/arch-5.c b/gcc/testsuite/gcc.target/riscv/arch-5.c new file mode 100644 index 00000000000..b0a1bd445fe --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/arch-5.c @@ -0,0 +1,5 @@ +/* { dg-do compile } */ +/* { dg-options "-O -march=rv32isabc_hghi_zfoo_xbar -mabi=ilp32" } */ +int foo() +{ +} diff --git a/gcc/testsuite/gcc.target/riscv/attribute-9.c b/gcc/testsuite/gcc.target/riscv/attribute-9.c index 670944a1cbe..bc4db0eb647 100644 --- a/gcc/testsuite/gcc.target/riscv/attribute-9.c +++ b/gcc/testsuite/gcc.target/riscv/attribute-9.c @@ -1,6 +1,6 @@ /* { dg-do compile } */ -/* { dg-options "-O -mriscv-attribute -march=rv32i2p0xbar_sabc_sxfoo -mabi=ilp32e" } */ +/* { dg-options "-O -mriscv-attribute -march=rv32i2p0sabc_xbar -mabi=ilp32e" } */ int foo() { } -/* { dg-final { scan-assembler ".attribute arch, \"rv32i2p0_xbar2p0_sabc2p0_sxfoo2p0\"" } } */ +/* { dg-final { scan-assembler ".attribute arch, \"rv32i2p0_sabc2p0_xbar2p0\"" } } */ From patchwork Fri Apr 10 09:20: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: 1268999 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=Y5iV6aqB; 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 48zCD84zkpz9sSX for ; Fri, 10 Apr 2020 19:20:40 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 92827385DC20; Fri, 10 Apr 2020 09:20:35 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pg1-x541.google.com (mail-pg1-x541.google.com [IPv6:2607:f8b0:4864:20::541]) by sourceware.org (Postfix) with ESMTPS id D5E7A385B835 for ; Fri, 10 Apr 2020 09:20:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org D5E7A385B835 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-x541.google.com with SMTP id n13so750707pgp.11 for ; Fri, 10 Apr 2020 02:20:32 -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=HZVe4xlGVPSPIg5V5/x0F4R0ZaPco2wrbPB8/4blznc=; b=Y5iV6aqBEli8aVv6pfmPlxnkdg8LSDN40+aCGhAlERvadZnEipeczBJWLJfTefBk+K QFV3Be1Jyk6PZhdXG3vCkgXB0wthUE75/nk1SET4Isa3z8Xqwiv2n3wl6mVFA+3TWGT9 nIkG5T9Qn9mR/5lUXuUpAWSxWDUY4g7cVF1+kOfu4cm33UdKAkTmlE7mzah+Halc2o+M xiONf365UxC42VaeP7hQKligifDdOLZSGmC/Z/5eXzZKQzw9wJaBUstsqFIwHBW543ZD MCOWnunkDkp8RNu15KlBo3CxQ0E7LIk6mHY7M94W3I2+Kz7+fX6nSQrkQuD3g3I2Lmig cnkQ== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=HZVe4xlGVPSPIg5V5/x0F4R0ZaPco2wrbPB8/4blznc=; b=AzBnurigW/2RGAiIiEn9QsE0OJhEQ8SoG8GtBbZBqH6th1eXfK9LLBkrWbsDXX7q44 t3R/ako2YexRGp8CKP4TWliFzjwf6zUEUthBSPot8+cEI2pjYVrVXCr62pXD3r5Gy8jl 45oO23u7DeaoAL728GsxgZLHOcTlgzNGBqEn0n8Ordiiu0PaBjmTgVZcQlRKOEE/AQPn /kqzhlHNZu671foxV3EUIYkk4425/2KKt+XmH/3L7efUBsQNX/uAsQ44Qjunwk8o4ySp rqRffwUlITcra2mBw8RUlPBcNGlHDy1czBLbiMMHVMyUZSZ5jB591tBB35YnvkSQOuPR uD3A== X-Gm-Message-State: AGi0PubEdFTlAKkSgwGvdwlKQmqrIrpi68CbUyqg2ZhdBYpmtKz2FWzc CFrMc/kVk1YbZ8v6ZiC144tuTQsPWNo= X-Google-Smtp-Source: APiQypK/VmlA2qV9h4Z9G1E3Z43nFuOpzUsNWD283coJtoHsLIA7OLDMyq/RF9H72rR4/XOxufdQ2g== X-Received: by 2002:a63:9a11:: with SMTP id o17mr3561079pge.234.1586510431527; Fri, 10 Apr 2020 02:20:31 -0700 (PDT) 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 a1sm1265277pfl.188.2020.04.10.02.20.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Apr 2020 02:20:31 -0700 (PDT) From: Kito Cheng To: gcc-patches@gcc.gnu.org, kito.cheng@gmail.com, jimw@sifive.com Subject: [PATCH v2 2/2] RISC-V: Handle implied extension for -march parser. Date: Fri, 10 Apr 2020 17:20:19 +0800 Message-Id: <20200410092019.98521-2-kito.cheng@sifive.com> X-Mailer: git-send-email 2.26.0 In-Reply-To: <20200410092019.98521-1-kito.cheng@sifive.com> References: <20200410092019.98521-1-kito.cheng@sifive.com> MIME-Version: 1.0 X-Spam-Status: No, score=-26.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, 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" - Implied rule are introduced into latest RISC-V ISA spec. - Only implemented D implied F-extension. Zicsr and Zifence are not implement yet, so the rule not included in this patch. - Pass preprocessed arch string to arch. - Verified with binutils 2.30 and 2.34. gcc/ChangeLog * common/config/riscv/riscv-common.c (riscv_implied_info_t): New. (riscv_implied_info): New. (riscv_subset_list): Add handle_implied_ext. (riscv_subset_list::to_string): New parameter version_p to control output format. (riscv_subset_list::handle_implied_ext): New. (riscv_subset_list::parse_std_ext): Call handle_implied_ext. (riscv_arch_str): New parameter version_p to control output format. (riscv_expand_arch): New. * config/riscv/riscv-protos.h (riscv_arch_str): New parameter, version_p. * config/riscv/riscv.h (riscv_expand_arch): New, (EXTRA_SPEC_FUNCTIONS): Define. (ASM_SPEC): Transform -march= via riscv_expand_arch. gcc/testsuite/ChangeLog * gcc.target/riscv/arch-6.c: New. * gcc.target/riscv/attribute-11.c: New. * gcc.target/riscv/attribute-12.c: New. --- gcc/common/config/riscv/riscv-common.c | 85 ++++++++++++++++--- gcc/config/riscv/riscv-protos.h | 2 +- gcc/config/riscv/riscv.h | 7 +- gcc/testsuite/gcc.target/riscv/arch-6.c | 5 ++ gcc/testsuite/gcc.target/riscv/attribute-11.c | 6 ++ gcc/testsuite/gcc.target/riscv/attribute-12.c | 6 ++ 6 files changed, 99 insertions(+), 12 deletions(-) create mode 100644 gcc/testsuite/gcc.target/riscv/arch-6.c create mode 100644 gcc/testsuite/gcc.target/riscv/attribute-11.c create mode 100644 gcc/testsuite/gcc.target/riscv/attribute-12.c diff --git a/gcc/common/config/riscv/riscv-common.c b/gcc/common/config/riscv/riscv-common.c index a2e8d7003cc..2df93460165 100644 --- a/gcc/common/config/riscv/riscv-common.c +++ b/gcc/common/config/riscv/riscv-common.c @@ -44,6 +44,20 @@ struct riscv_subset_t struct riscv_subset_t *next; }; +/* Type for implied ISA info. */ +struct riscv_implied_info_t +{ + const char *ext; + const char *implied_ext; +}; + +/* Implied ISA info, must end with NULL sentinel. */ +riscv_implied_info_t riscv_implied_info[] = +{ + {"d", "f"}, + {NULL, NULL} +}; + /* Subset list. */ class riscv_subset_list { @@ -73,6 +87,8 @@ private: const char *parse_multiletter_ext (const char *, const char *, const char *); + void handle_implied_ext (const char *, int, int); + public: ~riscv_subset_list (); @@ -82,7 +98,7 @@ public: int major_version = RISCV_DONT_CARE_VERSION, int minor_version = RISCV_DONT_CARE_VERSION) const; - std::string to_string () const; + std::string to_string (bool) const; unsigned xlen() const {return m_xlen;}; @@ -140,10 +156,11 @@ riscv_subset_list::add (const char *subset, int major_version, m_tail = s; } -/* Convert subset info to string with explicit version info. */ +/* Convert subset info to string with explicit version info, + VERSION_P to determine append version info or not. */ std::string -riscv_subset_list::to_string () const +riscv_subset_list::to_string (bool version_p) const { std::ostringstream oss; oss << "rv" << m_xlen; @@ -153,14 +170,20 @@ riscv_subset_list::to_string () const while (subset != NULL) { - if (!first) + /* For !version_p, we only separate extension with underline for + multi-letter extension. */ + if (!first && + (version_p || subset->name.length() > 1)) oss << '_'; first = false; - oss << subset->name - << subset->major_version - << 'p' - << subset->minor_version; + oss << subset->name; + + if (version_p) + oss << subset->major_version + << 'p' + << subset->minor_version; + subset = subset->next; } @@ -394,11 +417,38 @@ riscv_subset_list::parse_std_ext (const char *p) subset[0] = std_ext; + handle_implied_ext (subset, major_version, minor_version); + add (subset, major_version, minor_version); } return p; } + +/* Check any implied extensions for EXT with version + MAJOR_VERSION.MINOR_VERSION. */ +void +riscv_subset_list::handle_implied_ext (const char *ext, + int major_version, + int minor_version) +{ + riscv_implied_info_t *implied_info; + for (implied_info = &riscv_implied_info[0]; + implied_info->ext; + ++implied_info) + { + if (strcmp (ext, implied_info->ext) != 0) + continue; + + /* Skip if implied extension already present. */ + if (lookup (implied_info->implied_ext)) + continue; + + /* TODO: Implied extension might use different version. */ + add (implied_info->implied_ext, major_version, minor_version); + } +} + /* Parsing function for multi-letter extensions. Return Value: @@ -530,10 +580,10 @@ fail: /* Return the current arch string. */ std::string -riscv_arch_str () +riscv_arch_str (bool version_p) { gcc_assert (current_subset_list); - return current_subset_list->to_string (); + return current_subset_list->to_string (version_p); } /* Parse a RISC-V ISA string into an option mask. Must clear or set all arch @@ -600,6 +650,21 @@ riscv_handle_option (struct gcc_options *opts, } } +/* Expand arch string with implied extensions. */ + +const char * +riscv_expand_arch (int argc ATTRIBUTE_UNUSED, + const char **argv) +{ + static char *_arch_buf; + gcc_assert (argc == 1); + int flags; + location_t loc = UNKNOWN_LOCATION; + riscv_parse_arch_string (argv[0], &flags, loc); + _arch_buf = xstrdup (riscv_arch_str (false).c_str ()); + return _arch_buf; +} + /* Implement TARGET_OPTION_OPTIMIZATION_TABLE. */ static const struct default_options riscv_option_optimization_table[] = { diff --git a/gcc/config/riscv/riscv-protos.h b/gcc/config/riscv/riscv-protos.h index 8cf9137b5e7..4ff33593ec7 100644 --- a/gcc/config/riscv/riscv-protos.h +++ b/gcc/config/riscv/riscv-protos.h @@ -87,7 +87,7 @@ extern tree riscv_builtin_decl (unsigned int, bool); extern void riscv_init_builtins (void); /* Routines implemented in riscv-common.c. */ -extern std::string riscv_arch_str (); +extern std::string riscv_arch_str (bool version_p = true); extern bool riscv_hard_regno_rename_ok (unsigned, unsigned); diff --git a/gcc/config/riscv/riscv.h b/gcc/config/riscv/riscv.h index 567c23380fe..f494daa24e4 100644 --- a/gcc/config/riscv/riscv.h +++ b/gcc/config/riscv/riscv.h @@ -40,6 +40,11 @@ along with GCC; see the file COPYING3. If not see #define RISCV_TUNE_STRING_DEFAULT "rocket" #endif +extern const char *riscv_expand_arch (int argc, const char **argv); + +# define EXTRA_SPEC_FUNCTIONS \ + { "riscv_expand_arch", riscv_expand_arch }, + /* Support for a compile-time default CPU, et cetera. The rules are: --with-arch is ignored if -march is specified. --with-abi is ignored if -mabi is specified. @@ -59,7 +64,7 @@ along with GCC; see the file COPYING3. If not see #define ASM_SPEC "\ %(subtarget_asm_debugging_spec) \ %{" FPIE_OR_FPIC_SPEC ":-fpic} \ -%{march=*} \ +%{march=*:-march=%:riscv_expand_arch(%*)} \ %{mabi=*} \ %(subtarget_asm_spec)" diff --git a/gcc/testsuite/gcc.target/riscv/arch-6.c b/gcc/testsuite/gcc.target/riscv/arch-6.c new file mode 100644 index 00000000000..b36dccbf46b --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/arch-6.c @@ -0,0 +1,5 @@ +/* { dg-do compile } */ +/* { dg-options "-O -march=rv32id -mabi=ilp32" } */ +int foo() +{ +} diff --git a/gcc/testsuite/gcc.target/riscv/attribute-11.c b/gcc/testsuite/gcc.target/riscv/attribute-11.c new file mode 100644 index 00000000000..a8649508b2f --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/attribute-11.c @@ -0,0 +1,6 @@ +/* { dg-do compile } */ +/* { dg-options "-O -mriscv-attribute -march=rv32id -mabi=ilp32" } */ +int foo() +{ +} +/* { dg-final { scan-assembler ".attribute arch, \"rv32i2p0_f2p0_d2p0\"" } } */ diff --git a/gcc/testsuite/gcc.target/riscv/attribute-12.c b/gcc/testsuite/gcc.target/riscv/attribute-12.c new file mode 100644 index 00000000000..df27fc3234d --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/attribute-12.c @@ -0,0 +1,6 @@ +/* { dg-do compile } */ +/* { dg-options "-O -mriscv-attribute -march=rv32ifd -mabi=ilp32" } */ +int foo() +{ +} +/* { dg-final { scan-assembler ".attribute arch, \"rv32i2p0_f2p0_d2p0\"" } } */