Skip to content

Commit a708fb7

Browse files
wangpc-pptstellar
authored andcommitted
[RISCV] Allow Zicsr/Zifencei to duplicate with g (llvm#136842)
This matches GCC and we supported it in LLVM 17/18. Fixes llvm#136803 (cherry picked from commit 6c33735)
1 parent 1c03684 commit a708fb7

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1267,6 +1267,8 @@ RISC-V Support
12671267
- The option ``-mcmodel=large`` for the large code model is supported.
12681268
- Bump RVV intrinsic to version 1.0, the spec: https://github.com/riscv-non-isa/rvv-intrinsic-doc/releases/tag/v1.0.0-rc4
12691269

1270+
- `Zicsr` / `Zifencei` are allowed to be duplicated in the presence of `g` in `-march`.
1271+
12701272
CUDA/HIP Language Changes
12711273
^^^^^^^^^^^^^^^^^^^^^^^^^
12721274
- 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`.

llvm/lib/TargetParser/RISCVISAInfo.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,8 @@ struct RISCVProfile {
4545

4646
} // end anonymous namespace
4747

48-
static const char *RISCVGImplications[] = {
49-
"i", "m", "a", "f", "d", "zicsr", "zifencei"
50-
};
48+
static const char *RISCVGImplications[] = {"i", "m", "a", "f", "d"};
49+
static const char *RISCVGImplicationsZi[] = {"zicsr", "zifencei"};
5150

5251
#define GET_SUPPORTED_EXTENSIONS
5352
#include "llvm/TargetParser/RISCVTargetParserDef.inc"
@@ -718,6 +717,19 @@ RISCVISAInfo::parseArchString(StringRef Arch, bool EnableExperimentalExtension,
718717
} while (!Ext.empty());
719718
}
720719

720+
// We add Zicsr/Zifenci as final to allow duplicated "zicsr"/"zifencei" like
721+
// "rv64g_zicsr_zifencei".
722+
if (Baseline == 'g') {
723+
for (const char *Ext : RISCVGImplicationsZi) {
724+
if (ISAInfo->Exts.count(Ext))
725+
continue;
726+
727+
auto Version = findDefaultVersion(Ext);
728+
assert(Version && "Default extension version not found?");
729+
ISAInfo->Exts[std::string(Ext)] = {Version->Major, Version->Minor};
730+
}
731+
}
732+
721733
return RISCVISAInfo::postProcessAndChecking(std::move(ISAInfo));
722734
}
723735

llvm/unittests/TargetParser/RISCVISAInfoTest.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,14 @@ TEST(ParseArchString, RejectsDoubleOrTrailingUnderscore) {
507507
}
508508

509509
TEST(ParseArchString, RejectsDuplicateExtensionNames) {
510+
// Zicsr/Zifencei are allowed to duplicate with "g".
511+
ASSERT_THAT_EXPECTED(RISCVISAInfo::parseArchString("rv64g_zicsr", true),
512+
Succeeded());
513+
ASSERT_THAT_EXPECTED(RISCVISAInfo::parseArchString("rv64g_zifencei", true),
514+
Succeeded());
515+
ASSERT_THAT_EXPECTED(
516+
RISCVISAInfo::parseArchString("rv64g_zicsr_zifencei", true), Succeeded());
517+
510518
EXPECT_EQ(toString(RISCVISAInfo::parseArchString("rv64ii", true).takeError()),
511519
"invalid standard user-level extension 'i'");
512520
EXPECT_EQ(toString(RISCVISAInfo::parseArchString("rv32ee", true).takeError()),

0 commit comments

Comments
 (0)