@@ -32,9 +32,9 @@ using namespace llvm;
3232#define DEBUG_TYPE " searchable-table-emitter"
3333
3434static int64_t getAsInt (const Init *B) {
35- if (const BitsInit *BI = dyn_cast<BitsInit>(B))
35+ if (const auto *BI = dyn_cast<BitsInit>(B))
3636 return *BI->convertInitializerToInt ();
37- if (const IntInit *II = dyn_cast<IntInit>(B))
37+ if (const auto *II = dyn_cast<IntInit>(B))
3838 return II->getValue ();
3939 llvm_unreachable (" Unexpected initializer" );
4040}
@@ -126,20 +126,20 @@ class SearchableTableEmitter {
126126
127127 std::string primaryRepresentation (SMLoc Loc, const GenericField &Field,
128128 const Init *I) {
129- if (const StringInit *SI = dyn_cast<StringInit>(I)) {
129+ if (const auto *SI = dyn_cast<StringInit>(I)) {
130130 if (Field.IsCode || SI->hasCodeFormat ())
131131 return SI->getValue ().str ();
132132 else
133133 return SI->getAsString ();
134- } else if (const BitsInit *BI = dyn_cast<BitsInit>(I))
134+ } else if (const auto *BI = dyn_cast<BitsInit>(I)) {
135135 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)) {
137137 return BI->getValue () ? " true" : " false" ;
138- else if (Field.IsIntrinsic )
138+ } else if (Field.IsIntrinsic ) {
139139 return " Intrinsic::" + getIntrinsic (I).EnumName .str ();
140- else if (Field.IsInstruction )
140+ } else if (Field.IsInstruction ) {
141141 return I->getAsString ();
142- else if (Field.Enum ) {
142+ if (Field.Enum ) {
143143 const GenericEnum::Entry *Entry =
144144 Field.Enum ->getEntry (cast<DefInit>(I)->getDef ());
145145 if (!Entry)
@@ -152,7 +152,7 @@ class SearchableTableEmitter {
152152 }
153153
154154 bool isIntrinsic (const Init *I) {
155- if (const DefInit *DI = dyn_cast<DefInit>(I))
155+ if (const auto *DI = dyn_cast<DefInit>(I))
156156 return DI->getDef ()->isSubClassOf (" Intrinsic" );
157157 return false ;
158158 }
@@ -174,7 +174,7 @@ class SearchableTableEmitter {
174174 if (Ctx == TypeInTempStruct)
175175 return " std::string" ;
176176 return " StringRef" ;
177- } else if (const BitsRecTy *BI = dyn_cast<BitsRecTy>(Field.RecType )) {
177+ } else if (const auto *BI = dyn_cast<BitsRecTy>(Field.RecType )) {
178178 unsigned NumBits = BI->getNumBits ();
179179 if (NumBits <= 8 )
180180 return " uint8_t" ;
@@ -190,8 +190,9 @@ class SearchableTableEmitter {
190190 " ' of type bits is too large" );
191191 } else if (isa<BitRecTy>(Field.RecType )) {
192192 return " bool" ;
193- } else if (Field.Enum || Field.IsIntrinsic || Field.IsInstruction )
193+ } else if (Field.Enum || Field.IsIntrinsic || Field.IsInstruction ) {
194194 return " unsigned" ;
195+ }
195196 PrintFatalError (Index.Loc ,
196197 Twine (" In table '" ) + Table.Name + " ' lookup method '" +
197198 Index.Name + " ', key field '" + Field.Name +
@@ -359,8 +360,8 @@ void SearchableTableEmitter::emitLookupFunction(const GenericTable &Table,
359360
360361 std::vector<std::pair<const Record *, unsigned >> Entries;
361362 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 );
364365
365366 llvm::stable_sort (Entries,
366367 [&](const std::pair<const Record *, unsigned > &LHS,
@@ -369,19 +370,19 @@ void SearchableTableEmitter::emitLookupFunction(const GenericTable &Table,
369370 });
370371
371372 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 );
374375
375376 OS << " { " ;
376377 ListSeparator LS;
377378 for (const auto &Field : Index.Fields ) {
378379 std::string Repr = primaryRepresentation (
379- Index.Loc , Field, Entry. first ->getValueInit (Field.Name ));
380+ Index.Loc , Field, EntryRec ->getValueInit (Field.Name ));
380381 if (isa<StringRecTy>(Field.RecType ))
381382 Repr = StringRef (Repr).upper ();
382383 OS << LS << Repr;
383384 }
384- OS << " , " << Entry. second << " },\n " ;
385+ OS << " , " << EntryIndex << " },\n " ;
385386 }
386387
387388 OS << " };\n\n " ;
@@ -398,8 +399,8 @@ void SearchableTableEmitter::emitLookupFunction(const GenericTable &Table,
398399 Index.Fields [0 ].IsInstruction )) {
399400 int64_t FirstKeyVal = getNumericKey (Index, IndexRows[0 ]);
400401 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 ) {
403404 IsContiguous = false ;
404405 break ;
405406 }
@@ -509,9 +510,9 @@ void SearchableTableEmitter::emitLookupFunction(const GenericTable &Table,
509510 OS << " ||\n Key." << Field.Name << " != Idx->" << Field.Name ;
510511 }
511512
512- if (ShouldReturnRange)
513+ if (ShouldReturnRange) {
513514 OS << " return llvm::make_range(It.first, It.second);\n " ;
514- else if (IsPrimary) {
515+ } else if (IsPrimary) {
515516 OS << " )\n return nullptr;\n\n " ;
516517 OS << " return &*Idx;\n " ;
517518 } else {
@@ -557,8 +558,7 @@ void SearchableTableEmitter::emitGenericTable(const GenericTable &Table,
557558
558559 // The primary data table contains all the fields defined for this map.
559560 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 )) {
562562 OS << " { " ;
563563
564564 ListSeparator LS;
@@ -567,7 +567,7 @@ void SearchableTableEmitter::emitGenericTable(const GenericTable &Table,
567567 << primaryRepresentation (Table.Locs [0 ], Field,
568568 Entry->getValueInit (Field.Name ));
569569
570- OS << " }, // " << i << " \n " ;
570+ OS << " }, // " << Idx << " \n " ;
571571 }
572572 OS << " };\n " ;
573573
0 commit comments