Skip to content

Commit 4ea6552

Browse files
authored
[NFC][TableGen] Migrate LLVM RISCVTarget/VT Emitters to const RecordKeeper (#107697)
Migrate LLVM RISCVTarget/VT Emitters to const RecordKeeper.
1 parent 0f1bc5d commit 4ea6552

File tree

2 files changed

+16
-18
lines changed

2 files changed

+16
-18
lines changed

llvm/utils/TableGen/RISCVTargetDefEmitter.cpp

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ static StringRef getExtensionName(const Record *R) {
2525
}
2626

2727
static void printExtensionTable(raw_ostream &OS,
28-
const std::vector<Record *> &Extensions,
28+
ArrayRef<const Record *> Extensions,
2929
bool Experimental) {
3030
OS << "static const RISCVSupportedExtension Supported";
3131
if (Experimental)
3232
OS << "Experimental";
3333
OS << "Extensions[] = {\n";
3434

35-
for (Record *R : Extensions) {
35+
for (const Record *R : Extensions) {
3636
if (R->getValueAsBit("Experimental") != Experimental)
3737
continue;
3838

@@ -44,11 +44,11 @@ static void printExtensionTable(raw_ostream &OS,
4444
OS << "};\n\n";
4545
}
4646

47-
static void emitRISCVExtensions(RecordKeeper &Records, raw_ostream &OS) {
47+
static void emitRISCVExtensions(const RecordKeeper &Records, raw_ostream &OS) {
4848
OS << "#ifdef GET_SUPPORTED_EXTENSIONS\n";
4949
OS << "#undef GET_SUPPORTED_EXTENSIONS\n\n";
5050

51-
std::vector<Record *> Extensions =
51+
std::vector<const Record *> Extensions =
5252
Records.getAllDerivedDefinitionsIfDefined("RISCVExtension");
5353
llvm::sort(Extensions, [](const Record *Rec1, const Record *Rec2) {
5454
return getExtensionName(Rec1) < getExtensionName(Rec2);
@@ -66,7 +66,7 @@ static void emitRISCVExtensions(RecordKeeper &Records, raw_ostream &OS) {
6666

6767
if (!Extensions.empty()) {
6868
OS << "\nstatic constexpr ImpliedExtsEntry ImpliedExts[] = {\n";
69-
for (Record *Ext : Extensions) {
69+
for (const Record *Ext : Extensions) {
7070
auto ImpliesList = Ext->getValueAsListOfDefs("Implies");
7171
if (ImpliesList.empty())
7272
continue;
@@ -94,12 +94,12 @@ static void emitRISCVExtensions(RecordKeeper &Records, raw_ostream &OS) {
9494
//
9595
// This is almost the same as RISCVFeatures::parseFeatureBits, except that we
9696
// get feature name from feature records instead of feature bits.
97-
static void printMArch(raw_ostream &OS, const std::vector<Record *> &Features) {
97+
static void printMArch(raw_ostream &OS, ArrayRef<const Record *> Features) {
9898
RISCVISAUtils::OrderedExtensionMap Extensions;
9999
unsigned XLen = 0;
100100

101101
// Convert features to FeatureVector.
102-
for (auto *Feature : Features) {
102+
for (const Record *Feature : Features) {
103103
StringRef FeatureName = getExtensionName(Feature);
104104
if (Feature->isSubClassOf("RISCVExtension")) {
105105
unsigned Major = Feature->getValueAsInt("MajorVersion");
@@ -124,7 +124,7 @@ static void printMArch(raw_ostream &OS, const std::vector<Record *> &Features) {
124124
}
125125

126126
static void printProfileTable(raw_ostream &OS,
127-
const std::vector<Record *> &Profiles,
127+
ArrayRef<const Record *> Profiles,
128128
bool Experimental) {
129129
OS << "static constexpr RISCVProfile Supported";
130130
if (Experimental)
@@ -145,7 +145,7 @@ static void printProfileTable(raw_ostream &OS,
145145
OS << "};\n\n";
146146
}
147147

148-
static void emitRISCVProfiles(RecordKeeper &Records, raw_ostream &OS) {
148+
static void emitRISCVProfiles(const RecordKeeper &Records, raw_ostream &OS) {
149149
OS << "#ifdef GET_SUPPORTED_PROFILES\n";
150150
OS << "#undef GET_SUPPORTED_PROFILES\n\n";
151151

@@ -163,7 +163,7 @@ static void emitRISCVProfiles(RecordKeeper &Records, raw_ostream &OS) {
163163
OS << "#endif // GET_SUPPORTED_PROFILES\n\n";
164164
}
165165

166-
static void emitRISCVProcs(RecordKeeper &RK, raw_ostream &OS) {
166+
static void emitRISCVProcs(const RecordKeeper &RK, raw_ostream &OS) {
167167
OS << "#ifndef PROC\n"
168168
<< "#define PROC(ENUM, NAME, DEFAULT_MARCH, FAST_SCALAR_UNALIGN"
169169
<< ", FAST_VECTOR_UNALIGN)\n"
@@ -210,9 +210,8 @@ static void emitRISCVProcs(RecordKeeper &RK, raw_ostream &OS) {
210210
OS << "\n#undef TUNE_PROC\n";
211211
}
212212

213-
static void emitRISCVExtensionBitmask(RecordKeeper &RK, raw_ostream &OS) {
214-
215-
std::vector<Record *> Extensions =
213+
static void emitRISCVExtensionBitmask(const RecordKeeper &RK, raw_ostream &OS) {
214+
std::vector<const Record *> Extensions =
216215
RK.getAllDerivedDefinitionsIfDefined("RISCVExtensionBitmask");
217216
llvm::sort(Extensions, [](const Record *Rec1, const Record *Rec2) {
218217
return getExtensionName(Rec1) < getExtensionName(Rec2);
@@ -245,7 +244,7 @@ static void emitRISCVExtensionBitmask(RecordKeeper &RK, raw_ostream &OS) {
245244
OS << "#endif\n";
246245
}
247246

248-
static void EmitRISCVTargetDef(RecordKeeper &RK, raw_ostream &OS) {
247+
static void EmitRISCVTargetDef(const RecordKeeper &RK, raw_ostream &OS) {
249248
emitRISCVExtensions(RK, OS);
250249
emitRISCVProfiles(RK, OS);
251250
emitRISCVProcs(RK, OS);

llvm/utils/TableGen/VTEmitter.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ namespace {
1919

2020
class VTEmitter {
2121
private:
22-
RecordKeeper &Records;
22+
const RecordKeeper &Records;
2323

2424
public:
25-
VTEmitter(RecordKeeper &R) : Records(R) {}
25+
VTEmitter(const RecordKeeper &R) : Records(R) {}
2626

2727
void run(raw_ostream &OS);
2828
};
@@ -91,8 +91,7 @@ void VTEmitter::run(raw_ostream &OS) {
9191
emitSourceFileHeader("ValueTypes Source Fragment", OS, Records);
9292

9393
std::vector<const Record *> VTsByNumber{512};
94-
auto ValueTypes = Records.getAllDerivedDefinitions("ValueType");
95-
for (auto *VT : ValueTypes) {
94+
for (auto *VT : Records.getAllDerivedDefinitions("ValueType")) {
9695
auto Number = VT->getValueAsInt("Value");
9796
assert(0 <= Number && Number < (int)VTsByNumber.size() &&
9897
"ValueType should be uint16_t");

0 commit comments

Comments
 (0)