Skip to content

[TableGen][RISCV] Add initial support for marking profiles as experimental #91993

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 14, 2024
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
6 changes: 5 additions & 1 deletion llvm/lib/Target/RISCV/RISCVProfiles.td
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@

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

defvar RVI20U32Features = [Feature32Bit, FeatureStdExtI];
defvar RVI20U64Features = [Feature64Bit, FeatureStdExtI];
Expand Down
13 changes: 12 additions & 1 deletion llvm/test/TableGen/riscv-target-def.td
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,19 @@ def FeatureDummy

class RISCVProfile<string name, list<SubtargetFeature> features>
: SubtargetFeature<name, "Is" # NAME, "true",
"RISC-V " # name # " profile", features>;
"RISC-V " # name # " profile", features> {
bit Experimental = false;
}
class RISCVExperimentalProfile<string name, list<SubtargetFeature> features>
: RISCVProfile<"experimental-"#name, features> {
let Experimental = true;
}

def RVI20U32 : RISCVProfile<"rvi20u32", [Feature32Bit, FeatureStdExtI]>;
def RVI20U64 : RISCVProfile<"rvi20u64", [Feature64Bit, FeatureStdExtI]>;
def ProfileDummy : RISCVProfile<"dummy", [Feature64Bit, FeatureStdExtI,
FeatureStdExtF, FeatureStdExtZidummy]>;
def RVI99U64 : RISCVExperimentalProfile<"rvi99u64", [Feature64Bit, FeatureStdExtI]>;

class RISCVProcessorModel<string n,
SchedMachineModel m,
Expand Down Expand Up @@ -139,6 +146,10 @@ def ROCKET : RISCVTuneProcessorModel<"rocket",
// CHECK-NEXT: {"rvi20u64","rv64i2p1"},
// CHECK-NEXT: };

// CHECK: static constexpr RISCVProfile SupportedExperimentalProfiles[] = {
// CHECK-NEXT: {"experimental-rvi99u64","rv64i2p1"},
// CHECK-NEXT: };

// CHECK: #endif // GET_SUPPORTED_PROFILES

// CHECK: #ifndef PROC
Expand Down
35 changes: 26 additions & 9 deletions llvm/utils/TableGen/RISCVTargetDefEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,22 +122,39 @@ static void printMArch(raw_ostream &OS, const std::vector<Record *> &Features) {
OS << LS << Ext.first << Ext.second.Major << 'p' << Ext.second.Minor;
}

static void printProfileTable(raw_ostream &OS,
const std::vector<Record *> &Profiles,
bool Experimental) {
OS << "static constexpr RISCVProfile Supported";
if (Experimental)
OS << "Experimental";
OS << "Profiles[] = {\n";

for (const Record *Rec : Profiles) {
if (Rec->getValueAsBit("Experimental") != Experimental)
continue;

OS.indent(4) << "{\"" << Rec->getValueAsString("Name") << "\",\"";
printMArch(OS, Rec->getValueAsListOfDefs("Implies"));
OS << "\"},\n";
}

OS << "};\n\n";
}

static void emitRISCVProfiles(RecordKeeper &Records, raw_ostream &OS) {
OS << "#ifdef GET_SUPPORTED_PROFILES\n";
OS << "#undef GET_SUPPORTED_PROFILES\n\n";

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

if (!Profiles.empty()) {
llvm::sort(Profiles, LessRecordFieldName());
OS << "static constexpr RISCVProfile SupportedProfiles[] = {\n";
for (const Record *Rec : Profiles) {
OS.indent(4) << "{\"" << Rec->getValueAsString("Name") << "\",\"";
printMArch(OS, Rec->getValueAsListOfDefs("Implies"));
OS << "\"},\n";
}

OS << "};\n\n";
printProfileTable(OS, Profiles, /*Experimental=*/false);
bool HasExperimentalProfiles = any_of(Profiles, [&](auto &Rec) {
return Rec->getValueAsBit("Experimental");
});
if (HasExperimentalProfiles)
printProfileTable(OS, Profiles, /*Experimental=*/true);
}

OS << "#endif // GET_SUPPORTED_PROFILES\n\n";
Expand Down
Loading