Skip to content

Commit 891d687

Browse files
authored
[RISCV] Gate unratified profiles behind -menable-experimental-extensions (#92167)
As discussed in the last sync-up call, because these profiles are not yet finalised they shouldn't be exposed to users unless they opt-in to them (much like experimental extensions). We may later want to add a more specific flag, but reusing `-menable-experimental-extensions` solves the immediate problem. This is implemented using the new support for marking profiles s experimental added in #91993 to move the unratified profiles to RISCVExperimentalProfile and making the necessary changes to logic in RISCVISAInfo to handle this.
1 parent 24c3926 commit 891d687

File tree

5 files changed

+55
-21
lines changed

5 files changed

+55
-21
lines changed

clang/test/Driver/riscv-profiles.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@
111111
// RVA22S64: "-target-feature" "+svinval"
112112
// RVA22S64: "-target-feature" "+svpbmt"
113113

114-
// RUN: %clang --target=riscv64 -### -c %s 2>&1 -march=rva23u64 \
114+
// RUN: %clang --target=riscv64 -### -c %s 2>&1 -march=rva23u64 -menable-experimental-extensions \
115115
// RUN: | FileCheck -check-prefix=RVA23U64 %s
116116
// RVA23U64: "-target-feature" "+m"
117117
// RVA23U64: "-target-feature" "+a"
@@ -207,7 +207,7 @@
207207
// RVA23S64: "-target-feature" "+svnapot"
208208
// RVA23S64: "-target-feature" "+svpbmt"
209209

210-
// RUN: %clang --target=riscv64 -### -c %s 2>&1 -march=rvb23u64 \
210+
// RUN: %clang --target=riscv64 -### -c %s 2>&1 -march=rvb23u64 -menable-experimental-extensions \
211211
// RUN: | FileCheck -check-prefix=RVB23U64 %s
212212
// RVB23U64: "-target-feature" "+m"
213213
// RVB23U64: "-target-feature" "+a"
@@ -284,7 +284,7 @@
284284
// RVB23S64: "-target-feature" "+svnapot"
285285
// RVB23S64: "-target-feature" "+svpbmt"
286286

287-
// RUN: %clang --target=riscv32 -### -c %s 2>&1 -march=rvm23u32 \
287+
// RUN: %clang --target=riscv32 -### -c %s 2>&1 -march=rvm23u32 -menable-experimental-extensions \
288288
// RUN: | FileCheck -check-prefix=RVM23U32 %s
289289
// RVM23U32: "-target-feature" "+m"
290290
// RVM23U32: "-target-feature" "+zicbop"
@@ -322,3 +322,7 @@
322322

323323
// RUN: not %clang --target=riscv64 -### -c %s 2>&1 -march=rva22u64zfa | FileCheck -check-prefix=INVALID-ADDITIONAL %s
324324
// INVALID-ADDITIONAL: error: invalid arch name 'rva22u64zfa', additional extensions must be after separator '_'
325+
326+
// RUN: not %clang --target=riscv64 -### -c %s 2>&1 -march=rva23u64 | FileCheck -check-prefix=EXPERIMENTAL-NOFLAG %s
327+
// EXPERIMENTAL-NOFLAG: error: invalid arch name 'rva23u64'
328+
// EXPERIMENTAL-NOFLAG: requires '-menable-experimental-extensions' for profile 'rva23u64'

llvm/lib/Target/RISCV/RISCVProfiles.td

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ class RISCVProfile<string name, list<SubtargetFeature> features>
1313
// experimental.
1414
bit Experimental = false;
1515
}
16+
class RISCVExperimentalProfile<string name, list<SubtargetFeature> features>
17+
: RISCVProfile<"experimental-"#name, features> {
18+
let Experimental = true;
19+
}
1620

1721
defvar RVI20U32Features = [Feature32Bit, FeatureStdExtI];
1822
defvar RVI20U64Features = [Feature64Bit, FeatureStdExtI];
@@ -201,8 +205,8 @@ def RVA20U64 : RISCVProfile<"rva20u64", RVA20U64Features>;
201205
def RVA20S64 : RISCVProfile<"rva20s64", RVA20S64Features>;
202206
def RVA22U64 : RISCVProfile<"rva22u64", RVA22U64Features>;
203207
def RVA22S64 : RISCVProfile<"rva22s64", RVA22S64Features>;
204-
def RVA23U64 : RISCVProfile<"rva23u64", RVA23U64Features>;
205-
def RVA23S64 : RISCVProfile<"rva23s64", RVA23S64Features>;
206-
def RVB23U64 : RISCVProfile<"rvb23u64", RVB23U64Features>;
207-
def RVB23S64 : RISCVProfile<"rvb23s64", RVB23S64Features>;
208-
def RVM23U32 : RISCVProfile<"rvm23u32", RVM23U32Features>;
208+
def RVA23U64 : RISCVExperimentalProfile<"rva23u64", RVA23U64Features>;
209+
def RVA23S64 : RISCVExperimentalProfile<"rva23s64", RVA23S64Features>;
210+
def RVB23U64 : RISCVExperimentalProfile<"rvb23u64", RVB23U64Features>;
211+
def RVB23S64 : RISCVExperimentalProfile<"rvb23s64", RVB23S64Features>;
212+
def RVM23U32 : RISCVExperimentalProfile<"rvm23u32", RVM23U32Features>;

llvm/lib/TargetParser/RISCVISAInfo.cpp

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,10 @@ void llvm::riscvExtensionsHelp(StringMap<StringRef> DescMap) {
102102
for (const auto &P : SupportedProfiles)
103103
outs().indent(4) << P.Name << "\n";
104104

105+
outs() << "\nExperimental Profiles\n";
106+
for (const auto &P : SupportedExperimentalProfiles)
107+
outs().indent(4) << P.Name << "\n";
108+
105109
outs() << "\nUse -march to specify the target's extension.\n"
106110
"For example, clang -march=rv32i_v1p0\n";
107111
}
@@ -608,12 +612,25 @@ RISCVISAInfo::parseArchString(StringRef Arch, bool EnableExperimentalExtension,
608612
XLen = 64;
609613
} else {
610614
// Try parsing as a profile.
611-
auto I = llvm::upper_bound(SupportedProfiles, Arch,
612-
[](StringRef Arch, const RISCVProfile &Profile) {
613-
return Arch < Profile.Name;
614-
});
615-
616-
if (I != std::begin(SupportedProfiles) && Arch.starts_with((--I)->Name)) {
615+
auto ProfileCmp = [](StringRef Arch, const RISCVProfile &Profile) {
616+
return Arch < Profile.Name;
617+
};
618+
auto I = llvm::upper_bound(SupportedProfiles, Arch, ProfileCmp);
619+
bool FoundProfile = I != std::begin(SupportedProfiles) &&
620+
Arch.starts_with(std::prev(I)->Name);
621+
if (!FoundProfile) {
622+
I = llvm::upper_bound(SupportedExperimentalProfiles, Arch, ProfileCmp);
623+
FoundProfile = (I != std::begin(SupportedExperimentalProfiles) &&
624+
Arch.starts_with(std::prev(I)->Name));
625+
if (FoundProfile && !EnableExperimentalExtension) {
626+
return createStringError(errc::invalid_argument,
627+
"requires '-menable-experimental-extensions' "
628+
"for profile '" +
629+
std::prev(I)->Name + "'");
630+
}
631+
}
632+
if (FoundProfile) {
633+
--I;
617634
std::string NewArch = I->MArch.str();
618635
StringRef ArchWithoutProfile = Arch.drop_front(I->Name.size());
619636
if (!ArchWithoutProfile.empty()) {

llvm/test/CodeGen/RISCV/attributes.ll

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -265,11 +265,11 @@
265265
; RUN: llc -mtriple=riscv64 -mattr=+rva20s64 %s -o - | FileCheck --check-prefix=RVA20S64 %s
266266
; RUN: llc -mtriple=riscv64 -mattr=+rva22u64 %s -o - | FileCheck --check-prefix=RVA22U64 %s
267267
; RUN: llc -mtriple=riscv64 -mattr=+rva22s64 %s -o - | FileCheck --check-prefix=RVA22S64 %s
268-
; RUN: llc -mtriple=riscv64 -mattr=+rva23u64 %s -o - | FileCheck --check-prefix=RVA23U64 %s
269-
; RUN: llc -mtriple=riscv64 -mattr=+rva23s64 %s -o - | FileCheck --check-prefix=RVA23S64 %s
270-
; RUN: llc -mtriple=riscv64 -mattr=+rvb23u64 %s -o - | FileCheck --check-prefix=RVB23U64 %s
271-
; RUN: llc -mtriple=riscv64 -mattr=+rvb23s64 %s -o - | FileCheck --check-prefix=RVB23S64 %s
272-
; RUN: llc -mtriple=riscv32 -mattr=+rvm23u32 %s -o - | FileCheck --check-prefix=RVM23U32 %s
268+
; RUN: llc -mtriple=riscv64 -mattr=+experimental-rva23u64 %s -o - | FileCheck --check-prefix=RVA23U64 %s
269+
; RUN: llc -mtriple=riscv64 -mattr=+experimental-rva23s64 %s -o - | FileCheck --check-prefix=RVA23S64 %s
270+
; RUN: llc -mtriple=riscv64 -mattr=+experimental-rvb23u64 %s -o - | FileCheck --check-prefix=RVB23U64 %s
271+
; RUN: llc -mtriple=riscv64 -mattr=+experimental-rvb23s64 %s -o - | FileCheck --check-prefix=RVB23S64 %s
272+
; RUN: llc -mtriple=riscv32 -mattr=+experimental-rvm23u32 %s -o - | FileCheck --check-prefix=RVM23U32 %s
273273

274274
; CHECK: .attribute 4, 16
275275

llvm/unittests/TargetParser/RISCVISAInfoTest.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -726,6 +726,13 @@ TEST(ParseArchString,
726726
"duplicated standard user-level extension 'zicntr'");
727727
}
728728

729+
TEST(ParseArchString,
730+
RejectsExperimentalProfilesIfEnableExperimentalExtensionsNotSet) {
731+
EXPECT_EQ(
732+
toString(RISCVISAInfo::parseArchString("rva23u64", false).takeError()),
733+
"requires '-menable-experimental-extensions' for profile 'rva23u64'");
734+
}
735+
729736
TEST(ToFeatures, IIsDroppedAndExperimentalExtensionsArePrefixed) {
730737
auto MaybeISAInfo1 =
731738
RISCVISAInfo::parseArchString("rv64im_ztso", true, false);
@@ -1073,12 +1080,14 @@ Supported Profiles
10731080
rva20u64
10741081
rva22s64
10751082
rva22u64
1083+
rvi20u32
1084+
rvi20u64
1085+
1086+
Experimental Profiles
10761087
rva23s64
10771088
rva23u64
10781089
rvb23s64
10791090
rvb23u64
1080-
rvi20u32
1081-
rvi20u64
10821091
rvm23u32
10831092
10841093
Use -march to specify the target's extension.

0 commit comments

Comments
 (0)