[llvm-branch-commits] [clang] [llvm] release/20.x: [RISCV] Allow `Zicsr`/`Zifencei` to duplicate with `g` (#136842) (PR #137490)
via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Sat Apr 26 20:21:15 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: None (llvmbot)
<details>
<summary>Changes</summary>
Backport 6c3373534305a2ce23dd939344dd0a387a09fe88
Requested by: @<!-- -->wangpc-pp
---
Full diff: https://github.com/llvm/llvm-project/pull/137490.diff
3 Files Affected:
- (modified) clang/docs/ReleaseNotes.rst (+2)
- (modified) llvm/lib/TargetParser/RISCVISAInfo.cpp (+15-3)
- (modified) llvm/unittests/TargetParser/RISCVISAInfoTest.cpp (+8)
``````````diff
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()),
``````````
</details>
https://github.com/llvm/llvm-project/pull/137490
More information about the llvm-branch-commits
mailing list