[llvm] [TableGen] Migrate LLVM RISCVTarget/VT Emitters to const RecordKeeper (PR #107697)
Rahul Joshi via llvm-commits
llvm-commits at lists.llvm.org
Sat Sep 7 05:40:12 PDT 2024
https://github.com/jurahul created https://github.com/llvm/llvm-project/pull/107697
None
>From fb305eec065bdc802d8789ec4525d3eb120a7903 Mon Sep 17 00:00:00 2001
From: Rahul Joshi <rjoshi at nvidia.com>
Date: Sat, 7 Sep 2024 05:38:42 -0700
Subject: [PATCH] [TableGen] Migrate LLVM RISCVTarget/VT Emitters to const
RecordKeeper
---
llvm/utils/TableGen/RISCVTargetDefEmitter.cpp | 27 +++++++++----------
llvm/utils/TableGen/VTEmitter.cpp | 7 +++--
2 files changed, 16 insertions(+), 18 deletions(-)
diff --git a/llvm/utils/TableGen/RISCVTargetDefEmitter.cpp b/llvm/utils/TableGen/RISCVTargetDefEmitter.cpp
index ae5ce32d617b47..1fbcba59f964d8 100644
--- a/llvm/utils/TableGen/RISCVTargetDefEmitter.cpp
+++ b/llvm/utils/TableGen/RISCVTargetDefEmitter.cpp
@@ -25,14 +25,14 @@ static StringRef getExtensionName(const Record *R) {
}
static void printExtensionTable(raw_ostream &OS,
- const std::vector<Record *> &Extensions,
+ ArrayRef<const Record *> Extensions,
bool Experimental) {
OS << "static const RISCVSupportedExtension Supported";
if (Experimental)
OS << "Experimental";
OS << "Extensions[] = {\n";
- for (Record *R : Extensions) {
+ for (const Record *R : Extensions) {
if (R->getValueAsBit("Experimental") != Experimental)
continue;
@@ -44,11 +44,11 @@ static void printExtensionTable(raw_ostream &OS,
OS << "};\n\n";
}
-static void emitRISCVExtensions(RecordKeeper &Records, raw_ostream &OS) {
+static void emitRISCVExtensions(const RecordKeeper &Records, raw_ostream &OS) {
OS << "#ifdef GET_SUPPORTED_EXTENSIONS\n";
OS << "#undef GET_SUPPORTED_EXTENSIONS\n\n";
- std::vector<Record *> Extensions =
+ std::vector<const Record *> Extensions =
Records.getAllDerivedDefinitionsIfDefined("RISCVExtension");
llvm::sort(Extensions, [](const Record *Rec1, const Record *Rec2) {
return getExtensionName(Rec1) < getExtensionName(Rec2);
@@ -66,7 +66,7 @@ static void emitRISCVExtensions(RecordKeeper &Records, raw_ostream &OS) {
if (!Extensions.empty()) {
OS << "\nstatic constexpr ImpliedExtsEntry ImpliedExts[] = {\n";
- for (Record *Ext : Extensions) {
+ for (const Record *Ext : Extensions) {
auto ImpliesList = Ext->getValueAsListOfDefs("Implies");
if (ImpliesList.empty())
continue;
@@ -94,12 +94,12 @@ static void emitRISCVExtensions(RecordKeeper &Records, raw_ostream &OS) {
//
// This is almost the same as RISCVFeatures::parseFeatureBits, except that we
// get feature name from feature records instead of feature bits.
-static void printMArch(raw_ostream &OS, const std::vector<Record *> &Features) {
+static void printMArch(raw_ostream &OS, ArrayRef<const Record *> Features) {
RISCVISAUtils::OrderedExtensionMap Extensions;
unsigned XLen = 0;
// Convert features to FeatureVector.
- for (auto *Feature : Features) {
+ for (const Record *Feature : Features) {
StringRef FeatureName = getExtensionName(Feature);
if (Feature->isSubClassOf("RISCVExtension")) {
unsigned Major = Feature->getValueAsInt("MajorVersion");
@@ -124,7 +124,7 @@ static void printMArch(raw_ostream &OS, const std::vector<Record *> &Features) {
}
static void printProfileTable(raw_ostream &OS,
- const std::vector<Record *> &Profiles,
+ ArrayRef<const Record *> Profiles,
bool Experimental) {
OS << "static constexpr RISCVProfile Supported";
if (Experimental)
@@ -145,7 +145,7 @@ static void printProfileTable(raw_ostream &OS,
OS << "};\n\n";
}
-static void emitRISCVProfiles(RecordKeeper &Records, raw_ostream &OS) {
+static void emitRISCVProfiles(const RecordKeeper &Records, raw_ostream &OS) {
OS << "#ifdef GET_SUPPORTED_PROFILES\n";
OS << "#undef GET_SUPPORTED_PROFILES\n\n";
@@ -163,7 +163,7 @@ static void emitRISCVProfiles(RecordKeeper &Records, raw_ostream &OS) {
OS << "#endif // GET_SUPPORTED_PROFILES\n\n";
}
-static void emitRISCVProcs(RecordKeeper &RK, raw_ostream &OS) {
+static void emitRISCVProcs(const RecordKeeper &RK, raw_ostream &OS) {
OS << "#ifndef PROC\n"
<< "#define PROC(ENUM, NAME, DEFAULT_MARCH, FAST_SCALAR_UNALIGN"
<< ", FAST_VECTOR_UNALIGN)\n"
@@ -210,9 +210,8 @@ static void emitRISCVProcs(RecordKeeper &RK, raw_ostream &OS) {
OS << "\n#undef TUNE_PROC\n";
}
-static void emitRISCVExtensionBitmask(RecordKeeper &RK, raw_ostream &OS) {
-
- std::vector<Record *> Extensions =
+static void emitRISCVExtensionBitmask(const RecordKeeper &RK, raw_ostream &OS) {
+ std::vector<const Record *> Extensions =
RK.getAllDerivedDefinitionsIfDefined("RISCVExtensionBitmask");
llvm::sort(Extensions, [](const Record *Rec1, const Record *Rec2) {
return getExtensionName(Rec1) < getExtensionName(Rec2);
@@ -245,7 +244,7 @@ static void emitRISCVExtensionBitmask(RecordKeeper &RK, raw_ostream &OS) {
OS << "#endif\n";
}
-static void EmitRISCVTargetDef(RecordKeeper &RK, raw_ostream &OS) {
+static void EmitRISCVTargetDef(const RecordKeeper &RK, raw_ostream &OS) {
emitRISCVExtensions(RK, OS);
emitRISCVProfiles(RK, OS);
emitRISCVProcs(RK, OS);
diff --git a/llvm/utils/TableGen/VTEmitter.cpp b/llvm/utils/TableGen/VTEmitter.cpp
index 6cfd29e710829f..8f4bcd5fccc73d 100644
--- a/llvm/utils/TableGen/VTEmitter.cpp
+++ b/llvm/utils/TableGen/VTEmitter.cpp
@@ -19,10 +19,10 @@ namespace {
class VTEmitter {
private:
- RecordKeeper &Records;
+ const RecordKeeper &Records;
public:
- VTEmitter(RecordKeeper &R) : Records(R) {}
+ VTEmitter(const RecordKeeper &R) : Records(R) {}
void run(raw_ostream &OS);
};
@@ -91,8 +91,7 @@ void VTEmitter::run(raw_ostream &OS) {
emitSourceFileHeader("ValueTypes Source Fragment", OS, Records);
std::vector<const Record *> VTsByNumber{512};
- auto ValueTypes = Records.getAllDerivedDefinitions("ValueType");
- for (auto *VT : ValueTypes) {
+ for (auto *VT : Records.getAllDerivedDefinitions("ValueType")) {
auto Number = VT->getValueAsInt("Value");
assert(0 <= Number && Number < (int)VTsByNumber.size() &&
"ValueType should be uint16_t");
More information about the llvm-commits
mailing list