@@ -348,6 +348,24 @@ static const BitsInit &getBitsField(const Record &Def, StringRef FieldName) {
348
348
// Representation of the instruction to work on.
349
349
typedef std::vector<BitValue> insn_t ;
350
350
351
+ // / Extracts a NumBits long field from Insn, starting from StartBit.
352
+ // / Returns the value of the field if all bits are well-known,
353
+ // / otherwise std::nullopt.
354
+ static std::optional<uint64_t >
355
+ fieldFromInsn (const insn_t &Insn, unsigned StartBit, unsigned NumBits) {
356
+ uint64_t Field = 0 ;
357
+
358
+ for (unsigned BitIndex = 0 ; BitIndex < NumBits; ++BitIndex) {
359
+ if (Insn[StartBit + BitIndex] == BitValue::BIT_UNSET)
360
+ return std::nullopt;
361
+
362
+ if (Insn[StartBit + BitIndex] == BitValue::BIT_TRUE)
363
+ Field = Field | (1ULL << BitIndex);
364
+ }
365
+
366
+ return Field;
367
+ }
368
+
351
369
namespace {
352
370
353
371
static constexpr uint64_t NO_FIXED_SEGMENTS_SENTINEL =
@@ -558,15 +576,6 @@ class FilterChooser {
558
576
return Insn;
559
577
}
560
578
561
- // Populates the field of the insn given the start position and the number of
562
- // consecutive bits to scan for.
563
- //
564
- // Returns a pair of values (indicator, field), where the indicator is false
565
- // if there exists any uninitialized bit value in the range and true if all
566
- // bits are well-known. The second value is the potentially populated field.
567
- std::pair<bool , uint64_t > fieldFromInsn (const insn_t &Insn, unsigned StartBit,
568
- unsigned NumBits) const ;
569
-
570
579
// / dumpFilterArray - dumpFilterArray prints out debugging info for the given
571
580
// / filter array as a series of chars.
572
581
void dumpFilterArray (raw_ostream &OS, ArrayRef<BitValue> Filter) const ;
@@ -663,12 +672,12 @@ Filter::Filter(const FilterChooser &owner, unsigned startBit, unsigned numBits)
663
672
insn_t Insn = Owner.insnWithID (OpcPair.EncodingID );
664
673
665
674
// Scans the segment for possibly well-specified encoding bits.
666
- auto [Ok, Field] = Owner. fieldFromInsn (Insn, StartBit, NumBits);
675
+ std::optional< uint64_t > Field = fieldFromInsn (Insn, StartBit, NumBits);
667
676
668
- if (Ok ) {
677
+ if (Field ) {
669
678
// The encoding bits are well-known. Lets add the uid of the
670
679
// instruction into the bucket keyed off the constant field value.
671
- FilteredInstructions[Field].push_back (OpcPair);
680
+ FilteredInstructions[* Field].push_back (OpcPair);
672
681
++NumFiltered;
673
682
} else {
674
683
// Some of the encoding bit(s) are unspecified. This contributes to
@@ -1099,28 +1108,6 @@ void DecoderEmitter::emitDecoderFunction(formatted_raw_ostream &OS,
1099
1108
OS << " }\n " ;
1100
1109
}
1101
1110
1102
- // Populates the field of the insn given the start position and the number of
1103
- // consecutive bits to scan for.
1104
- //
1105
- // Returns a pair of values (indicator, field), where the indicator is false
1106
- // if there exists any uninitialized bit value in the range and true if all
1107
- // bits are well-known. The second value is the potentially populated field.
1108
- std::pair<bool , uint64_t > FilterChooser::fieldFromInsn (const insn_t &Insn,
1109
- unsigned StartBit,
1110
- unsigned NumBits) const {
1111
- uint64_t Field = 0 ;
1112
-
1113
- for (unsigned i = 0 ; i < NumBits; ++i) {
1114
- if (Insn[StartBit + i] == BitValue::BIT_UNSET)
1115
- return {false , Field};
1116
-
1117
- if (Insn[StartBit + i] == BitValue::BIT_TRUE)
1118
- Field = Field | (1ULL << i);
1119
- }
1120
-
1121
- return {true , Field};
1122
- }
1123
-
1124
1111
// / dumpFilterArray - dumpFilterArray prints out debugging info for the given
1125
1112
// / filter array as a series of chars.
1126
1113
void FilterChooser::dumpFilterArray (raw_ostream &OS,
0 commit comments