From: Kito Cheng <kito.cheng@sifive.com>
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 <kito.cheng@sifive.com>
Subject: [PATCH 2/5] RISC-V: Relax the -march string for accept any order
Date: Mon, 8 Jan 2024 21:47:35 +0800 [thread overview]
Message-ID: <20240108134738.998804-3-kito.cheng@sifive.com> (raw)
In-Reply-To: <20240108134738.998804-1-kito.cheng@sifive.com>
-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
next prev parent reply other threads:[~2024-01-08 13:47 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-08 13:47 [PATCH 0/5] " Kito Cheng
2024-01-08 13:47 ` [PATCH 1/5] RISC-V: Extract part parsing base ISA logic into a standalone function [NFC] Kito Cheng
2024-01-08 13:47 ` Kito Cheng [this message]
2024-01-08 13:47 ` [PATCH 3/5] RISC-V: Remove unused function in riscv_subset_list [NFC] Kito Cheng
2024-01-08 13:47 ` [PATCH 4/5] RISC-V: Update testsuite due to -march string relaxation Kito Cheng
2024-01-08 13:47 ` [PATCH 5/5] RISC-V: Document the syntax of -march Kito Cheng
2024-01-09 18:31 ` [PATCH 0/5] RISC-V: Relax the -march string for accept any order Jeff Law
2024-01-10 0:58 ` Kito Cheng
2024-01-10 1:38 ` Fangrui Song
2024-01-16 14:33 ` Jeff Law
2024-01-19 7:20 ` Kito Cheng
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240108134738.998804-3-kito.cheng@sifive.com \
--to=kito.cheng@sifive.com \
--cc=andrew@sifive.com \
--cc=christoph.muellner@vrull.eu \
--cc=gcc-patches@gcc.gnu.org \
--cc=jeffreyalaw@gmail.com \
--cc=jim.wilson.gcc@gmail.com \
--cc=kito.cheng@gmail.com \
--cc=palmer@dabbelt.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).