Skip to content

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

Merged
merged 1 commit into from
May 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
18 changes: 15 additions & 3 deletions llvm/lib/TargetParser/RISCVISAInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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));
}

Expand Down
8 changes: 8 additions & 0 deletions llvm/unittests/TargetParser/RISCVISAInfoTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
Expand Down
Loading