From patchwork Mon Nov 20 19:14:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiawei X-Patchwork-Id: 167370 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2b07:b0:403:3b70:6f57 with SMTP id io7csp159780vqb; Mon, 20 Nov 2023 11:15:36 -0800 (PST) X-Google-Smtp-Source: AGHT+IFZkd1Ys/jpDas5EVXb+e0gDQQAQKVZOUCgOZOOz1r+77BPBz00C3Qa0nlDnPHoGlUcqK/u X-Received: by 2002:a05:6808:1210:b0:3b5:66af:f8d6 with SMTP id a16-20020a056808121000b003b566aff8d6mr11669670oil.47.1700507736498; Mon, 20 Nov 2023 11:15:36 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1700507736; cv=pass; d=google.com; s=arc-20160816; b=AQh03It3AgJ6IMHE7Y+Xk4c4AL1kNJlCcyd0ID4nFIYGnh93/tsXwYukdfiPEySJQB aYgGL7eIPO+LnMRbcae/LR6EYkvhgr2FPbO/H98oVlZodKzYbOmvIsyDD5bXi6kYdtO2 DjAagBNg0i3ApEJt+PwUFpg/LEYuzDBCpiyiB1+bOPd/2p1w93uxEDC6yEhj0Cz0o9Cl k3JkXIK46E9T0UlDzGpc0FK38W+2Om1+fURMH7iBlgOPukz3GcvvxHdQ1tZ1Ltl+ngXC A/2sHvL52WN37UUi7QwUWiy9Rh8/JMO34+89waksD2e3Jb0rz1TNO0qP2wNqp0n7uGHN QTJw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:arc-filter :dmarc-filter:delivered-to; bh=DXuRVT8Wi+RUAfd3/UOT7Dz/NrI2WQu8VTbMdyqFQ7E=; fh=P7I1IKOv1oY0yi/vlnw3+IHckicQUVdanjBcER2WvHw=; b=Xg7onD7i8iLrSBGfNhWd6eeRLazfMqRNbapufX6O5UNMnqDVlrkvOE6QtnWWDl8CgM yMDzFhf/umbGCE2MuDjiUxb80+NgHTkAB4AoMC17Cph8GK2obE97qAqxcvpe1iWYmQlp 2Zz4WDQEoMjJWXbfOkS9EVtfREQcH3OmrGBM9tSPlgKQQS9doy6zUr0juk7bh76FOSxb MdYTpCfM8wK8OrHZwOW47mW6Tb4bFUdjEsyS55iMBFJHuRdUHslMdGd0co+2e+a2+GJe BWbALC+MiKSk9MZMmsG57xB3k68wQ4pa94CQJfZq0ODfzEEzO7WIFAXYUY7AnptSDoEP 6K6Q== ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id bq39-20020a05620a46a700b0077bc720d11dsi8217736qkb.338.2023.11.20.11.15.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Nov 2023 11:15:36 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 43F3C385840C for ; Mon, 20 Nov 2023 19:15:36 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from cstnet.cn (smtp21.cstnet.cn [159.226.251.21]) by sourceware.org (Postfix) with ESMTPS id 417E23858D33 for ; Mon, 20 Nov 2023 19:15:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 417E23858D33 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=iscas.ac.cn Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=iscas.ac.cn ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 417E23858D33 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=159.226.251.21 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700507714; cv=none; b=rFNtxRqk0UgqxV/uEfZc3gzfZ1w00PPDaMdj/VXtPlpPr4Crxj8009VE4lpyx9dBTcrhdcQCqgc6BQ5rGcc8xSvWodr8Uc5CbHD8007mBrbEVdBttMuyhqtqrJKRgqpKvmfCmqW6YOXT5vS+zZCe48XDuccFoAZ4DGQh4I4Dcqo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700507714; c=relaxed/simple; bh=mtEyGnRq/+HMa5KamUTlpq3iy6neUX6nmh2VG+pnZgk=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=VLSEmD2bPMjc93vgv/TFQlpLvShhJKhuh9/ASWDniLCC88iobmjL5su64UYBNqPhM3MG6aMzv6BLs9ETZqnYHtS51ro0moKv+aN4mtUbcRLftuo1csSIOO4XMWBRBasGJXVEN34ph+wmYi0FUFnowsL9DG25MxZgMUGdgy8oVOA= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from localhost.localdomain (unknown [47.113.87.88]) by APP-01 (Coremail) with SMTP id qwCowADn7XVkr1tlDgDbAA--.37779S2; Tue, 21 Nov 2023 03:11:33 +0800 (CST) From: Jiawei To: gcc-patches@gcc.gnu.org Cc: kito.cheng@sifive.com, palmer@dabbelt.com, jeffreyalaw@gmail.com, christoph.muellner@vrull.eu, Jiawei Subject: [RFC] RISC-V: Support RISC-V Profiles in -march option. Date: Tue, 21 Nov 2023 03:14:47 +0800 Message-Id: <20231120191447.2189928-1-jiawei@iscas.ac.cn> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-CM-TRANSID: qwCowADn7XVkr1tlDgDbAA--.37779S2 X-Coremail-Antispam: 1UD129KBjvJXoW3Gr4UJF4kur4Dur45CFWUtwb_yoW7KF1xpF 45Gws0krZ5JFZ3Wrn3KFyUWw43KrsIgryYvw1v9r17A39rJrWjq3WkKw1Sk3W5JF48urnF 9F4Y9ryF9w45X3DanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUkF14x267AKxVWUJVW8JwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2ocxC64kIII0Yj41l84x0c7CEw4AK67xGY2AK02 1l84ACjcxK6xIIjxv20xvE14v26r1j6r1xM28EF7xvwVC0I7IYx2IY6xkF7I0E14v26r1j 6r4UM28EF7xvwVC2z280aVAFwI0_Jr0_Gr1l84ACjcxK6I8E87Iv6xkF7I0E14v26r4j6r 4UJwAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0 I7IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r 4UM4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwCY02Avz4vE174l42xK 82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGw C20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r126r1DMIIYrxkI7VAKI48J MIIF0xvE2Ix0cI8IcVAFwI0_Jr0_JF4lIxAIcVC0I7IYx2IY6xkF7I0E14v26r1j6r4UMI IF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVWUJVW8JwCI42IY6I8E 87Iv6xkF7I0E14v26r1j6r4UYxBIdaVFxhVjvjDU0xZFpf9x0pRCD7sUUUUU= X-Originating-IP: [47.113.87.88] X-CM-SenderInfo: 5mld4v3l6l2u1dvotugofq/1tbiCQcBAGVbcC6U-wAAsE X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, KAM_SHORT, SPF_HELO_PASS, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783111600315608277 X-GMAIL-MSGID: 1783111600315608277 Supports RISC-V profiles[1] in -march option. Default input set the profile is before other formal extensions. [1]https://github.com/riscv/riscv-profiles/blob/main/profiles.adoc gcc/ChangeLog: * common/config/riscv/riscv-common.cc (struct riscv_profiles): New struct. (riscv_subset_list::parse_profiles): New function. (riscv_subset_list::parse): New table. * config/riscv/riscv-subset.h: New protype. gcc/testsuite/ChangeLog: * gcc.target/riscv/arch-29.c: New test. * gcc.target/riscv/arch-30.c: New test. * gcc.target/riscv/arch-31.c: New test. --- gcc/common/config/riscv/riscv-common.cc | 58 +++++++++++++++++++++++- gcc/config/riscv/riscv-subset.h | 2 + gcc/testsuite/gcc.target/riscv/arch-29.c | 5 ++ gcc/testsuite/gcc.target/riscv/arch-30.c | 5 ++ gcc/testsuite/gcc.target/riscv/arch-31.c | 5 ++ 6 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.target/riscv/arch-29.c create mode 100644 gcc/testsuite/gcc.target/riscv/arch-30.c create mode 100644 gcc/testsuite/gcc.target/riscv/arch-31.c diff --git a/gcc/common/config/riscv/riscv-common.cc b/gcc/common/config/riscv/riscv-common.cc index 5111626157b..30617e619b1 100644 --- a/gcc/common/config/riscv/riscv-common.cc +++ b/gcc/common/config/riscv/riscv-common.cc @@ -165,6 +165,12 @@ struct riscv_ext_version int minor_version; }; +struct riscv_profiles +{ + const char * profile_name; + const char * profile_string; +}; + /* All standard extensions defined in all supported ISA spec. */ static const struct riscv_ext_version riscv_ext_version_table[] = { @@ -348,6 +354,28 @@ static const struct riscv_ext_version riscv_combine_info[] = {NULL, ISA_SPEC_CLASS_NONE, 0, 0} }; +static const riscv_profiles riscv_profiles_table[] = +{ + {"RVI20U64", "rv64i"}, + {"RVI20U32", "rv32i"}, + /*Currently we don't have zicntr,ziccif,ziccrse,ziccamoa, + zicclsm,za128rs yet. */ + {"RVA20U64", "rv64imafdc_zicsr"}, + /*Ss1p11, svbare, sv39, svade, sscptr, ssvecd, sstvala should + control by binutils. */ + {"RVA20S64", "rv64imafdc_zicsr_zifencei"}, + /*Currently we don't have zicntr,zihpm,ziccif,ziccrse,ziccamoa, + zicclsm,zic64b,za64rs yet. */ + {"RVA22U64", "rv64imafdc_zicsr_zihintpause_zba_zbb_zbs_" \ + "zicbom_zicbop_zicboz_zfhmin_zkt"}, + /*Ss1p12, svbare, sv39, svade, sscptr, ssvecd, sstvala, + scounterenw should control by binutils. */ + {"RVA22S64","rv64imafdc_zicsr_zifencei_zihintpause" \ + "_zba_zbb_zbs_zicbom_zicbop_zicboz_zfhmin_zkt_svpbmt_svinval"}, + /* Terminate the list. */ + {NULL, NULL} +}; + static const riscv_cpu_info riscv_cpu_tables[] = { #define RISCV_CORE(CORE_NAME, ARCH, TUNE) \ @@ -927,6 +955,31 @@ riscv_subset_list::parsing_subset_version (const char *ext, return p; } +const char * +riscv_subset_list::parse_profiles (const char * p){ + for (int i = 0; riscv_profiles_table[i].profile_name != NULL; ++i) { + const char* match = strstr(p, riscv_profiles_table[i].profile_name); + const char* plus_ext = strchr(p, '+'); + /* Find profile at the begin. */ + if (match != NULL && match == p) { + /* If there's no '+' sign, return the profile_string directly. */ + if(!plus_ext) + return riscv_profiles_table[i].profile_string; + /* If there's a '+' sign, concatenate profiles with other ext. */ + else { + size_t arch_len = strlen(riscv_profiles_table[i].profile_string) + + strlen(plus_ext); + static char* result = new char[arch_len + 2]; + strcpy(result, riscv_profiles_table[i].profile_string); + strcat(result, "_"); + strcat(result, plus_ext + 1); /* skip the '+'. */ + return result; + } + } + } + return p; +} + /* Parsing function for standard extensions. Return Value: @@ -1430,7 +1483,10 @@ riscv_subset_list::parse (const char *arch, location_t loc) riscv_subset_list *subset_list = new riscv_subset_list (arch, loc); riscv_subset_t *itr; + const char *p = arch; + p = subset_list->parse_profiles(p); + if (startswith (p, "rv32")) { subset_list->m_xlen = 32; @@ -1443,7 +1499,7 @@ riscv_subset_list::parse (const char *arch, location_t loc) } else { - error_at (loc, "%<-march=%s%>: ISA string must begin with rv32 or rv64", + error_at (loc, "%<-march=%s%>: ISA string must begin with rv32, rv64 or a profile", arch); goto fail; } diff --git a/gcc/config/riscv/riscv-subset.h b/gcc/config/riscv/riscv-subset.h index d2a4bd20530..c8b778330b4 100644 --- a/gcc/config/riscv/riscv-subset.h +++ b/gcc/config/riscv/riscv-subset.h @@ -76,6 +76,8 @@ private: const char *parse_single_multiletter_ext (const char *, const char *, const char *); + const char *parse_profiles (const char*); + void handle_implied_ext (const char *); bool check_implied_ext (); void handle_combine_ext (); diff --git a/gcc/testsuite/gcc.target/riscv/arch-29.c b/gcc/testsuite/gcc.target/riscv/arch-29.c new file mode 100644 index 00000000000..eb24abe4153 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/arch-29.c @@ -0,0 +1,5 @@ +/* { dg-do compile } */ +/* { dg-options "-march=RVI20U64 -mabi=lp64" } */ +int foo() +{ +} diff --git a/gcc/testsuite/gcc.target/riscv/arch-30.c b/gcc/testsuite/gcc.target/riscv/arch-30.c new file mode 100644 index 00000000000..bc556a3e717 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/arch-30.c @@ -0,0 +1,5 @@ +/* { dg-do compile } */ +/* { dg-options "-march=RVI20U64+mafdc -mabi=lp64d" } */ +int foo() +{ +} diff --git a/gcc/testsuite/gcc.target/riscv/arch-31.c b/gcc/testsuite/gcc.target/riscv/arch-31.c new file mode 100644 index 00000000000..a7b80a5ad43 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/arch-31.c @@ -0,0 +1,5 @@ +/* { dg-do compile } */ +/* { dg-options "-march=RVA22S64 -mabi=lp64d" } */ +int foo() +{ +}