@@ -348,6 +348,24 @@ static const BitsInit &getBitsField(const Record &Def, StringRef FieldName) {
348348// Representation of the instruction to work on.
349349typedef std::vector<BitValue> insn_t ;
350350
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+
351369namespace {
352370
353371static constexpr uint64_t NO_FIXED_SEGMENTS_SENTINEL =
@@ -558,15 +576,6 @@ class FilterChooser {
558576 return Insn;
559577 }
560578
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-
570579 // / dumpFilterArray - dumpFilterArray prints out debugging info for the given
571580 // / filter array as a series of chars.
572581 void dumpFilterArray (raw_ostream &OS, ArrayRef<BitValue> Filter) const ;
@@ -663,12 +672,12 @@ Filter::Filter(const FilterChooser &owner, unsigned startBit, unsigned numBits)
663672 insn_t Insn = Owner.insnWithID (OpcPair.EncodingID );
664673
665674 // 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);
667676
668- if (Ok ) {
677+ if (Field ) {
669678 // The encoding bits are well-known. Lets add the uid of the
670679 // instruction into the bucket keyed off the constant field value.
671- FilteredInstructions[Field].push_back (OpcPair);
680+ FilteredInstructions[* Field].push_back (OpcPair);
672681 ++NumFiltered;
673682 } else {
674683 // Some of the encoding bit(s) are unspecified. This contributes to
@@ -1099,28 +1108,6 @@ void DecoderEmitter::emitDecoderFunction(formatted_raw_ostream &OS,
10991108 OS << " }\n " ;
11001109}
11011110
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-
11241111// / dumpFilterArray - dumpFilterArray prints out debugging info for the given
11251112// / filter array as a series of chars.
11261113void FilterChooser::dumpFilterArray (raw_ostream &OS,
0 commit comments