@@ -300,6 +300,12 @@ class DecoderEmitter {
300
300
301
301
namespace {
302
302
303
+ struct EncodingIsland {
304
+ unsigned StartBit;
305
+ unsigned NumBits;
306
+ uint64_t FieldVal;
307
+ };
308
+
303
309
// / Filter - Filter works with FilterChooser to produce the decoding tree for
304
310
// / the ISA.
305
311
// /
@@ -425,12 +431,6 @@ class FilterChooser {
425
431
// / Set to true if decoding conflict was encountered.
426
432
bool HasConflict = false ;
427
433
428
- struct Island {
429
- unsigned StartBit;
430
- unsigned NumBits;
431
- uint64_t FieldVal;
432
- };
433
-
434
434
public:
435
435
// / Constructs a top-level filter chooser.
436
436
FilterChooser (ArrayRef<InstructionEncoding> Encodings,
@@ -483,12 +483,6 @@ class FilterChooser {
483
483
return FilterBits.Zero [Idx] || FilterBits.One [Idx];
484
484
}
485
485
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
-
492
486
// / Scans the well-known encoding bits of the encodings and, builds up a list
493
487
// / of candidate filters, and then returns the best one, if any.
494
488
std::unique_ptr<Filter> findBestFilter (ArrayRef<bitAttr_t> BitAttrs,
@@ -948,48 +942,36 @@ void FilterChooser::dumpStack(raw_ostream &OS, indent Indent,
948
942
// This returns a list of undecoded bits of an instructions, for example,
949
943
// Inst{20} = 1 && Inst{3-0} == 0b1111 represents two islands of yet-to-be
950
944
// 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;
954
948
uint64_t FieldVal;
955
949
unsigned StartBit;
956
950
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 ;
962
952
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);
973
961
} 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 ;
977
966
}
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 ;
989
971
}
990
972
}
991
- // If we are still in Island after the loop, do some housekeeping.
992
- if (State == 2 )
973
+
974
+ if (OnIsland )
993
975
Islands.push_back ({StartBit, FilterWidth - StartBit, FieldVal});
994
976
995
977
return Islands;
@@ -1140,17 +1122,17 @@ void DecoderTableBuilder::emitSingletonTableEntry(
1140
1122
KnownBits EncodingBits = Encoding.getMandatoryBits ();
1141
1123
1142
1124
// Look for islands of undecoded bits of the singleton.
1143
- std::vector<FilterChooser::Island > Islands = FC. getIslands (EncodingBits);
1125
+ std::vector<EncodingIsland > Islands = getIslands (EncodingBits, FC. FilterBits );
1144
1126
1145
1127
// Emit the predicate table entry if one is needed.
1146
1128
emitPredicateTableEntry (EncodingID);
1147
1129
1148
1130
// Check any additional encoding fields needed.
1149
- for (const FilterChooser::Island &Ilnd : reverse (Islands)) {
1131
+ for (const EncodingIsland &Island : reverse (Islands)) {
1150
1132
TableInfo.Table .insertOpcode (OPC_CheckField);
1151
- TableInfo.Table .insertULEB128 (Ilnd .StartBit );
1152
- TableInfo.Table .insertUInt8 (Ilnd .NumBits );
1153
- TableInfo.Table .insertULEB128 (Ilnd .FieldVal );
1133
+ TableInfo.Table .insertULEB128 (Island .StartBit );
1134
+ TableInfo.Table .insertUInt8 (Island .NumBits );
1135
+ TableInfo.Table .insertULEB128 (Island .FieldVal );
1154
1136
}
1155
1137
1156
1138
// Check for soft failure of the match.
@@ -1186,7 +1168,8 @@ FilterChooser::findBestFilter(ArrayRef<bitAttr_t> BitAttrs, bool AllowMixed,
1186
1168
KnownBits EncodingBits = Encoding.getMandatoryBits ();
1187
1169
1188
1170
// Look for islands of undecoded bits of any instruction.
1189
- std::vector<Island> Islands = getIslands (EncodingBits);
1171
+ std::vector<EncodingIsland> Islands =
1172
+ getIslands (EncodingBits, FilterBits);
1190
1173
if (!Islands.empty ()) {
1191
1174
// Found an instruction with island(s). Now just assign a filter.
1192
1175
return std::make_unique<Filter>(
0 commit comments