From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pl1-x62e.google.com (mail-pl1-x62e.google.com [IPv6:2607:f8b0:4864:20::62e]) by sourceware.org (Postfix) with ESMTPS id 8EEE4385842B for ; Mon, 8 Jan 2024 13:47:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8EEE4385842B Authentication-Results: sourceware.org; dmarc=pass (p=reject dis=none) header.from=sifive.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=sifive.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 8EEE4385842B Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::62e ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704721682; cv=none; b=xRX7JspwuPZW6NqEMqL3PMwfMWcnKPznI9DYQXrShxVWmsvtGXtsAzjSj94JeG+06JawRE/gsQUZUS/5u3aV7DP5jujDRrMMv3HRCJLthvO0vbd2ya9btzWyvrJVcqVOX7wIa5LD6sKFaYZ2nRrwNSM8oBXXtVbMZTY6ZCjiA/w= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704721682; c=relaxed/simple; bh=DceE9FZVoAA/O4oGg27GFlnoq6nTt49fnt8fpPgZpdg=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=EsSH//FL4k/OpEBTKy9kKKuD9xLb0r81jLBNJCawboHoZXJUeJV7pGtmnu1TV3YP9rRmivfjj7xdG8FsYYbllfq2j7kYOeaEayS7sWltEyY+wWOINB8qBsSyFMUFopZiBLfRMCr/OiYNGQajMRVaDsurYQc55GGWTJCZP3anIeQ= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pl1-x62e.google.com with SMTP id d9443c01a7336-1d4ba539f6cso16569705ad.3 for ; Mon, 08 Jan 2024 05:47:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1704721676; x=1705326476; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=fCKTiGAerFb02Yus8CvOf0Kfco4TBiIkJ+a/N4dc5L4=; b=L89AUKyyUsT8SEx6Pq7DzU66c3zlvlCHIcbADSQKO8l7wa4H1u+Ibgd7exufeE6mTd fpqNY2Z9uircqYkvnxr2+kN8wbXaiq/5U87Q9O8+Fm1piTr4bYhs8wNTCtnEd1Ef9Cqk TvwOQ0OgfNxjg+sU/79MpmGjOd2tcZVdyV8rVR7mYAeajAZhe7chSQcu8wqdpRrjRJ30 9G2hSM4IFZn3Up55SE4uZZYgA723bbwINXGFFBTpgAEHGpwI2T+FJCJV8337i/GaudHr 5qhrpobsJlhVwZoFQKaCeW1xf/DKWe7uNovpE58SEV1IrKXl8mIw1B/9VFxbKFNDdi1q 10bA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704721676; x=1705326476; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=fCKTiGAerFb02Yus8CvOf0Kfco4TBiIkJ+a/N4dc5L4=; b=FMzULaPwruYyR+5rN7mI7iJ3RCto66g1p/fCyu2qBFm8m2SMqhbTfyIIcYdNmARlIh hEn1RTH6lA0sCBAzMEC2Xw0cdpLYX0dcyFFN4vW9nBa/cydRYNbRrleTdP/aFxuvf/nt OVZOv3BkVYxI0L+hdsxcgIDFV83ZgHxMaOnNKJ8RFwl+Sx2C9FUTbmWwjpX6sL7Q5dmr TKGEi/1LkW733oseu2Xeae5mEyvyHQy/PhOvLNPX7zMMbva5vz/O5VWtlWgl8kdRdO4W wcSQUlHFQiHvJhpfBDfRvnxbuWwhyIm4v8BEp+wxvI6PKYpd71crJ0RPEEVvHHOG5vEs augQ== X-Gm-Message-State: AOJu0YwD7JlWglZhGjNm0akv5Nt3+hk/L4CgcST55aXZj6V9lBCaVYN1 72y0LqyWhSvEM+acLFp9GuFgcf2qH5pFYDKr40mxr76EOpfD0lOtLxoVBio32qCYT//wbPQJd08 Sj9je2c2w1J+pH8YSGVsej7F+MqzgiuohZLVPbqclztuNXmombUcVex+PGrWmzVUkXmdJGrxZzR YO4EKL3m2JBlw= X-Google-Smtp-Source: AGHT+IG2Lw8Lv796RGQEszIbBmf1unMf/6NqB9Wz/8uyp5G03TnrQjGMcJFzH+XfV/O8Yks7L4uMuQ== X-Received: by 2002:a17:903:1d1:b0:1d3:f0c1:6ad6 with SMTP id e17-20020a17090301d100b001d3f0c16ad6mr4724230plh.18.1704721675841; Mon, 08 Jan 2024 05:47:55 -0800 (PST) Received: from hsinchu18.internal.sifive.com (59-124-168-89.hinet-ip.hinet.net. [59.124.168.89]) by smtp.gmail.com with ESMTPSA id jc20-20020a17090325d400b001d403969b65sm4588056plb.187.2024.01.08.05.47.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Jan 2024 05:47:55 -0800 (PST) From: Kito Cheng To: gcc-patches@gcc.gnu.org, kito.cheng@gmail.com, jim.wilson.gcc@gmail.com, palmer@dabbelt.com, andrew@sifive.com, jeffreyalaw@gmail.com, christoph.muellner@vrull.eu Cc: Kito Cheng Subject: [PATCH 2/5] RISC-V: Relax the -march string for accept any order Date: Mon, 8 Jan 2024 21:47:35 +0800 Message-Id: <20240108134738.998804-3-kito.cheng@sifive.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240108134738.998804-1-kito.cheng@sifive.com> References: <20240108134738.998804-1-kito.cheng@sifive.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-12.8 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_SHORT,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,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 List-Id: -march was require canonical order before, however it's not easy for most user when we have so many extension, so this patch is relax the constraint, -march accept the ISA string in any order, it only has few requirement: 1. Must start with rv[32|64][e|i|g]. 2. Multi-letter and single letter extension must be separated by at least one underscore(`_`). gcc/ChangeLog: * common/config/riscv/riscv-common.cc (riscv_subset_list::parse_single_std_ext): New parameter. (riscv_subset_list::parse_single_multiletter_ext): Ditto. (riscv_subset_list::parse_single_ext): Ditto. (riscv_subset_list::parse): Relax the order for the input of ISA string. * config/riscv/riscv-subset.h (riscv_subset_list::parse_single_std_ext): New parameter. (riscv_subset_list::parse_single_multiletter_ext): Ditto. (riscv_subset_list::parse_single_ext): Ditto. gcc/testsuite/ChangeLog: * gcc.target/riscv/arch-33.c: New. * gcc.target/riscv/arch-34.c: New. --- gcc/common/config/riscv/riscv-common.cc | 91 ++++++++++++++---------- gcc/config/riscv/riscv-subset.h | 6 +- gcc/testsuite/gcc.target/riscv/arch-33.c | 5 ++ gcc/testsuite/gcc.target/riscv/arch-34.c | 5 ++ 4 files changed, 67 insertions(+), 40 deletions(-) create mode 100644 gcc/testsuite/gcc.target/riscv/arch-33.c create mode 100644 gcc/testsuite/gcc.target/riscv/arch-34.c diff --git a/gcc/common/config/riscv/riscv-common.cc b/gcc/common/config/riscv/riscv-common.cc index f0359380451..891ecfce464 100644 --- a/gcc/common/config/riscv/riscv-common.cc +++ b/gcc/common/config/riscv/riscv-common.cc @@ -1132,10 +1132,12 @@ riscv_subset_list::parse_std_ext (const char *p) Points to the end of extensions. Arguments: - `p`: Current parsing position. */ + `p`: Current parsing position. + `exact_single_p`: True if input string is exactly an extension and end + with '\0'. */ const char * -riscv_subset_list::parse_single_std_ext (const char *p) +riscv_subset_list::parse_single_std_ext (const char *p, bool exact_single_p) { if (*p == 'x' || *p == 's' || *p == 'z') { @@ -1146,6 +1148,11 @@ riscv_subset_list::parse_single_std_ext (const char *p) return nullptr; } + if (exact_single_p && strlen (p) > 1) + { + return nullptr; + } + unsigned major_version = 0; unsigned minor_version = 0; bool explicit_version_p = false; @@ -1296,13 +1303,16 @@ riscv_subset_list::check_conflict_ext () Arguments: `p`: Current parsing position. `ext_type`: What kind of extensions, 's', 'z' or 'x'. - `ext_type_str`: Full name for kind of extension. */ + `ext_type_str`: Full name for kind of extension. + `exact_single_p`: True if input string is exactly an extension and end + with '\0'. */ const char * riscv_subset_list::parse_single_multiletter_ext (const char *p, const char *ext_type, - const char *ext_type_str) + const char *ext_type_str, + bool exact_single_p) { unsigned major_version = 0; unsigned minor_version = 0; @@ -1314,6 +1324,7 @@ riscv_subset_list::parse_single_multiletter_ext (const char *p, char *subset = xstrdup (p); const char *end_of_version; bool explicit_version_p = false; + char *q = subset; char *ext; char backup; size_t len = strlen (p); @@ -1321,6 +1332,17 @@ riscv_subset_list::parse_single_multiletter_ext (const char *p, bool found_any_number = false; bool found_minor_version = false; + if (!exact_single_p) + { + /* Extension may not ended with '\0', may come with another extension + which concat by '_' */ + /* Parse until end of this extension including version number. */ + while (*++q != '\0' && *q != '_') + ; + + len = q - subset; + } + end_of_version_pos = len; /* Find the begin of version string. */ for (i = len -1; i > 0; --i) @@ -1505,21 +1527,26 @@ riscv_subset_list::parse_multiletter_ext (const char *p, Points to the end of extensions. Arguments: - `p`: Current parsing position. */ + `p`: Current parsing position. + `exact_single_p`: True if input string is exactly an extension and end + with '\0'. */ const char * -riscv_subset_list::parse_single_ext (const char *p) +riscv_subset_list::parse_single_ext (const char *p, bool exact_single_p) { switch (p[0]) { case 'x': - return parse_single_multiletter_ext (p, "x", "non-standard extension"); + return parse_single_multiletter_ext (p, "x", "non-standard extension", + exact_single_p); case 'z': - return parse_single_multiletter_ext (p, "z", "sub-extension"); + return parse_single_multiletter_ext (p, "z", "sub-extension", + exact_single_p); case 's': - return parse_single_multiletter_ext (p, "s", "supervisor extension"); + return parse_single_multiletter_ext (p, "s", "supervisor extension", + exact_single_p); default: - return parse_single_std_ext (p); + return parse_single_std_ext (p, exact_single_p); } } @@ -1538,37 +1565,27 @@ riscv_subset_list::parse (const char *arch, location_t loc) if (p == NULL) goto fail; - /* Parsing standard extension. */ - p = subset_list->parse_std_ext (p); - - if (p == NULL) - goto fail; - - /* Parsing sub-extensions. */ - p = subset_list->parse_multiletter_ext (p, "z", "sub-extension"); - - if (p == NULL) - goto fail; - - /* Parsing supervisor extension. */ - p = subset_list->parse_multiletter_ext (p, "s", "supervisor extension"); - - if (p == NULL) - goto fail; - - /* Parsing non-standard extension. */ - p = subset_list->parse_multiletter_ext (p, "x", "non-standard extension"); + while (p && *p) + { + switch (*p) + { + case '_': + ++p; + continue; + case 'e': + case 'i': + case 'g': + error_at (loc, "%<-march=%s%>: 'i', 'e' or 'g' must be the first extension.", + arch); + goto fail; + default: + p = subset_list->parse_single_ext (p, /*exact_single_p=*/ false); + } + } if (p == NULL) goto fail; - if (*p != '\0') - { - error_at (loc, "%<-march=%s%>: unexpected ISA string at end: %qs", - arch, p); - goto fail; - } - for (itr = subset_list->m_head; itr != NULL; itr = itr->next) { subset_list->handle_implied_ext (itr->name.c_str ()); diff --git a/gcc/config/riscv/riscv-subset.h b/gcc/config/riscv/riscv-subset.h index c8117d8daf2..a80f9138e5c 100644 --- a/gcc/config/riscv/riscv-subset.h +++ b/gcc/config/riscv/riscv-subset.h @@ -71,12 +71,12 @@ private: const char *parse_std_ext (const char *); - const char *parse_single_std_ext (const char *); + const char *parse_single_std_ext (const char *, bool); const char *parse_multiletter_ext (const char *, const char *, const char *); const char *parse_single_multiletter_ext (const char *, const char *, - const char *); + const char *, bool); void handle_implied_ext (const char *); bool check_implied_ext (); @@ -101,7 +101,7 @@ public: riscv_subset_list *clone () const; static riscv_subset_list *parse (const char *, location_t); - const char *parse_single_ext (const char *); + const char *parse_single_ext (const char *, bool exact_single_p = true); const riscv_subset_t *begin () const {return m_head;}; const riscv_subset_t *end () const {return NULL;}; diff --git a/gcc/testsuite/gcc.target/riscv/arch-33.c b/gcc/testsuite/gcc.target/riscv/arch-33.c new file mode 100644 index 00000000000..3fac9285ca3 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/arch-33.c @@ -0,0 +1,5 @@ +/* { dg-do compile } */ +/* { dg-options "-march=rv64i_zba____zbs_mac_d -mabi=lp64d" } */ +int foo() +{ +} diff --git a/gcc/testsuite/gcc.target/riscv/arch-34.c b/gcc/testsuite/gcc.target/riscv/arch-34.c new file mode 100644 index 00000000000..9b9f1a7a439 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/arch-34.c @@ -0,0 +1,5 @@ +/* { dg-do compile } */ +/* { dg-options "-march=rv64i_xtheadbs_zba_fcd -mabi=lp64d" } */ +int foo() +{ +} -- 2.34.1