Skip to content

Commit 7341c96

Browse files
committed
[RISCV][TableGen] Generate RISCVTargetParser.inc from the new RISCVExtension tblgen information.
Instead of using RISCVISAInfo's extension information, use the extension found in tblgen after llvm#89326. We still need to use RISCVISAInfo code to get the sorting rules for the ISA string. The ISA string we generate now is not quite the same extension we had before. No implied extensions are included in the generate string unless they are explicitly listed in RISCVProcessors.td. This primarily affects Zicsr being implied by F, V implying Zve*, and Zvl*b implying a smaller Zvl*b. All of these implication should be picked up when the string is used by the frontend. The benefit is that we get a more manageable ISA string for humans to deal with. This is a step towards generating RISCVISAInfo's extension list from tblgen.
1 parent 4b78a1a commit 7341c96

File tree

1 file changed

+23
-20
lines changed

1 file changed

+23
-20
lines changed

llvm/utils/TableGen/RISCVTargetDefEmitter.cpp

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,34 +17,34 @@
1717

1818
using namespace llvm;
1919

20-
using ISAInfoTy = llvm::Expected<std::unique_ptr<RISCVISAInfo>>;
21-
2220
// We can generate march string from target features as what has been described
2321
// in RISC-V ISA specification (version 20191213) 'Chapter 27. ISA Extension
2422
// Naming Conventions'.
2523
//
2624
// This is almost the same as RISCVFeatures::parseFeatureBits, except that we
2725
// get feature name from feature records instead of feature bits.
28-
static std::string getMArch(const Record &Rec) {
29-
std::vector<std::string> FeatureVector;
26+
static void printMArch(raw_ostream &OS, const Record &Rec) {
27+
std::map<std::string, std::pair<unsigned, unsigned>,
28+
RISCVISAInfo::ExtensionComparator>
29+
Extensions;
3030
unsigned XLen = 32;
3131

3232
// Convert features to FeatureVector.
3333
for (auto *Feature : Rec.getValueAsListOfDefs("Features")) {
3434
StringRef FeatureName = Feature->getValueAsString("Name");
35-
if (llvm::RISCVISAInfo::isSupportedExtensionFeature(FeatureName))
36-
FeatureVector.push_back((Twine("+") + FeatureName).str());
37-
else if (FeatureName == "64bit")
35+
if (Feature->isSubClassOf("RISCVExtension")) {
36+
unsigned Major = Feature->getValueAsInt("MajorVersion");
37+
unsigned Minor = Feature->getValueAsInt("MinorVersion");
38+
Extensions.try_emplace(FeatureName.str(), Major, Minor);
39+
} else if (FeatureName == "64bit")
3840
XLen = 64;
3941
}
4042

41-
ISAInfoTy ISAInfo = llvm::RISCVISAInfo::parseFeatures(XLen, FeatureVector);
42-
if (!ISAInfo)
43-
report_fatal_error("Invalid features");
43+
OS << "rv" << XLen;
4444

45-
// RISCVISAInfo::toString will generate a march string with all the extensions
46-
// we have added to it.
47-
return (*ISAInfo)->toString();
45+
ListSeparator LS("_");
46+
for (auto const &Ext : Extensions)
47+
OS << LS << Ext.first << Ext.second.first << 'p' << Ext.second.second;
4848
}
4949

5050
static void EmitRISCVTargetDef(RecordKeeper &RK, raw_ostream &OS) {
@@ -54,12 +54,6 @@ static void EmitRISCVTargetDef(RecordKeeper &RK, raw_ostream &OS) {
5454

5555
// Iterate on all definition records.
5656
for (const Record *Rec : RK.getAllDerivedDefinitions("RISCVProcessorModel")) {
57-
std::string MArch = Rec->getValueAsString("DefaultMarch").str();
58-
59-
// Compute MArch from features if we don't specify it.
60-
if (MArch.empty())
61-
MArch = getMArch(*Rec);
62-
6357
bool FastScalarUnalignedAccess =
6458
any_of(Rec->getValueAsListOfDefs("Features"), [&](auto &Feature) {
6559
return Feature->getValueAsString("Name") == "unaligned-scalar-mem";
@@ -75,7 +69,16 @@ static void EmitRISCVTargetDef(RecordKeeper &RK, raw_ostream &OS) {
7569

7670
OS << "PROC(" << Rec->getName() << ", "
7771
<< "{\"" << Rec->getValueAsString("Name") << "\"}, "
78-
<< "{\"" << MArch << "\"}, " << FastUnalignedAccess << ")\n";
72+
<< "{\"";
73+
74+
StringRef MArch = Rec->getValueAsString("DefaultMarch");
75+
76+
// Compute MArch from features if we don't specify it.
77+
if (MArch.empty())
78+
printMArch(OS, *Rec);
79+
else
80+
OS << MArch;
81+
OS << "\"}, " << FastUnalignedAccess << ")\n";
7982
}
8083
OS << "\n#undef PROC\n";
8184
OS << "\n";

0 commit comments

Comments
 (0)