Skip to content

[RISCV] Allow Zicsr/Zifencei to duplicate with g #136842

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 5 commits into from
Apr 27, 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 @@ -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 be duplicated in the presence of `g` in `-march`.

CUDA/HIP Language Changes
^^^^^^^^^^^^^^^^^^^^^^^^^

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 @@ -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));
}

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 @@ -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()),
Expand Down
Loading