@@ -89,12 +89,12 @@ static void emitRISCVExtensions(RecordKeeper &Records, raw_ostream &OS) {
8989//
9090// This is almost the same as RISCVFeatures::parseFeatureBits, except that we
9191// get feature name from feature records instead of feature bits.
92- static void printMArch (raw_ostream &OS, const Record &Rec ) {
92+ static void printMArch (raw_ostream &OS, const std::vector< Record *> &Features ) {
9393 RISCVISAUtils::OrderedExtensionMap Extensions;
9494 unsigned XLen = 0 ;
9595
9696 // Convert features to FeatureVector.
97- for (auto *Feature : Rec. getValueAsListOfDefs ( " Features" ) ) {
97+ for (auto *Feature : Features) {
9898 StringRef FeatureName = getExtensionName (Feature);
9999 if (Feature->isSubClassOf (" RISCVExtension" )) {
100100 unsigned Major = Feature->getValueAsInt (" MajorVersion" );
@@ -118,22 +118,39 @@ static void printMArch(raw_ostream &OS, const Record &Rec) {
118118 OS << LS << Ext.first << Ext.second .Major << ' p' << Ext.second .Minor ;
119119}
120120
121+ static void emitRISCVProfiles (RecordKeeper &Records, raw_ostream &OS) {
122+ OS << " #ifdef GET_SUPPORTED_PROFILES\n " ;
123+ OS << " #undef GET_SUPPORTED_PROFILES\n\n " ;
124+
125+ OS << " static constexpr RISCVProfile SupportedProfiles[] = {\n " ;
126+
127+ for (const Record *Rec : Records.getAllDerivedDefinitions (" RISCVProfile" )) {
128+ OS.indent (4 ) << " {\" " << Rec->getValueAsString (" Name" ) << " \" ,\" " ;
129+ printMArch (OS, Rec->getValueAsListOfDefs (" Implies" ));
130+ OS << " \" },\n " ;
131+ }
132+
133+ OS << " };\n\n " ;
134+
135+ OS << " #endif // GET_SUPPORTED_PROFILES\n\n " ;
136+ }
137+
121138static void emitRISCVProcs (RecordKeeper &RK, raw_ostream &OS) {
122139 OS << " #ifndef PROC\n "
123140 << " #define PROC(ENUM, NAME, DEFAULT_MARCH, FAST_UNALIGNED_ACCESS)\n "
124141 << " #endif\n\n " ;
125142
126143 // Iterate on all definition records.
127144 for (const Record *Rec : RK.getAllDerivedDefinitions (" RISCVProcessorModel" )) {
128- bool FastScalarUnalignedAccess =
129- any_of (Rec->getValueAsListOfDefs (" Features" ), [&](auto &Feature) {
130- return Feature->getValueAsString (" Name" ) == " unaligned-scalar-mem" ;
131- });
145+ const std::vector<Record *> &Features =
146+ Rec->getValueAsListOfDefs (" Features" );
147+ bool FastScalarUnalignedAccess = any_of (Features, [&](auto &Feature) {
148+ return Feature->getValueAsString (" Name" ) == " unaligned-scalar-mem" ;
149+ });
132150
133- bool FastVectorUnalignedAccess =
134- any_of (Rec->getValueAsListOfDefs (" Features" ), [&](auto &Feature) {
135- return Feature->getValueAsString (" Name" ) == " unaligned-vector-mem" ;
136- });
151+ bool FastVectorUnalignedAccess = any_of (Features, [&](auto &Feature) {
152+ return Feature->getValueAsString (" Name" ) == " unaligned-vector-mem" ;
153+ });
137154
138155 bool FastUnalignedAccess =
139156 FastScalarUnalignedAccess && FastVectorUnalignedAccess;
@@ -145,7 +162,7 @@ static void emitRISCVProcs(RecordKeeper &RK, raw_ostream &OS) {
145162
146163 // Compute MArch from features if we don't specify it.
147164 if (MArch.empty ())
148- printMArch (OS, *Rec );
165+ printMArch (OS, Features );
149166 else
150167 OS << MArch;
151168 OS << " \" }, " << FastUnalignedAccess << " )\n " ;
@@ -167,6 +184,7 @@ static void emitRISCVProcs(RecordKeeper &RK, raw_ostream &OS) {
167184
168185static void EmitRISCVTargetDef (RecordKeeper &RK, raw_ostream &OS) {
169186 emitRISCVExtensions (RK, OS);
187+ emitRISCVProfiles (RK, OS);
170188 emitRISCVProcs (RK, OS);
171189}
172190
0 commit comments