Skip to content

Commit fd21d35

Browse files
authored
[TableGen] Reduce the number of vectors passed to getIslands. NFC (#130402)
Combine the StartBits, EndBits, and FieldVals vectors into a single vector of a struct that contains all 3 pieces of information. Instead of storing EndBits, we store NumBits since that's what the users want. I've removed the BitNo variable as it was easy to construct calculate from StartBit. I've also removed Num in favor of Islands.size().
1 parent 3ce43c8 commit fd21d35

File tree

1 file changed

+26
-42
lines changed

1 file changed

+26
-42
lines changed

llvm/utils/TableGen/DecoderEmitter.cpp

+26-42
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,12 @@ class FilterChooser {
428428
// Parent emitter
429429
const DecoderEmitter *Emitter;
430430

431+
struct Island {
432+
unsigned StartBit;
433+
unsigned NumBits;
434+
uint64_t FieldVal;
435+
};
436+
431437
public:
432438
FilterChooser(ArrayRef<EncodingAndInst> Insts,
433439
const std::vector<EncodingIDAndOpcode> &IDs,
@@ -513,13 +519,10 @@ class FilterChooser {
513519
}
514520

515521
// 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,
517523
// Inst{20} = 1 && Inst{3-0} == 0b1111 represents two islands of yet-to-be
518524
// 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;
523526

524527
// Emits code to check the Predicates member of an instruction are true.
525528
// Returns true if predicate matches were emitted, false otherwise.
@@ -1106,19 +1109,15 @@ void FilterChooser::dumpStack(raw_ostream &OS, const char *prefix) const {
11061109
// This returns a list of undecoded bits of an instructions, for example,
11071110
// Inst{20} = 1 && Inst{3-0} == 0b1111 represents two islands of yet-to-be
11081111
// 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,
11121113
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;
11171116

11181117
// 0: Init
11191118
// 1: Water (the bit value does not affect decoding)
11201119
// 2: Island (well-known bit value needed for decoding)
1121-
int State = 0;
1120+
unsigned State = 0;
11221121

11231122
for (unsigned i = 0; i < BitWidth; ++i) {
11241123
int64_t Val = Value(Insn[i]);
@@ -1132,35 +1131,26 @@ unsigned FilterChooser::getIslands(std::vector<unsigned> &StartBits,
11321131
State = 1; // Still in Water
11331132
else {
11341133
State = 2; // Into the Island
1135-
BitNo = 0;
1136-
StartBits.push_back(i);
1134+
StartBit = i;
11371135
FieldVal = Val;
11381136
}
11391137
break;
11401138
case 2:
11411139
if (Filtered || Val == -1) {
11421140
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});
11461142
} else {
11471143
State = 2; // Still in Island
1148-
++BitNo;
1149-
FieldVal = FieldVal | Val << BitNo;
1144+
FieldVal |= Val << (i - StartBit);
11501145
}
11511146
break;
11521147
}
11531148
}
11541149
// 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});
11601152

1161-
assert(StartBits.size() == Num && EndBits.size() == Num &&
1162-
FieldVals.size() == Num);
1163-
return Num;
1153+
return Islands.size();
11641154
}
11651155

11661156
void FilterChooser::emitBinaryParser(raw_ostream &OS, indent Indent,
@@ -1428,32 +1418,28 @@ void FilterChooser::emitSoftFailTableEntry(DecoderTableInfo &TableInfo,
14281418
// Emits table entries to decode the singleton.
14291419
void FilterChooser::emitSingletonTableEntry(DecoderTableInfo &TableInfo,
14301420
EncodingIDAndOpcode Opc) const {
1431-
std::vector<unsigned> StartBits;
1432-
std::vector<unsigned> EndBits;
1433-
std::vector<uint64_t> FieldVals;
1421+
std::vector<Island> Islands;
14341422
insn_t Insn;
14351423
insnWithID(Insn, Opc.EncodingID);
14361424

14371425
// 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);
14411427

14421428
// Emit the predicate table entry if one is needed.
14431429
emitPredicateTableEntry(TableInfo, Opc.EncodingID);
14441430

14451431
// Check any additional encoding fields needed.
14461432
for (unsigned I = Size; I != 0; --I) {
1447-
unsigned NumBits = EndBits[I - 1] - StartBits[I - 1] + 1;
1433+
unsigned NumBits = Islands[I - 1].NumBits;
14481434
assert(isUInt<8>(NumBits) && "NumBits overflowed uint8 table entry!");
14491435
TableInfo.Table.push_back(MCD::OPC_CheckField);
14501436
uint8_t Buffer[16], *P;
1451-
encodeULEB128(StartBits[I - 1], Buffer);
1437+
encodeULEB128(Islands[I - 1].StartBit, Buffer);
14521438
for (P = Buffer; *P >= 128; ++P)
14531439
TableInfo.Table.push_back(*P);
14541440
TableInfo.Table.push_back(*P);
14551441
TableInfo.Table.push_back(NumBits);
1456-
encodeULEB128(FieldVals[I - 1], Buffer);
1442+
encodeULEB128(Islands[I - 1].FieldVal, Buffer);
14571443
for (P = Buffer; *P >= 128; ++P)
14581444
TableInfo.Table.push_back(*P);
14591445
TableInfo.Table.push_back(*P);
@@ -1568,17 +1554,15 @@ bool FilterChooser::filterProcessor(bool AllowMixed, bool Greedy) {
15681554
assert(numInstructions == 3);
15691555

15701556
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;
15741558
insn_t Insn;
15751559

15761560
insnWithID(Insn, Opcode.EncodingID);
15771561

15781562
// Look for islands of undecoded bits of any instruction.
1579-
if (getIslands(StartBits, EndBits, FieldVals, Insn) > 0) {
1563+
if (getIslands(Islands, Insn) > 0) {
15801564
// 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);
15821566
return true;
15831567
}
15841568
}

0 commit comments

Comments
 (0)