@@ -212,19 +212,21 @@ class SearchableTableEmitter {
212
212
int64_t SearchableTableEmitter::getNumericKey (const SearchIndex &Index,
213
213
const Record *Rec) {
214
214
assert (Index.Fields .size () == 1 );
215
+ const GenericField &Field = Index.Fields [0 ];
215
216
216
217
// To be consistent with compareBy and primaryRepresentation elsewhere,
217
218
// we check for IsInstruction before Enum-- these fields are not exclusive.
218
- if (Index. Fields [ 0 ] .IsInstruction ) {
219
- const Record *TheDef = Rec->getValueAsDef (Index. Fields [ 0 ] .Name );
219
+ if (Field .IsInstruction ) {
220
+ const Record *TheDef = Rec->getValueAsDef (Field .Name );
220
221
return Target->getInstrIntValue (TheDef);
221
222
}
222
- if (Index. Fields [ 0 ] .Enum ) {
223
- const Record *EnumEntry = Rec->getValueAsDef (Index. Fields [ 0 ] .Name );
224
- return Index. Fields [ 0 ] .Enum ->EntryMap [EnumEntry]->second ;
223
+ if (Field .Enum ) {
224
+ const Record *EnumEntry = Rec->getValueAsDef (Field .Name );
225
+ return Field .Enum ->EntryMap [EnumEntry]->second ;
225
226
}
227
+ assert (isa<BitsRecTy>(Field.RecType ) && " unexpected field type" );
226
228
227
- return getInt (Rec, Index. Fields [ 0 ] .Name );
229
+ return getInt (Rec, Field .Name );
228
230
}
229
231
230
232
// / Less-than style comparison between \p LHS and \p RHS according to the
@@ -392,37 +394,31 @@ void SearchableTableEmitter::emitLookupFunction(const GenericTable &Table,
392
394
}
393
395
}
394
396
395
- if (IsContiguous) {
397
+ if (Index. EarlyOut || IsContiguous) {
396
398
const GenericField &Field = Index.Fields [0 ];
397
399
std::string FirstRepr = primaryRepresentation (
398
400
Index.Loc , Field, IndexRows[0 ]->getValueInit (Field.Name ));
399
401
std::string LastRepr = primaryRepresentation (
400
402
Index.Loc , Field, IndexRows.back ()->getValueInit (Field.Name ));
401
- OS << " if ((" << Field.Name << " < " << FirstRepr << " ) ||\n " ;
402
- OS << " (" << Field.Name << " > " << LastRepr << " ))\n " ;
403
- OS << " return nullptr;\n " ;
404
- OS << " auto Table = ArrayRef(" << IndexName << " );\n " ;
405
- OS << " size_t Idx = " << Index.Fields [0 ].Name << " - " << FirstRepr
406
- << " ;\n " ;
407
- OS << " return " ;
408
- if (IsPrimary)
409
- OS << " &Table[Idx]" ;
410
- else
411
- OS << " &" << Table.Name << " [Table[Idx]._index]" ;
412
- OS << " ;\n " ;
413
- OS << " }\n " ;
414
- return ;
415
- }
416
-
417
- if (Index.EarlyOut ) {
418
- const GenericField &Field = Index.Fields [0 ];
419
- std::string FirstRepr = primaryRepresentation (
420
- Index.Loc , Field, IndexRows[0 ]->getValueInit (Field.Name ));
421
- std::string LastRepr = primaryRepresentation (
422
- Index.Loc , Field, IndexRows.back ()->getValueInit (Field.Name ));
423
- OS << " if ((" << Field.Name << " < " << FirstRepr << " ) ||\n " ;
424
- OS << " (" << Field.Name << " > " << LastRepr << " ))\n " ;
403
+ std::string TS =
404
+ ' (' + searchableFieldType (Table, Index, Field, TypeInStaticStruct) +
405
+ ' )' ;
406
+ OS << " if (" << TS << Field.Name << " != std::clamp(" << TS << Field.Name
407
+ << " , " << TS << FirstRepr << " , " << TS << LastRepr << " ))\n " ;
425
408
OS << " return nullptr;\n\n " ;
409
+
410
+ if (IsContiguous && !Index.EarlyOut ) {
411
+ OS << " auto Table = ArrayRef(" << IndexName << " );\n " ;
412
+ OS << " size_t Idx = " << Field.Name << " - " << FirstRepr << " ;\n " ;
413
+ OS << " return " ;
414
+ if (IsPrimary)
415
+ OS << " &Table[Idx]" ;
416
+ else
417
+ OS << " &" << Table.Name << " [Table[Idx]._index]" ;
418
+ OS << " ;\n " ;
419
+ OS << " }\n " ;
420
+ return ;
421
+ }
426
422
}
427
423
428
424
OS << " struct KeyType {\n " ;
0 commit comments