Skip to content

Commit c9106c8

Browse files
authored
[TableGen][DecoderEmitter] Add a couple of helper methods (NFC) (#155163)
Replace push_back with more specific insertOpcode/insertUInt8.
1 parent 66be00d commit c9106c8

File tree

1 file changed

+32
-27
lines changed

1 file changed

+32
-27
lines changed

llvm/utils/TableGen/DecoderEmitter.cpp

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -252,15 +252,23 @@ class DecoderTable {
252252
DecoderTable() { Data.reserve(16384); }
253253

254254
void clear() { Data.clear(); }
255-
void push_back(uint8_t Item) { Data.push_back(Item); }
256255
size_t size() const { return Data.size(); }
257256
const uint8_t *data() const { return Data.data(); }
258257

259258
using const_iterator = std::vector<uint8_t>::const_iterator;
260259
const_iterator begin() const { return Data.begin(); }
261260
const_iterator end() const { return Data.end(); }
262261

263-
// Insert a ULEB128 encoded value into the table.
262+
/// Inserts a state machine opcode into the table.
263+
void insertOpcode(MCD::DecoderOps Opcode) { Data.push_back(Opcode); }
264+
265+
/// Inserts a uint8 encoded value into the table.
266+
void insertUInt8(unsigned Value) {
267+
assert(isUInt<8>(Value));
268+
Data.push_back(Value);
269+
}
270+
271+
/// Inserts a ULEB128 encoded value into the table.
264272
void insertULEB128(uint64_t Value) {
265273
// Encode and emit the value to filter against.
266274
uint8_t Buffer[16];
@@ -1243,10 +1251,10 @@ void FilterChooser::emitPredicateTableEntry(DecoderTableInfo &TableInfo,
12431251
// computed.
12441252
unsigned PIdx = getPredicateIndex(TableInfo, PS.str());
12451253

1246-
const uint8_t DecoderOp = TableInfo.isOutermostScope()
1247-
? MCD::OPC_CheckPredicateOrFail
1248-
: MCD::OPC_CheckPredicate;
1249-
TableInfo.Table.push_back(DecoderOp);
1254+
const MCD::DecoderOps DecoderOp = TableInfo.isOutermostScope()
1255+
? MCD::OPC_CheckPredicateOrFail
1256+
: MCD::OPC_CheckPredicate;
1257+
TableInfo.Table.insertOpcode(DecoderOp);
12501258
TableInfo.Table.insertULEB128(PIdx);
12511259

12521260
if (DecoderOp == MCD::OPC_CheckPredicate) {
@@ -1286,7 +1294,7 @@ void FilterChooser::emitSoftFailTableEntry(DecoderTableInfo &TableInfo,
12861294
if (!NeedPositiveMask && !NeedNegativeMask)
12871295
return;
12881296

1289-
TableInfo.Table.push_back(MCD::OPC_SoftFail);
1297+
TableInfo.Table.insertOpcode(MCD::OPC_SoftFail);
12901298
TableInfo.Table.insertULEB128(PositiveMask.getZExtValue());
12911299
TableInfo.Table.insertULEB128(NegativeMask.getZExtValue());
12921300
}
@@ -1305,14 +1313,12 @@ void FilterChooser::emitSingletonTableEntry(DecoderTableInfo &TableInfo,
13051313

13061314
// Check any additional encoding fields needed.
13071315
for (const Island &Ilnd : reverse(Islands)) {
1308-
assert(isUInt<8>(Ilnd.NumBits) && "NumBits overflowed uint8 table entry!");
1309-
const uint8_t DecoderOp = TableInfo.isOutermostScope()
1310-
? MCD::OPC_CheckFieldOrFail
1311-
: MCD::OPC_CheckField;
1312-
TableInfo.Table.push_back(DecoderOp);
1313-
1316+
const MCD::DecoderOps DecoderOp = TableInfo.isOutermostScope()
1317+
? MCD::OPC_CheckFieldOrFail
1318+
: MCD::OPC_CheckField;
1319+
TableInfo.Table.insertOpcode(DecoderOp);
13141320
TableInfo.Table.insertULEB128(Ilnd.StartBit);
1315-
TableInfo.Table.push_back(Ilnd.NumBits);
1321+
TableInfo.Table.insertUInt8(Ilnd.NumBits);
13161322
TableInfo.Table.insertULEB128(Ilnd.FieldVal);
13171323

13181324
if (DecoderOp == MCD::OPC_CheckField) {
@@ -1338,12 +1344,11 @@ void FilterChooser::emitSingletonTableEntry(DecoderTableInfo &TableInfo,
13381344
// decoder method indicates that additional processing should be done to see
13391345
// if there is any other instruction that also matches the bitpattern and
13401346
// can decode it.
1341-
const uint8_t DecoderOp =
1342-
Encoding.hasCompleteDecoder()
1343-
? MCD::OPC_Decode
1344-
: (TableInfo.isOutermostScope() ? MCD::OPC_TryDecodeOrFail
1345-
: MCD::OPC_TryDecode);
1346-
TableInfo.Table.push_back(DecoderOp);
1347+
const MCD::DecoderOps DecoderOp =
1348+
Encoding.hasCompleteDecoder() ? MCD::OPC_Decode
1349+
: TableInfo.isOutermostScope() ? MCD::OPC_TryDecodeOrFail
1350+
: MCD::OPC_TryDecode;
1351+
TableInfo.Table.insertOpcode(DecoderOp);
13471352
const Record *InstDef = Encodings[EncodingID].getInstruction()->TheDef;
13481353
TableInfo.Table.insertULEB128(Emitter->getTarget().getInstrIntValue(InstDef));
13491354
TableInfo.Table.insertULEB128(DIdx);
@@ -1661,14 +1666,13 @@ void FilterChooser::emitTableEntries(DecoderTableInfo &TableInfo) const {
16611666
} else {
16621667
// The general case: emit a switch over the field value.
16631668
DecoderTable &Table = TableInfo.Table;
1664-
Table.push_back(MCD::OPC_ExtractField);
1669+
Table.insertOpcode(MCD::OPC_ExtractField);
16651670
Table.insertULEB128(StartBit);
1666-
assert(isUInt<8>(NumBits) && "NumBits overflowed uint8 table entry!");
1667-
Table.push_back(NumBits);
1671+
Table.insertUInt8(NumBits);
16681672

16691673
// Emit switch cases for all but the last element.
16701674
for (const auto &[FilterVal, Delegate] : drop_end(FilterChooserMap)) {
1671-
Table.push_back(MCD::OPC_FilterValue);
1675+
Table.insertOpcode(MCD::OPC_FilterValue);
16721676
Table.insertULEB128(FilterVal);
16731677
size_t FixupPos = Table.insertNumToSkip();
16741678

@@ -1682,8 +1686,9 @@ void FilterChooser::emitTableEntries(DecoderTableInfo &TableInfo) const {
16821686
// Emit a switch case for the last element. It never falls through;
16831687
// if it doesn't match, we leave the current scope.
16841688
const auto &[FilterVal, Delegate] = *FilterChooserMap.rbegin();
1685-
Table.push_back(!TableInfo.isOutermostScope() ? MCD::OPC_FilterValue
1686-
: MCD::OPC_FilterValueOrFail);
1689+
Table.insertOpcode(!TableInfo.isOutermostScope()
1690+
? MCD::OPC_FilterValue
1691+
: MCD::OPC_FilterValueOrFail);
16871692
Table.insertULEB128(FilterVal);
16881693
if (!TableInfo.isOutermostScope())
16891694
TableInfo.FixupStack.back().push_back(Table.insertNumToSkip());
@@ -2519,7 +2524,7 @@ namespace {
25192524
assert(TableInfo.isOutermostScope() && "fixup stack phasing error!");
25202525
TableInfo.popScope();
25212526

2522-
TableInfo.Table.push_back(MCD::OPC_Fail);
2527+
TableInfo.Table.insertOpcode(MCD::OPC_Fail);
25232528

25242529
// Print the table to the output stream.
25252530
OpcodeMask |= emitTable(OS, TableInfo.Table, DecoderNamespace, HwModeID,

0 commit comments

Comments
 (0)