Skip to content

Commit e5a277b

Browse files
authored
[TableGen][RISCV] Add initial support for marking profiles as experimental (#91993)
This is just the TableGen-side changes, split out as the minimal testable unit. It doesn't yet transition RVA23 and friends to be experimental (and add the necessary other changes for this to work). Although choosing not to emit the SupportedExperimentalProfiles array if no experimental profiles are present isn't consistent with what we do for experimental extensions, we need to do this in order to avoid adding a warning for the empty array when building LLVM for as long as we don't have any experimental profiles defined.
1 parent cff9e77 commit e5a277b

File tree

3 files changed

+43
-11
lines changed

3 files changed

+43
-11
lines changed

llvm/lib/Target/RISCV/RISCVProfiles.td

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@
88

99
class RISCVProfile<string name, list<SubtargetFeature> features>
1010
: SubtargetFeature<name, "Is" # NAME, "true",
11-
"RISC-V " # name # " profile", features>;
11+
"RISC-V " # name # " profile", features> {
12+
// Indicates if the profile is not yet ratified, so should be treated as
13+
// experimental.
14+
bit Experimental = false;
15+
}
1216

1317
defvar RVI20U32Features = [Feature32Bit, FeatureStdExtI];
1418
defvar RVI20U64Features = [Feature64Bit, FeatureStdExtI];

llvm/test/TableGen/riscv-target-def.td

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,19 @@ def FeatureDummy
5353

5454
class RISCVProfile<string name, list<SubtargetFeature> features>
5555
: SubtargetFeature<name, "Is" # NAME, "true",
56-
"RISC-V " # name # " profile", features>;
56+
"RISC-V " # name # " profile", features> {
57+
bit Experimental = false;
58+
}
59+
class RISCVExperimentalProfile<string name, list<SubtargetFeature> features>
60+
: RISCVProfile<"experimental-"#name, features> {
61+
let Experimental = true;
62+
}
5763

5864
def RVI20U32 : RISCVProfile<"rvi20u32", [Feature32Bit, FeatureStdExtI]>;
5965
def RVI20U64 : RISCVProfile<"rvi20u64", [Feature64Bit, FeatureStdExtI]>;
6066
def ProfileDummy : RISCVProfile<"dummy", [Feature64Bit, FeatureStdExtI,
6167
FeatureStdExtF, FeatureStdExtZidummy]>;
68+
def RVI99U64 : RISCVExperimentalProfile<"rvi99u64", [Feature64Bit, FeatureStdExtI]>;
6269

6370
class RISCVProcessorModel<string n,
6471
SchedMachineModel m,
@@ -139,6 +146,10 @@ def ROCKET : RISCVTuneProcessorModel<"rocket",
139146
// CHECK-NEXT: {"rvi20u64","rv64i2p1"},
140147
// CHECK-NEXT: };
141148

149+
// CHECK: static constexpr RISCVProfile SupportedExperimentalProfiles[] = {
150+
// CHECK-NEXT: {"experimental-rvi99u64","rv64i2p1"},
151+
// CHECK-NEXT: };
152+
142153
// CHECK: #endif // GET_SUPPORTED_PROFILES
143154

144155
// CHECK: #ifndef PROC

llvm/utils/TableGen/RISCVTargetDefEmitter.cpp

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -122,22 +122,39 @@ static void printMArch(raw_ostream &OS, const std::vector<Record *> &Features) {
122122
OS << LS << Ext.first << Ext.second.Major << 'p' << Ext.second.Minor;
123123
}
124124

125+
static void printProfileTable(raw_ostream &OS,
126+
const std::vector<Record *> &Profiles,
127+
bool Experimental) {
128+
OS << "static constexpr RISCVProfile Supported";
129+
if (Experimental)
130+
OS << "Experimental";
131+
OS << "Profiles[] = {\n";
132+
133+
for (const Record *Rec : Profiles) {
134+
if (Rec->getValueAsBit("Experimental") != Experimental)
135+
continue;
136+
137+
OS.indent(4) << "{\"" << Rec->getValueAsString("Name") << "\",\"";
138+
printMArch(OS, Rec->getValueAsListOfDefs("Implies"));
139+
OS << "\"},\n";
140+
}
141+
142+
OS << "};\n\n";
143+
}
144+
125145
static void emitRISCVProfiles(RecordKeeper &Records, raw_ostream &OS) {
126146
OS << "#ifdef GET_SUPPORTED_PROFILES\n";
127147
OS << "#undef GET_SUPPORTED_PROFILES\n\n";
128148

129149
auto Profiles = Records.getAllDerivedDefinitionsIfDefined("RISCVProfile");
130150

131151
if (!Profiles.empty()) {
132-
llvm::sort(Profiles, LessRecordFieldName());
133-
OS << "static constexpr RISCVProfile SupportedProfiles[] = {\n";
134-
for (const Record *Rec : Profiles) {
135-
OS.indent(4) << "{\"" << Rec->getValueAsString("Name") << "\",\"";
136-
printMArch(OS, Rec->getValueAsListOfDefs("Implies"));
137-
OS << "\"},\n";
138-
}
139-
140-
OS << "};\n\n";
152+
printProfileTable(OS, Profiles, /*Experimental=*/false);
153+
bool HasExperimentalProfiles = any_of(Profiles, [&](auto &Rec) {
154+
return Rec->getValueAsBit("Experimental");
155+
});
156+
if (HasExperimentalProfiles)
157+
printProfileTable(OS, Profiles, /*Experimental=*/true);
141158
}
142159

143160
OS << "#endif // GET_SUPPORTED_PROFILES\n\n";

0 commit comments

Comments
 (0)