Author: Pengcheng Wang Date: 2025-04-27T11:12:47+08:00 New Revision: 6c3373534305a2ce23dd939344dd0a387a09fe88
URL: https://github.com/llvm/llvm-project/commit/6c3373534305a2ce23dd939344dd0a387a09fe88 DIFF: https://github.com/llvm/llvm-project/commit/6c3373534305a2ce23dd939344dd0a387a09fe88.diff LOG: [RISCV] Allow `Zicsr`/`Zifencei` to duplicate with `g` (#136842) This matches GCC and we supported it in LLVM 17/18. Fixes #136803 Added: Modified: clang/docs/ReleaseNotes.rst llvm/lib/TargetParser/RISCVISAInfo.cpp llvm/unittests/TargetParser/RISCVISAInfoTest.cpp Removed: ################################################################################ diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 3724c8cbc70fe..eb2e8f2b8a6c0 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -646,6 +646,8 @@ RISC-V Support Qualcomm's `Xqciint` extension to save and restore some GPRs in interrupt service routines. +- `Zicsr` / `Zifencei` are allowed to be duplicated in the presence of `g` in `-march`. + CUDA/HIP Language Changes ^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/llvm/lib/TargetParser/RISCVISAInfo.cpp b/llvm/lib/TargetParser/RISCVISAInfo.cpp index ff0174210f87f..ad7bdcd112459 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,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 625c79abd04f4..7b059ba7111d6 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()), _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits