@@ -247,35 +247,31 @@ int64_t SearchableTableEmitter::getNumericKey(const SearchIndex &Index,
247
247
bool SearchableTableEmitter::compareBy (const Record *LHS, const Record *RHS,
248
248
const SearchIndex &Index) {
249
249
// Compare two values and return:
250
- // - true if LHS < RHS.
251
- // - false if LHS > RHS.
252
- // - std::nullopt if LHS == RHS.
253
- auto CmpLTValue = [](const auto &LHS,
254
- const auto &RHS) -> std::optional<bool > {
250
+ // * -1 if LHS < RHS.
251
+ // * 1 if LHS > RHS.
252
+ // * 0 if LHS == RHS.
253
+ auto CmpLTValue = [](const auto &LHS, const auto &RHS) -> int {
255
254
if (LHS < RHS)
256
- return true ;
255
+ return - 1 ;
257
256
if (LHS > RHS)
258
- return false ;
259
- return std::nullopt ;
257
+ return 1 ;
258
+ return 0 ;
260
259
};
261
260
262
261
// Specialized form of `CmpLTValue` for string-like types that uses compare()
263
262
// to do the comparison of the 2 strings once (instead if 2 comparisons if we
264
263
// use `CmpLTValue`).
265
- auto CmpLTString = [](StringRef LHS, StringRef RHS) -> std::optional<bool > {
266
- int Cmp = LHS.compare (RHS);
267
- if (Cmp == 0 )
268
- return std::nullopt;
269
- return Cmp < 0 ;
264
+ auto CmpLTString = [](StringRef LHS, StringRef RHS) -> int {
265
+ return LHS.compare (RHS);
270
266
};
271
267
272
268
// Compare two fields and returns:
273
269
// - true if LHS < RHS.
274
270
// - false if LHS > RHS.
275
271
// - std::nullopt if LHS == RHS.
276
- auto CmpLTField = [this , &Index, &CmpLTValue, &CmpLTString](
277
- const Init *LHSI, const Init *RHSI,
278
- const GenericField &Field) -> std::optional< bool > {
272
+ auto CmpLTField = [this , &Index, &CmpLTValue,
273
+ &CmpLTString]( const Init *LHSI, const Init *RHSI,
274
+ const GenericField &Field) -> int {
279
275
if (isa<BitsRecTy>(Field.RecType ) || isa<IntRecTy>(Field.RecType )) {
280
276
int64_t LHSi = getAsInt (LHSI);
281
277
int64_t RHSi = getAsInt (RHSI);
@@ -285,9 +281,8 @@ bool SearchableTableEmitter::compareBy(const Record *LHS, const Record *RHS,
285
281
if (Field.IsIntrinsic ) {
286
282
const CodeGenIntrinsic &LHSi = getIntrinsic (LHSI);
287
283
const CodeGenIntrinsic &RHSi = getIntrinsic (RHSI);
288
- if (std::optional<bool > Cmp =
289
- CmpLTString (LHSi.TargetPrefix , RHSi.TargetPrefix ))
290
- return *Cmp;
284
+ if (int Cmp = CmpLTString (LHSi.TargetPrefix , RHSi.TargetPrefix ))
285
+ return Cmp;
291
286
return CmpLTString (LHSi.Name , RHSi.Name );
292
287
}
293
288
@@ -299,8 +294,8 @@ bool SearchableTableEmitter::compareBy(const Record *LHS, const Record *RHS,
299
294
// Order pseudo instructions before non-pseudo ones.
300
295
bool LHSNotPseudo = !LHSr->getValueAsBit (" isPseudo" );
301
296
bool RHSNotPseudo = !RHSr->getValueAsBit (" isPseudo" );
302
- if (std::optional< bool > Cmp = CmpLTValue (LHSNotPseudo, RHSNotPseudo))
303
- return * Cmp;
297
+ if (int Cmp = CmpLTValue (LHSNotPseudo, RHSNotPseudo))
298
+ return Cmp;
304
299
return CmpLTString (LHSr->getName (), RHSr->getName ());
305
300
}
306
301
@@ -324,8 +319,8 @@ bool SearchableTableEmitter::compareBy(const Record *LHS, const Record *RHS,
324
319
for (const GenericField &Field : Index.Fields ) {
325
320
const Init *LHSI = LHS->getValueInit (Field.Name );
326
321
const Init *RHSI = RHS->getValueInit (Field.Name );
327
- if (std::optional< bool > Cmp = CmpLTField (LHSI, RHSI, Field))
328
- return * Cmp;
322
+ if (int Cmp = CmpLTField (LHSI, RHSI, Field))
323
+ return Cmp < 0 ;
329
324
}
330
325
return false ;
331
326
}
0 commit comments