@@ -428,6 +428,12 @@ class FilterChooser {
428
428
// Parent emitter
429
429
const DecoderEmitter *Emitter;
430
430
431
+ struct Island {
432
+ unsigned StartBit;
433
+ unsigned NumBits;
434
+ uint64_t FieldVal;
435
+ };
436
+
431
437
public:
432
438
FilterChooser (ArrayRef<EncodingAndInst> Insts,
433
439
const std::vector<EncodingIDAndOpcode> &IDs,
@@ -513,13 +519,10 @@ class FilterChooser {
513
519
}
514
520
515
521
// Calculates the island(s) needed to decode the instruction.
516
- // This returns a lit of undecoded bits of an instructions, for example,
522
+ // This returns a list of undecoded bits of an instructions, for example,
517
523
// Inst{20} = 1 && Inst{3-0} == 0b1111 represents two islands of yet-to-be
518
524
// decoded bits in order to verify that the instruction matches the Opcode.
519
- unsigned getIslands (std::vector<unsigned > &StartBits,
520
- std::vector<unsigned > &EndBits,
521
- std::vector<uint64_t > &FieldVals,
522
- const insn_t &Insn) const ;
525
+ unsigned getIslands (std::vector<Island> &Islands, const insn_t &Insn) const ;
523
526
524
527
// Emits code to check the Predicates member of an instruction are true.
525
528
// Returns true if predicate matches were emitted, false otherwise.
@@ -1106,19 +1109,15 @@ void FilterChooser::dumpStack(raw_ostream &OS, const char *prefix) const {
1106
1109
// This returns a list of undecoded bits of an instructions, for example,
1107
1110
// Inst{20} = 1 && Inst{3-0} == 0b1111 represents two islands of yet-to-be
1108
1111
// decoded bits in order to verify that the instruction matches the Opcode.
1109
- unsigned FilterChooser::getIslands (std::vector<unsigned > &StartBits,
1110
- std::vector<unsigned > &EndBits,
1111
- std::vector<uint64_t > &FieldVals,
1112
+ unsigned FilterChooser::getIslands (std::vector<Island> &Islands,
1112
1113
const insn_t &Insn) const {
1113
- unsigned Num, BitNo;
1114
- Num = BitNo = 0 ;
1115
-
1116
- uint64_t FieldVal = 0 ;
1114
+ uint64_t FieldVal;
1115
+ unsigned StartBit;
1117
1116
1118
1117
// 0: Init
1119
1118
// 1: Water (the bit value does not affect decoding)
1120
1119
// 2: Island (well-known bit value needed for decoding)
1121
- int State = 0 ;
1120
+ unsigned State = 0 ;
1122
1121
1123
1122
for (unsigned i = 0 ; i < BitWidth; ++i) {
1124
1123
int64_t Val = Value (Insn[i]);
@@ -1132,35 +1131,26 @@ unsigned FilterChooser::getIslands(std::vector<unsigned> &StartBits,
1132
1131
State = 1 ; // Still in Water
1133
1132
else {
1134
1133
State = 2 ; // Into the Island
1135
- BitNo = 0 ;
1136
- StartBits.push_back (i);
1134
+ StartBit = i;
1137
1135
FieldVal = Val;
1138
1136
}
1139
1137
break ;
1140
1138
case 2 :
1141
1139
if (Filtered || Val == -1 ) {
1142
1140
State = 1 ; // Into the Water
1143
- EndBits.push_back (i - 1 );
1144
- FieldVals.push_back (FieldVal);
1145
- ++Num;
1141
+ Islands.push_back ({StartBit, i - StartBit, FieldVal});
1146
1142
} else {
1147
1143
State = 2 ; // Still in Island
1148
- ++BitNo;
1149
- FieldVal = FieldVal | Val << BitNo;
1144
+ FieldVal |= Val << (i - StartBit);
1150
1145
}
1151
1146
break ;
1152
1147
}
1153
1148
}
1154
1149
// If we are still in Island after the loop, do some housekeeping.
1155
- if (State == 2 ) {
1156
- EndBits.push_back (BitWidth - 1 );
1157
- FieldVals.push_back (FieldVal);
1158
- ++Num;
1159
- }
1150
+ if (State == 2 )
1151
+ Islands.push_back ({StartBit, BitWidth - StartBit, FieldVal});
1160
1152
1161
- assert (StartBits.size () == Num && EndBits.size () == Num &&
1162
- FieldVals.size () == Num);
1163
- return Num;
1153
+ return Islands.size ();
1164
1154
}
1165
1155
1166
1156
void FilterChooser::emitBinaryParser (raw_ostream &OS, indent Indent,
@@ -1428,32 +1418,28 @@ void FilterChooser::emitSoftFailTableEntry(DecoderTableInfo &TableInfo,
1428
1418
// Emits table entries to decode the singleton.
1429
1419
void FilterChooser::emitSingletonTableEntry (DecoderTableInfo &TableInfo,
1430
1420
EncodingIDAndOpcode Opc) const {
1431
- std::vector<unsigned > StartBits;
1432
- std::vector<unsigned > EndBits;
1433
- std::vector<uint64_t > FieldVals;
1421
+ std::vector<Island> Islands;
1434
1422
insn_t Insn;
1435
1423
insnWithID (Insn, Opc.EncodingID );
1436
1424
1437
1425
// Look for islands of undecoded bits of the singleton.
1438
- getIslands (StartBits, EndBits, FieldVals, Insn);
1439
-
1440
- unsigned Size = StartBits.size ();
1426
+ unsigned Size = getIslands (Islands, Insn);
1441
1427
1442
1428
// Emit the predicate table entry if one is needed.
1443
1429
emitPredicateTableEntry (TableInfo, Opc.EncodingID );
1444
1430
1445
1431
// Check any additional encoding fields needed.
1446
1432
for (unsigned I = Size ; I != 0 ; --I) {
1447
- unsigned NumBits = EndBits [I - 1 ] - StartBits[I - 1 ] + 1 ;
1433
+ unsigned NumBits = Islands [I - 1 ]. NumBits ;
1448
1434
assert (isUInt<8 >(NumBits) && " NumBits overflowed uint8 table entry!" );
1449
1435
TableInfo.Table .push_back (MCD::OPC_CheckField);
1450
1436
uint8_t Buffer[16 ], *P;
1451
- encodeULEB128 (StartBits [I - 1 ], Buffer);
1437
+ encodeULEB128 (Islands [I - 1 ]. StartBit , Buffer);
1452
1438
for (P = Buffer; *P >= 128 ; ++P)
1453
1439
TableInfo.Table .push_back (*P);
1454
1440
TableInfo.Table .push_back (*P);
1455
1441
TableInfo.Table .push_back (NumBits);
1456
- encodeULEB128 (FieldVals [I - 1 ], Buffer);
1442
+ encodeULEB128 (Islands [I - 1 ]. FieldVal , Buffer);
1457
1443
for (P = Buffer; *P >= 128 ; ++P)
1458
1444
TableInfo.Table .push_back (*P);
1459
1445
TableInfo.Table .push_back (*P);
@@ -1568,17 +1554,15 @@ bool FilterChooser::filterProcessor(bool AllowMixed, bool Greedy) {
1568
1554
assert (numInstructions == 3 );
1569
1555
1570
1556
for (const auto &Opcode : Opcodes) {
1571
- std::vector<unsigned > StartBits;
1572
- std::vector<unsigned > EndBits;
1573
- std::vector<uint64_t > FieldVals;
1557
+ std::vector<Island> Islands;
1574
1558
insn_t Insn;
1575
1559
1576
1560
insnWithID (Insn, Opcode.EncodingID );
1577
1561
1578
1562
// Look for islands of undecoded bits of any instruction.
1579
- if (getIslands (StartBits, EndBits, FieldVals , Insn) > 0 ) {
1563
+ if (getIslands (Islands , Insn) > 0 ) {
1580
1564
// Found an instruction with island(s). Now just assign a filter.
1581
- runSingleFilter (StartBits [0 ], EndBits [0 ] - StartBits[ 0 ] + 1 , true );
1565
+ runSingleFilter (Islands [0 ]. StartBit , Islands [0 ]. NumBits , true );
1582
1566
return true ;
1583
1567
}
1584
1568
}
0 commit comments