@@ -32,9 +32,9 @@ using namespace llvm;
32
32
#define DEBUG_TYPE " searchable-table-emitter"
33
33
34
34
static int64_t getAsInt (const Init *B) {
35
- if (const BitsInit *BI = dyn_cast<BitsInit>(B))
35
+ if (const auto *BI = dyn_cast<BitsInit>(B))
36
36
return *BI->convertInitializerToInt ();
37
- if (const IntInit *II = dyn_cast<IntInit>(B))
37
+ if (const auto *II = dyn_cast<IntInit>(B))
38
38
return II->getValue ();
39
39
llvm_unreachable (" Unexpected initializer" );
40
40
}
@@ -126,20 +126,20 @@ class SearchableTableEmitter {
126
126
127
127
std::string primaryRepresentation (SMLoc Loc, const GenericField &Field,
128
128
const Init *I) {
129
- if (const StringInit *SI = dyn_cast<StringInit>(I)) {
129
+ if (const auto *SI = dyn_cast<StringInit>(I)) {
130
130
if (Field.IsCode || SI->hasCodeFormat ())
131
131
return SI->getValue ().str ();
132
132
else
133
133
return SI->getAsString ();
134
- } else if (const BitsInit *BI = dyn_cast<BitsInit>(I))
134
+ } else if (const auto *BI = dyn_cast<BitsInit>(I)) {
135
135
return " 0x" + utohexstr (getAsInt (BI));
136
- else if (const BitInit *BI = dyn_cast<BitInit>(I))
136
+ } else if (const auto *BI = dyn_cast<BitInit>(I)) {
137
137
return BI->getValue () ? " true" : " false" ;
138
- else if (Field.IsIntrinsic )
138
+ } else if (Field.IsIntrinsic ) {
139
139
return " Intrinsic::" + getIntrinsic (I).EnumName .str ();
140
- else if (Field.IsInstruction )
140
+ } else if (Field.IsInstruction ) {
141
141
return I->getAsString ();
142
- else if (Field.Enum ) {
142
+ if (Field.Enum ) {
143
143
const GenericEnum::Entry *Entry =
144
144
Field.Enum ->getEntry (cast<DefInit>(I)->getDef ());
145
145
if (!Entry)
@@ -152,7 +152,7 @@ class SearchableTableEmitter {
152
152
}
153
153
154
154
bool isIntrinsic (const Init *I) {
155
- if (const DefInit *DI = dyn_cast<DefInit>(I))
155
+ if (const auto *DI = dyn_cast<DefInit>(I))
156
156
return DI->getDef ()->isSubClassOf (" Intrinsic" );
157
157
return false ;
158
158
}
@@ -174,7 +174,7 @@ class SearchableTableEmitter {
174
174
if (Ctx == TypeInTempStruct)
175
175
return " std::string" ;
176
176
return " StringRef" ;
177
- } else if (const BitsRecTy *BI = dyn_cast<BitsRecTy>(Field.RecType )) {
177
+ } else if (const auto *BI = dyn_cast<BitsRecTy>(Field.RecType )) {
178
178
unsigned NumBits = BI->getNumBits ();
179
179
if (NumBits <= 8 )
180
180
return " uint8_t" ;
@@ -190,8 +190,9 @@ class SearchableTableEmitter {
190
190
" ' of type bits is too large" );
191
191
} else if (isa<BitRecTy>(Field.RecType )) {
192
192
return " bool" ;
193
- } else if (Field.Enum || Field.IsIntrinsic || Field.IsInstruction )
193
+ } else if (Field.Enum || Field.IsIntrinsic || Field.IsInstruction ) {
194
194
return " unsigned" ;
195
+ }
195
196
PrintFatalError (Index.Loc ,
196
197
Twine (" In table '" ) + Table.Name + " ' lookup method '" +
197
198
Index.Name + " ', key field '" + Field.Name +
@@ -359,8 +360,8 @@ void SearchableTableEmitter::emitLookupFunction(const GenericTable &Table,
359
360
360
361
std::vector<std::pair<const Record *, unsigned >> Entries;
361
362
Entries.reserve (Table.Entries .size ());
362
- for (unsigned i = 0 ; i < Table.Entries . size (); ++i )
363
- Entries.emplace_back (Table. Entries [i], i );
363
+ for (auto [Idx, TblEntry] : enumerate( Table.Entries ) )
364
+ Entries.emplace_back (TblEntry, Idx );
364
365
365
366
llvm::stable_sort (Entries,
366
367
[&](const std::pair<const Record *, unsigned > &LHS,
@@ -369,19 +370,19 @@ void SearchableTableEmitter::emitLookupFunction(const GenericTable &Table,
369
370
});
370
371
371
372
IndexRowsStorage.reserve (Entries.size ());
372
- for (const auto &Entry : Entries) {
373
- IndexRowsStorage.push_back (Entry. first );
373
+ for (const auto &[EntryRec, EntryIndex] : Entries) {
374
+ IndexRowsStorage.push_back (EntryRec );
374
375
375
376
OS << " { " ;
376
377
ListSeparator LS;
377
378
for (const auto &Field : Index.Fields ) {
378
379
std::string Repr = primaryRepresentation (
379
- Index.Loc , Field, Entry. first ->getValueInit (Field.Name ));
380
+ Index.Loc , Field, EntryRec ->getValueInit (Field.Name ));
380
381
if (isa<StringRecTy>(Field.RecType ))
381
382
Repr = StringRef (Repr).upper ();
382
383
OS << LS << Repr;
383
384
}
384
- OS << " , " << Entry. second << " },\n " ;
385
+ OS << " , " << EntryIndex << " },\n " ;
385
386
}
386
387
387
388
OS << " };\n\n " ;
@@ -398,8 +399,8 @@ void SearchableTableEmitter::emitLookupFunction(const GenericTable &Table,
398
399
Index.Fields [0 ].IsInstruction )) {
399
400
int64_t FirstKeyVal = getNumericKey (Index, IndexRows[0 ]);
400
401
IsContiguous = true ;
401
- for (unsigned i = 0 ; i < IndexRows. size (); ++i ) {
402
- if (getNumericKey (Index, IndexRows[i] ) != ( FirstKeyVal + i) ) {
402
+ for (const auto &[Idx, IndexRow] : enumerate(IndexRows) ) {
403
+ if (getNumericKey (Index, IndexRow ) != FirstKeyVal + ( int64_t )Idx ) {
403
404
IsContiguous = false ;
404
405
break ;
405
406
}
@@ -509,9 +510,9 @@ void SearchableTableEmitter::emitLookupFunction(const GenericTable &Table,
509
510
OS << " ||\n Key." << Field.Name << " != Idx->" << Field.Name ;
510
511
}
511
512
512
- if (ShouldReturnRange)
513
+ if (ShouldReturnRange) {
513
514
OS << " return llvm::make_range(It.first, It.second);\n " ;
514
- else if (IsPrimary) {
515
+ } else if (IsPrimary) {
515
516
OS << " )\n return nullptr;\n\n " ;
516
517
OS << " return &*Idx;\n " ;
517
518
} else {
@@ -557,8 +558,7 @@ void SearchableTableEmitter::emitGenericTable(const GenericTable &Table,
557
558
558
559
// The primary data table contains all the fields defined for this map.
559
560
OS << " constexpr " << Table.CppTypeName << " " << Table.Name << " [] = {\n " ;
560
- for (unsigned i = 0 ; i < Table.Entries .size (); ++i) {
561
- const Record *Entry = Table.Entries [i];
561
+ for (const auto &[Idx, Entry] : enumerate(Table.Entries )) {
562
562
OS << " { " ;
563
563
564
564
ListSeparator LS;
@@ -567,7 +567,7 @@ void SearchableTableEmitter::emitGenericTable(const GenericTable &Table,
567
567
<< primaryRepresentation (Table.Locs [0 ], Field,
568
568
Entry->getValueInit (Field.Name ));
569
569
570
- OS << " }, // " << i << " \n " ;
570
+ OS << " }, // " << Idx << " \n " ;
571
571
}
572
572
OS << " };\n " ;
573
573
0 commit comments