-
Notifications
You must be signed in to change notification settings - Fork 14.3k
release/20.x: [RISCV] Allow Zicsr
/Zifencei
to duplicate with g
(#136842)
#137490
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
Conversation
@topperc What do you think about merging this PR to the release branch? |
@llvm/pr-subscribers-backend-risc-v @llvm/pr-subscribers-clang Author: None (llvmbot) ChangesBackport 6c33735 Requested by: @wangpc-pp Full diff: https://github.com/llvm/llvm-project/pull/137490.diff 3 Files Affected:
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index b8f26ec9a5447..47ef2f80ac3f2 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -1267,6 +1267,8 @@ RISC-V Support
- The option ``-mcmodel=large`` for the large code model is supported.
- Bump RVV intrinsic to version 1.0, the spec: https://github.com/riscv-non-isa/rvv-intrinsic-doc/releases/tag/v1.0.0-rc4
+- `Zicsr` / `Zifencei` are allowed to be duplicated in the presence of `g` in `-march`.
+
CUDA/HIP Language Changes
^^^^^^^^^^^^^^^^^^^^^^^^^
- Fixed a bug about overriding a constexpr pure-virtual member function with a non-constexpr virtual member function which causes compilation failure when including standard C++ header `format`.
diff --git a/llvm/lib/TargetParser/RISCVISAInfo.cpp b/llvm/lib/TargetParser/RISCVISAInfo.cpp
index c78d60fd86b3f..64ec411cb06e1 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"
@@ -718,6 +717,19 @@ RISCVISAInfo::parseArchString(StringRef Arch, bool EnableExperimentalExtension,
} while (!Ext.empty());
}
+ // We add Zicsr/Zifenci as final to allow duplicated "zicsr"/"zifencei" like
+ // "rv64g_zicsr_zifencei".
+ if (Baseline == 'g') {
+ for (const char *Ext : RISCVGImplicationsZi) {
+ if (ISAInfo->Exts.count(Ext))
+ continue;
+
+ 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 7ebfcf915a7c5..5089bc0fd479a 100644
--- a/llvm/unittests/TargetParser/RISCVISAInfoTest.cpp
+++ b/llvm/unittests/TargetParser/RISCVISAInfoTest.cpp
@@ -507,6 +507,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()),
|
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
This has some failing tests. |
The failure is not related to this PR I think, it is about
|
Thanks @tstellar! Now all checks are passed! |
This matches GCC and we supported it in LLVM 17/18. Fixes llvm#136803 (cherry picked from commit 6c33735)
@wangpc-pp (or anyone else). If you would like to add a note about this fix in the release notes (completely optional). Please reply to this comment with a one or two sentence description of the fix. When you are done, please add the release:note label to this PR. |
It is in the |
Backport 6c33735
Requested by: @wangpc-pp