https://github.com/wangpc-pp created https://github.com/llvm/llvm-project/pull/136842
This matches GCC and we supported it in LLVM 17/18. Fixes #136803 >From e133a5fc0091ec045a0ea0114d553c72e8f33e51 Mon Sep 17 00:00:00 2001 From: Pengcheng Wang <wangpengcheng...@bytedance.com> Date: Wed, 23 Apr 2025 18:19:41 +0800 Subject: [PATCH] [RISCV] Allow `Zicsr`/`Zifencei` to duplicate with `g` This matches GCC and we supported it in LLVM 17/18. Fixes #136803 --- clang/docs/ReleaseNotes.rst | 2 ++ llvm/lib/TargetParser/RISCVISAInfo.cpp | 14 +++++++++++--- llvm/unittests/TargetParser/RISCVISAInfoTest.cpp | 8 ++++++++ 3 files changed, 21 insertions(+), 3 deletions(-) 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()), _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits