@@ -31,9 +31,9 @@ using namespace llvm;
31
31
#define DEBUG_TYPE " searchable-table-emitter"
32
32
33
33
static int64_t getAsInt (const Init *B) {
34
- if (const BitsInit *BI = dyn_cast<BitsInit>(B))
34
+ if (const auto *BI = dyn_cast<BitsInit>(B))
35
35
return *BI->convertInitializerToInt ();
36
- if (const IntInit *II = dyn_cast<IntInit>(B))
36
+ if (const auto *II = dyn_cast<IntInit>(B))
37
37
return II->getValue ();
38
38
llvm_unreachable (" Unexpected initializer" );
39
39
}
@@ -115,20 +115,20 @@ class SearchableTableEmitter {
115
115
116
116
std::string primaryRepresentation (SMLoc Loc, const GenericField &Field,
117
117
const Init *I) {
118
- if (const StringInit *SI = dyn_cast<StringInit>(I)) {
118
+ if (const auto *SI = dyn_cast<StringInit>(I)) {
119
119
if (Field.IsCode || SI->hasCodeFormat ())
120
120
return SI->getValue ().str ();
121
121
else
122
122
return SI->getAsString ();
123
- } else if (const BitsInit *BI = dyn_cast<BitsInit>(I))
123
+ } else if (const auto *BI = dyn_cast<BitsInit>(I)) {
124
124
return " 0x" + utohexstr (getAsInt (BI));
125
- else if (const BitInit *BI = dyn_cast<BitInit>(I))
125
+ } else if (const auto *BI = dyn_cast<BitInit>(I)) {
126
126
return BI->getValue () ? " true" : " false" ;
127
- else if (Field.IsIntrinsic )
127
+ } else if (Field.IsIntrinsic ) {
128
128
return " Intrinsic::" + getIntrinsic (I).EnumName .str ();
129
- else if (Field.IsInstruction )
129
+ } else if (Field.IsInstruction ) {
130
130
return I->getAsString ();
131
- else if (Field.Enum ) {
131
+ } else if (Field.Enum ) {
132
132
auto *Entry = Field.Enum ->EntryMap [cast<DefInit>(I)->getDef ()];
133
133
if (!Entry)
134
134
PrintFatalError (Loc,
@@ -140,7 +140,7 @@ class SearchableTableEmitter {
140
140
}
141
141
142
142
bool isIntrinsic (const Init *I) {
143
- if (const DefInit *DI = dyn_cast<DefInit>(I))
143
+ if (const auto *DI = dyn_cast<DefInit>(I))
144
144
return DI->getDef ()->isSubClassOf (" Intrinsic" );
145
145
return false ;
146
146
}
@@ -162,7 +162,7 @@ class SearchableTableEmitter {
162
162
if (Ctx == TypeInTempStruct)
163
163
return " std::string" ;
164
164
return " StringRef" ;
165
- } else if (const BitsRecTy *BI = dyn_cast<BitsRecTy>(Field.RecType )) {
165
+ } else if (const auto *BI = dyn_cast<BitsRecTy>(Field.RecType )) {
166
166
unsigned NumBits = BI->getNumBits ();
167
167
if (NumBits <= 8 )
168
168
return " uint8_t" ;
@@ -178,8 +178,9 @@ class SearchableTableEmitter {
178
178
" ' of type bits is too large" );
179
179
} else if (isa<BitRecTy>(Field.RecType )) {
180
180
return " bool" ;
181
- } else if (Field.Enum || Field.IsIntrinsic || Field.IsInstruction )
181
+ } else if (Field.Enum || Field.IsIntrinsic || Field.IsInstruction ) {
182
182
return " unsigned" ;
183
+ }
183
184
PrintFatalError (Index.Loc ,
184
185
Twine (" In table '" ) + Table.Name + " ' lookup method '" +
185
186
Index.Name + " ', key field '" + Field.Name +
@@ -346,8 +347,8 @@ void SearchableTableEmitter::emitLookupFunction(const GenericTable &Table,
346
347
347
348
std::vector<std::pair<const Record *, unsigned >> Entries;
348
349
Entries.reserve (Table.Entries .size ());
349
- for (unsigned i = 0 ; i < Table.Entries . size (); ++i )
350
- Entries.emplace_back (Table. Entries [i], i );
350
+ for (auto [Idx, TblEntry] : enumerate( Table.Entries ) )
351
+ Entries.emplace_back (TblEntry, Idx );
351
352
352
353
llvm::stable_sort (Entries,
353
354
[&](const std::pair<const Record *, unsigned > &LHS,
@@ -356,19 +357,19 @@ void SearchableTableEmitter::emitLookupFunction(const GenericTable &Table,
356
357
});
357
358
358
359
IndexRowsStorage.reserve (Entries.size ());
359
- for (const auto &Entry : Entries) {
360
- IndexRowsStorage.push_back (Entry. first );
360
+ for (const auto &[EntryRec, EntryIndex] : Entries) {
361
+ IndexRowsStorage.push_back (EntryRec );
361
362
362
363
OS << " { " ;
363
364
ListSeparator LS;
364
365
for (const auto &Field : Index.Fields ) {
365
366
std::string Repr = primaryRepresentation (
366
- Index.Loc , Field, Entry. first ->getValueInit (Field.Name ));
367
+ Index.Loc , Field, EntryRec ->getValueInit (Field.Name ));
367
368
if (isa<StringRecTy>(Field.RecType ))
368
369
Repr = StringRef (Repr).upper ();
369
370
OS << LS << Repr;
370
371
}
371
- OS << " , " << Entry. second << " },\n " ;
372
+ OS << " , " << EntryIndex << " },\n " ;
372
373
}
373
374
374
375
OS << " };\n\n " ;
@@ -385,8 +386,8 @@ void SearchableTableEmitter::emitLookupFunction(const GenericTable &Table,
385
386
Index.Fields [0 ].IsInstruction )) {
386
387
int64_t FirstKeyVal = getNumericKey (Index, IndexRows[0 ]);
387
388
IsContiguous = true ;
388
- for (unsigned i = 0 ; i < IndexRows. size (); ++i ) {
389
- if (getNumericKey (Index, IndexRows[i] ) != ( FirstKeyVal + i) ) {
389
+ for (const auto &[Idx, IndexRow] : enumerate(IndexRows) ) {
390
+ if (getNumericKey (Index, IndexRow ) != FirstKeyVal + ( int64_t )Idx ) {
390
391
IsContiguous = false ;
391
392
break ;
392
393
}
@@ -496,9 +497,9 @@ void SearchableTableEmitter::emitLookupFunction(const GenericTable &Table,
496
497
OS << " ||\n Key." << Field.Name << " != Idx->" << Field.Name ;
497
498
}
498
499
499
- if (ShouldReturnRange)
500
+ if (ShouldReturnRange) {
500
501
OS << " return llvm::make_range(It.first, It.second);\n " ;
501
- else if (IsPrimary) {
502
+ } else if (IsPrimary) {
502
503
OS << " )\n return nullptr;\n\n " ;
503
504
OS << " return &*Idx;\n " ;
504
505
} else {
@@ -544,8 +545,7 @@ void SearchableTableEmitter::emitGenericTable(const GenericTable &Table,
544
545
545
546
// The primary data table contains all the fields defined for this map.
546
547
OS << " constexpr " << Table.CppTypeName << " " << Table.Name << " [] = {\n " ;
547
- for (unsigned i = 0 ; i < Table.Entries .size (); ++i) {
548
- const Record *Entry = Table.Entries [i];
548
+ for (const auto &[Idx, Entry] : enumerate(Table.Entries )) {
549
549
OS << " { " ;
550
550
551
551
ListSeparator LS;
@@ -554,7 +554,7 @@ void SearchableTableEmitter::emitGenericTable(const GenericTable &Table,
554
554
<< primaryRepresentation (Table.Locs [0 ], Field,
555
555
Entry->getValueInit (Field.Name ));
556
556
557
- OS << " }, // " << i << " \n " ;
557
+ OS << " }, // " << Idx << " \n " ;
558
558
}
559
559
OS << " };\n " ;
560
560
0 commit comments