@@ -300,6 +300,12 @@ class DecoderEmitter {
300300
301301namespace  {
302302
303+ struct  EncodingIsland  {
304+   unsigned  StartBit;
305+   unsigned  NumBits;
306+   uint64_t  FieldVal;
307+ };
308+ 
303309// / Filter - Filter works with FilterChooser to produce the decoding tree for
304310// / the ISA.
305311// /
@@ -425,12 +431,6 @@ class FilterChooser {
425431  // / Set to true if decoding conflict was encountered.
426432  bool  HasConflict = false ;
427433
428-   struct  Island  {
429-     unsigned  StartBit;
430-     unsigned  NumBits;
431-     uint64_t  FieldVal;
432-   };
433- 
434434public: 
435435  // / Constructs a top-level filter chooser.
436436  FilterChooser (ArrayRef<InstructionEncoding> Encodings,
@@ -483,12 +483,6 @@ class FilterChooser {
483483    return  FilterBits.Zero [Idx] || FilterBits.One [Idx];
484484  }
485485
486-   //  Calculates the island(s) needed to decode the instruction.
487-   //  This returns a list of undecoded bits of an instructions, for example,
488-   //  Inst{20} = 1 && Inst{3-0} == 0b1111 represents two islands of yet-to-be
489-   //  decoded bits in order to verify that the instruction matches the Opcode.
490-   std::vector<Island> getIslands (const  KnownBits &EncodingBits) const ;
491- 
492486  // / Scans the well-known encoding bits of the encodings and, builds up a list
493487  // / of candidate filters, and then returns the best one, if any.
494488  std::unique_ptr<Filter> findBestFilter (ArrayRef<bitAttr_t> BitAttrs,
@@ -948,48 +942,36 @@ void FilterChooser::dumpStack(raw_ostream &OS, indent Indent,
948942//  This returns a list of undecoded bits of an instructions, for example,
949943//  Inst{20} = 1 && Inst{3-0} == 0b1111 represents two islands of yet-to-be
950944//  decoded bits in order to verify that the instruction matches the Opcode.
951- std::vector<FilterChooser::Island> 
952- FilterChooser::getIslands ( const  KnownBits &EncodingBits)  const  {
953-   std::vector<Island > Islands;
945+ static   std::vector<EncodingIsland>  getIslands ( const  KnownBits &EncodingBits, 
946+                                                const  KnownBits &FilterBits)  {
947+   std::vector<EncodingIsland > Islands;
954948  uint64_t  FieldVal;
955949  unsigned  StartBit;
956950
957-   //  0: Init
958-   //  1: Water (the bit value does not affect decoding)
959-   //  2: Island (well-known bit value needed for decoding)
960-   unsigned  State = 0 ;
961- 
951+   bool  OnIsland = false ;
962952  unsigned  FilterWidth = FilterBits.getBitWidth ();
963-   for  (unsigned  i = 0 ; i != FilterWidth; ++i) {
964-     bool  IsKnown = EncodingBits.Zero [i] || EncodingBits.One [i];
965-     bool  Filtered = isPositionFiltered (i);
966-     switch  (State) {
967-     default :
968-       llvm_unreachable (" Unreachable code!" 
969-     case  0 :
970-     case  1 :
971-       if  (Filtered || !IsKnown) {
972-         State = 1 ; //  Still in Water
953+   for  (unsigned  I = 0 ; I != FilterWidth; ++I) {
954+     bool  IsKnown = EncodingBits.Zero [I] || EncodingBits.One [I];
955+     bool  IsFiltered = FilterBits.Zero [I] || FilterBits.One [I];
956+     if  (!IsFiltered && IsKnown) {
957+       if  (OnIsland) {
958+         //  Accumulate island bits.
959+         FieldVal |= static_cast <uint64_t >(EncodingBits.One [I])
960+                     << (I - StartBit);
973961      } else  {
974-         State = 2 ; //  Into the Island
975-         StartBit = i;
976-         FieldVal = static_cast <uint64_t >(EncodingBits.One [i]);
962+         //  Onto an island.
963+         StartBit = I;
964+         FieldVal = static_cast <uint64_t >(EncodingBits.One [I]);
965+         OnIsland = true ;
977966      }
978-       break ;
979-     case  2 :
980-       if  (Filtered || !IsKnown) {
981-         State = 1 ; //  Into the Water
982-         Islands.push_back ({StartBit, i - StartBit, FieldVal});
983-       } else  {
984-         State = 2 ; //  Still in Island
985-         FieldVal |= static_cast <uint64_t >(EncodingBits.One [i])
986-                     << (i - StartBit);
987-       }
988-       break ;
967+     } else  if  (OnIsland) {
968+       //  Into the water.
969+       Islands.push_back ({StartBit, I - StartBit, FieldVal});
970+       OnIsland = false ;
989971    }
990972  }
991-    //  If we are still in Island after the loop, do some housekeeping. 
992-   if  (State ==  2 )
973+ 
974+   if  (OnIsland )
993975    Islands.push_back ({StartBit, FilterWidth - StartBit, FieldVal});
994976
995977  return  Islands;
@@ -1136,17 +1118,17 @@ void DecoderTableBuilder::emitSingletonTableEntry(
11361118  KnownBits EncodingBits = Encoding.getMandatoryBits ();
11371119
11381120  //  Look for islands of undecoded bits of the singleton.
1139-   std::vector<FilterChooser::Island > Islands = FC. getIslands (EncodingBits);
1121+   std::vector<EncodingIsland > Islands = getIslands (EncodingBits, FC. FilterBits );
11401122
11411123  //  Emit the predicate table entry if one is needed.
11421124  emitPredicateTableEntry (EncodingID);
11431125
11441126  //  Check any additional encoding fields needed.
1145-   for  (const  FilterChooser::Island &Ilnd  : reverse (Islands)) {
1127+   for  (const  EncodingIsland &Island  : reverse (Islands)) {
11461128    TableInfo.Table .insertOpcode (OPC_CheckField);
1147-     TableInfo.Table .insertULEB128 (Ilnd .StartBit );
1148-     TableInfo.Table .insertUInt8 (Ilnd .NumBits );
1149-     TableInfo.Table .insertULEB128 (Ilnd .FieldVal );
1129+     TableInfo.Table .insertULEB128 (Island .StartBit );
1130+     TableInfo.Table .insertUInt8 (Island .NumBits );
1131+     TableInfo.Table .insertULEB128 (Island .FieldVal );
11501132  }
11511133
11521134  //  Check for soft failure of the match.
@@ -1182,7 +1164,8 @@ FilterChooser::findBestFilter(ArrayRef<bitAttr_t> BitAttrs, bool AllowMixed,
11821164      KnownBits EncodingBits = Encoding.getMandatoryBits ();
11831165
11841166      //  Look for islands of undecoded bits of any instruction.
1185-       std::vector<Island> Islands = getIslands (EncodingBits);
1167+       std::vector<EncodingIsland> Islands =
1168+           getIslands (EncodingBits, FilterBits);
11861169      if  (!Islands.empty ()) {
11871170        //  Found an instruction with island(s).  Now just assign a filter.
11881171        return  std::make_unique<Filter>(
0 commit comments