@@ -236,35 +236,31 @@ int64_t SearchableTableEmitter::getNumericKey(const SearchIndex &Index,
236
236
bool SearchableTableEmitter::compareBy (const Record *LHS, const Record *RHS,
237
237
const SearchIndex &Index) {
238
238
// Compare two values and return:
239
- // - true if LHS < RHS.
240
- // - false if LHS > RHS.
241
- // - std::nullopt if LHS == RHS.
242
- auto CmpLTValue = [](const auto &LHS,
243
- const auto &RHS) -> std::optional<bool > {
239
+ // * -1 if LHS < RHS.
240
+ // * 1 if LHS > RHS.
241
+ // * 0 if LHS == RHS.
242
+ auto CmpLTValue = [](const auto &LHS, const auto &RHS) -> int {
244
243
if (LHS < RHS)
245
- return true ;
244
+ return - 1 ;
246
245
if (LHS > RHS)
247
- return false ;
248
- return std::nullopt ;
246
+ return 1 ;
247
+ return 0 ;
249
248
};
250
249
251
250
// Specialized form of `CmpLTValue` for string-like types that uses compare()
252
251
// to do the comparison of the 2 strings once (instead if 2 comparisons if we
253
252
// use `CmpLTValue`).
254
- auto CmpLTString = [](StringRef LHS, StringRef RHS) -> std::optional<bool > {
255
- int Cmp = LHS.compare (RHS);
256
- if (Cmp == 0 )
257
- return std::nullopt;
258
- return Cmp < 0 ;
253
+ auto CmpLTString = [](StringRef LHS, StringRef RHS) -> int {
254
+ return LHS.compare (RHS);
259
255
};
260
256
261
257
// Compare two fields and returns:
262
258
// - true if LHS < RHS.
263
259
// - false if LHS > RHS.
264
260
// - std::nullopt if LHS == RHS.
265
- auto CmpLTField = [this , &Index, &CmpLTValue, &CmpLTString](
266
- const Init *LHSI, const Init *RHSI,
267
- const GenericField &Field) -> std::optional< bool > {
261
+ auto CmpLTField = [this , &Index, &CmpLTValue,
262
+ &CmpLTString]( const Init *LHSI, const Init *RHSI,
263
+ const GenericField &Field) -> int {
268
264
if (isa<BitsRecTy>(Field.RecType ) || isa<IntRecTy>(Field.RecType )) {
269
265
int64_t LHSi = getAsInt (LHSI);
270
266
int64_t RHSi = getAsInt (RHSI);
@@ -274,9 +270,8 @@ bool SearchableTableEmitter::compareBy(const Record *LHS, const Record *RHS,
274
270
if (Field.IsIntrinsic ) {
275
271
const CodeGenIntrinsic &LHSi = getIntrinsic (LHSI);
276
272
const CodeGenIntrinsic &RHSi = getIntrinsic (RHSI);
277
- if (std::optional<bool > Cmp =
278
- CmpLTString (LHSi.TargetPrefix , RHSi.TargetPrefix ))
279
- return *Cmp;
273
+ if (int Cmp = CmpLTString (LHSi.TargetPrefix , RHSi.TargetPrefix ))
274
+ return Cmp;
280
275
return CmpLTString (LHSi.Name , RHSi.Name );
281
276
}
282
277
@@ -288,8 +283,8 @@ bool SearchableTableEmitter::compareBy(const Record *LHS, const Record *RHS,
288
283
// Order pseudo instructions before non-pseudo ones.
289
284
bool LHSNotPseudo = !LHSr->getValueAsBit (" isPseudo" );
290
285
bool RHSNotPseudo = !RHSr->getValueAsBit (" isPseudo" );
291
- if (std::optional< bool > Cmp = CmpLTValue (LHSNotPseudo, RHSNotPseudo))
292
- return * Cmp;
286
+ if (int Cmp = CmpLTValue (LHSNotPseudo, RHSNotPseudo))
287
+ return Cmp;
293
288
return CmpLTString (LHSr->getName (), RHSr->getName ());
294
289
}
295
290
@@ -313,8 +308,8 @@ bool SearchableTableEmitter::compareBy(const Record *LHS, const Record *RHS,
313
308
for (const GenericField &Field : Index.Fields ) {
314
309
const Init *LHSI = LHS->getValueInit (Field.Name );
315
310
const Init *RHSI = RHS->getValueInit (Field.Name );
316
- if (std::optional< bool > Cmp = CmpLTField (LHSI, RHSI, Field))
317
- return * Cmp;
311
+ if (int Cmp = CmpLTField (LHSI, RHSI, Field))
312
+ return Cmp < 0 ;
318
313
}
319
314
return false ;
320
315
}
0 commit comments