-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[RISCV] Allow Zicsr
/Zifencei
to duplicate with g
#136842
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[RISCV] Allow Zicsr
/Zifencei
to duplicate with g
#136842
Conversation
@llvm/pr-subscribers-backend-risc-v Author: Pengcheng Wang (wangpc-pp) ChangesThis matches GCC and we supported it in LLVM 17/18. Fixes #136803 Full diff: https://github.com/llvm/llvm-project/pull/136842.diff 3 Files Affected:
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 5ccd346a93b4f..632d8396ed3b6 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -632,6 +632,8 @@ RISC-V Support
Qualcomm's `Xqciint` extension to save and restore some GPRs in interrupt
service routines.
+- `Zicsr` / `Zifencei` are allowed to duplicate with `g` in `-march`.
+
CUDA/HIP Language Changes
^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/llvm/lib/TargetParser/RISCVISAInfo.cpp b/llvm/lib/TargetParser/RISCVISAInfo.cpp
index ff0174210f87f..a63ad98bf26a4 100644
--- a/llvm/lib/TargetParser/RISCVISAInfo.cpp
+++ b/llvm/lib/TargetParser/RISCVISAInfo.cpp
@@ -45,9 +45,8 @@ struct RISCVProfile {
} // end anonymous namespace
-static const char *RISCVGImplications[] = {
- "i", "m", "a", "f", "d", "zicsr", "zifencei"
-};
+static const char *RISCVGImplications[] = {"i", "m", "a", "f", "d"};
+static const char *RISCVGImplicationsZi[] = {+"zicsr", "zifencei"};
#define GET_SUPPORTED_EXTENSIONS
#include "llvm/TargetParser/RISCVTargetParserDef.inc"
@@ -717,6 +716,15 @@ RISCVISAInfo::parseArchString(StringRef Arch, bool EnableExperimentalExtension,
} while (!Ext.empty());
}
+ // We add Zicsr/Zifenci as final to allow duplicated "zicsr"/"zifencei".
+ if (Baseline == 'g') {
+ for (const char *Ext : RISCVGImplicationsZi) {
+ auto Version = findDefaultVersion(Ext);
+ assert(Version && "Default extension version not found?");
+ ISAInfo->Exts[std::string(Ext)] = {Version->Major, Version->Minor};
+ }
+ }
+
return RISCVISAInfo::postProcessAndChecking(std::move(ISAInfo));
}
diff --git a/llvm/unittests/TargetParser/RISCVISAInfoTest.cpp b/llvm/unittests/TargetParser/RISCVISAInfoTest.cpp
index 43896fede57d8..0bea138560895 100644
--- a/llvm/unittests/TargetParser/RISCVISAInfoTest.cpp
+++ b/llvm/unittests/TargetParser/RISCVISAInfoTest.cpp
@@ -512,6 +512,14 @@ TEST(ParseArchString, RejectsDoubleOrTrailingUnderscore) {
}
TEST(ParseArchString, RejectsDuplicateExtensionNames) {
+ // Zicsr/Zifencei are allowed to duplicate with "g".
+ ASSERT_THAT_EXPECTED(RISCVISAInfo::parseArchString("rv64g_zicsr", true),
+ Succeeded());
+ ASSERT_THAT_EXPECTED(RISCVISAInfo::parseArchString("rv64g_zifencei", true),
+ Succeeded());
+ ASSERT_THAT_EXPECTED(
+ RISCVISAInfo::parseArchString("rv64g_zicsr_zifencei", true), Succeeded());
+
EXPECT_EQ(toString(RISCVISAInfo::parseArchString("rv64ii", true).takeError()),
"invalid standard user-level extension 'i'");
EXPECT_EQ(toString(RISCVISAInfo::parseArchString("rv32ee", true).takeError()),
|
@llvm/pr-subscribers-clang Author: Pengcheng Wang (wangpc-pp) ChangesThis matches GCC and we supported it in LLVM 17/18. Fixes #136803 Full diff: https://github.com/llvm/llvm-project/pull/136842.diff 3 Files Affected:
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 5ccd346a93b4f..632d8396ed3b6 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -632,6 +632,8 @@ RISC-V Support
Qualcomm's `Xqciint` extension to save and restore some GPRs in interrupt
service routines.
+- `Zicsr` / `Zifencei` are allowed to duplicate with `g` in `-march`.
+
CUDA/HIP Language Changes
^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/llvm/lib/TargetParser/RISCVISAInfo.cpp b/llvm/lib/TargetParser/RISCVISAInfo.cpp
index ff0174210f87f..a63ad98bf26a4 100644
--- a/llvm/lib/TargetParser/RISCVISAInfo.cpp
+++ b/llvm/lib/TargetParser/RISCVISAInfo.cpp
@@ -45,9 +45,8 @@ struct RISCVProfile {
} // end anonymous namespace
-static const char *RISCVGImplications[] = {
- "i", "m", "a", "f", "d", "zicsr", "zifencei"
-};
+static const char *RISCVGImplications[] = {"i", "m", "a", "f", "d"};
+static const char *RISCVGImplicationsZi[] = {+"zicsr", "zifencei"};
#define GET_SUPPORTED_EXTENSIONS
#include "llvm/TargetParser/RISCVTargetParserDef.inc"
@@ -717,6 +716,15 @@ RISCVISAInfo::parseArchString(StringRef Arch, bool EnableExperimentalExtension,
} while (!Ext.empty());
}
+ // We add Zicsr/Zifenci as final to allow duplicated "zicsr"/"zifencei".
+ if (Baseline == 'g') {
+ for (const char *Ext : RISCVGImplicationsZi) {
+ auto Version = findDefaultVersion(Ext);
+ assert(Version && "Default extension version not found?");
+ ISAInfo->Exts[std::string(Ext)] = {Version->Major, Version->Minor};
+ }
+ }
+
return RISCVISAInfo::postProcessAndChecking(std::move(ISAInfo));
}
diff --git a/llvm/unittests/TargetParser/RISCVISAInfoTest.cpp b/llvm/unittests/TargetParser/RISCVISAInfoTest.cpp
index 43896fede57d8..0bea138560895 100644
--- a/llvm/unittests/TargetParser/RISCVISAInfoTest.cpp
+++ b/llvm/unittests/TargetParser/RISCVISAInfoTest.cpp
@@ -512,6 +512,14 @@ TEST(ParseArchString, RejectsDoubleOrTrailingUnderscore) {
}
TEST(ParseArchString, RejectsDuplicateExtensionNames) {
+ // Zicsr/Zifencei are allowed to duplicate with "g".
+ ASSERT_THAT_EXPECTED(RISCVISAInfo::parseArchString("rv64g_zicsr", true),
+ Succeeded());
+ ASSERT_THAT_EXPECTED(RISCVISAInfo::parseArchString("rv64g_zifencei", true),
+ Succeeded());
+ ASSERT_THAT_EXPECTED(
+ RISCVISAInfo::parseArchString("rv64g_zicsr_zifencei", true), Succeeded());
+
EXPECT_EQ(toString(RISCVISAInfo::parseArchString("rv64ii", true).takeError()),
"invalid standard user-level extension 'i'");
EXPECT_EQ(toString(RISCVISAInfo::parseArchString("rv32ee", true).takeError()),
|
This matches GCC and we supported it in LLVM 17/18. Fixes llvm#136803
e133a5f
to
723976e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
If you're planning on backporting this, should the release notes be added in a separate commit? I'm wondering if you'll end up with issues trying to cherry-pick it otherwise |
I think we'd typically land a change in the most logical way for the main branch and then handle unpicking the backport manually - it just means the tooling needs a little bit of help but it's not complex to manually drop the release note change. I don't feel strongly given what a minor detail it is, but that would be my default. |
This reverts commit ddd46bf.
According to the sync-up meeting, we can proceed this patch as-is. I will merge this in a few days. I added back the release note. @asb |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
/cherry-pick 6c33735 |
/pull-request #137490 |
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/10/builds/4224 Here is the relevant piece of the build log for the reference
|
This matches GCC and we supported it in LLVM 17/18. Fixes llvm#136803
This matches GCC and we supported it in LLVM 17/18. Fixes llvm#136803
This matches GCC and we supported it in LLVM 17/18. Fixes llvm#136803
This matches GCC and we supported it in LLVM 17/18. Fixes llvm#136803
This matter was addressed at the RVI Toolchain SIG meeting on 05/08/25. It was concluded that the duplication of implied extensions, such as in the cases of G and Zifencei, and F and Zicsr, can be silently disregarded. Both GCC and LLVM toolchains are consistent with this approach through the application of this LLVM patch. However, the duplication of unrelated extensions should result in an error message indicating an invalid duplicated extension, which is already implemented in both toolchains. |
This matches GCC and we supported it in LLVM 17/18. Fixes llvm#136803
This matches GCC and we supported it in LLVM 17/18. Fixes llvm#136803 (cherry picked from commit 6c33735)
This matches GCC and we supported it in LLVM 17/18.
Fixes #136803