[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
Tue May 13 15:02:58 PDT 2025
https://github.com/llvmbot updated https://github.com/llvm/llvm-project/pull/137490
>From a708fb737a78ff0b3d13d3d8e21f354542947e07 Mon Sep 17 00:00:00 2001
From: Pengcheng Wang <wangpengcheng.pp at bytedance.com>
Date: Sun, 27 Apr 2025 11:12:47 +0800
Subject: [PATCH] [RISCV] Allow `Zicsr`/`Zifencei` to duplicate with `g`
(#136842)
This matches GCC and we supported it in LLVM 17/18.
Fixes #136803
(cherry picked from commit 6c3373534305a2ce23dd939344dd0a387a09fe88)
---
clang/docs/ReleaseNotes.rst | 2 ++
llvm/lib/TargetParser/RISCVISAInfo.cpp | 18 +++++++++++++++---
.../TargetParser/RISCVISAInfoTest.cpp | 8 ++++++++
3 files changed, 25 insertions(+), 3 deletions(-)
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()),
More information about the llvm-branch-commits
mailing list