Skip to content

Commit bfab873

Browse files
committed
[TableGen][DecoderEmitter] Replace opcode mask with booleans (NFC)
To make the future diff smaller.
1 parent 3ef066f commit bfab873

File tree

1 file changed

+28
-31
lines changed

1 file changed

+28
-31
lines changed

llvm/utils/TableGen/DecoderEmitter.cpp

Lines changed: 28 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,9 @@ struct DecoderTableInfo {
226226
DecoderTable Table;
227227
PredicateSet Predicates;
228228
DecoderSet Decoders;
229+
bool HasCheckPredicate;
230+
bool HasSoftFail;
231+
bool HasTryDecode;
229232

230233
void insertPredicate(StringRef Predicate) {
231234
Predicates.insert(CachedHashString(Predicate));
@@ -266,11 +269,10 @@ class DecoderEmitter {
266269

267270
const CodeGenTarget &getTarget() const { return Target; }
268271

269-
// Emit the decoder state machine table. Returns a mask of MCD decoder ops
270-
// that were emitted.
271-
unsigned emitTable(formatted_raw_ostream &OS, DecoderTable &Table,
272-
StringRef Namespace, unsigned HwModeID, unsigned BitWidth,
273-
ArrayRef<unsigned> EncodingIDs) const;
272+
// Emit the decoder state machine table.
273+
void emitTable(formatted_raw_ostream &OS, DecoderTableInfo &TableInfo,
274+
StringRef Namespace, unsigned HwModeID, unsigned BitWidth,
275+
ArrayRef<unsigned> EncodingIDs) const;
274276
void emitInstrLenTable(formatted_raw_ostream &OS,
275277
ArrayRef<unsigned> InstrLen) const;
276278
void emitPredicateFunction(formatted_raw_ostream &OS,
@@ -629,12 +631,11 @@ static StringRef getDecoderOpName(DecoderOps Op) {
629631
llvm_unreachable("Unknown decoder op");
630632
}
631633

632-
// Emit the decoder state machine table. Returns a mask of MCD decoder ops
633-
// that were emitted.
634-
unsigned DecoderEmitter::emitTable(formatted_raw_ostream &OS,
635-
DecoderTable &Table, StringRef Namespace,
636-
unsigned HwModeID, unsigned BitWidth,
637-
ArrayRef<unsigned> EncodingIDs) const {
634+
// Emit the decoder state machine table.
635+
void DecoderEmitter::emitTable(formatted_raw_ostream &OS,
636+
DecoderTableInfo &TableInfo, StringRef Namespace,
637+
unsigned HwModeID, unsigned BitWidth,
638+
ArrayRef<unsigned> EncodingIDs) const {
638639
// We'll need to be able to map from a decoded opcode into the corresponding
639640
// EncodingID for this specific combination of BitWidth and Namespace. This
640641
// is used below to index into Encodings.
@@ -648,7 +649,7 @@ unsigned DecoderEmitter::emitTable(formatted_raw_ostream &OS,
648649
OS << "static const uint8_t DecoderTable" << Namespace;
649650
if (HwModeID != DefaultMode)
650651
OS << '_' << Target.getHwModes().getModeName(HwModeID);
651-
OS << BitWidth << "[" << Table.size() << "] = {\n";
652+
OS << BitWidth << "[" << TableInfo.Table.size() << "] = {\n";
652653

653654
// Emit ULEB128 encoded value to OS, returning the number of bytes emitted.
654655
auto EmitULEB128 = [](DecoderTable::const_iterator &I,
@@ -678,6 +679,7 @@ unsigned DecoderEmitter::emitTable(formatted_raw_ostream &OS,
678679

679680
// FIXME: We may be able to use the NumToSkip values to recover
680681
// appropriate indentation levels.
682+
DecoderTable &Table = TableInfo.Table;
681683
DecoderTable::const_iterator I = Table.begin();
682684
DecoderTable::const_iterator E = Table.end();
683685
const uint8_t *const EndPtr = Table.data() + Table.size();
@@ -826,8 +828,6 @@ unsigned DecoderEmitter::emitTable(formatted_raw_ostream &OS,
826828
OS << '\n';
827829
}
828830
OS << "};\n\n";
829-
830-
return OpcodeMask;
831831
}
832832

833833
void DecoderEmitter::emitInstrLenTable(formatted_raw_ostream &OS,
@@ -1114,6 +1114,7 @@ void DecoderTableBuilder::emitPredicateTableEntry(unsigned EncodingID) const {
11141114

11151115
TableInfo.Table.insertOpcode(OPC_CheckPredicate);
11161116
TableInfo.Table.insertULEB128(PredicateIndex);
1117+
TableInfo.HasCheckPredicate = true;
11171118
}
11181119

11191120
void DecoderTableBuilder::emitSoftFailTableEntry(unsigned EncodingID) const {
@@ -1130,6 +1131,7 @@ void DecoderTableBuilder::emitSoftFailTableEntry(unsigned EncodingID) const {
11301131
TableInfo.Table.insertOpcode(OPC_SoftFail);
11311132
TableInfo.Table.insertULEB128(PositiveMask.getZExtValue());
11321133
TableInfo.Table.insertULEB128(NegativeMask.getZExtValue());
1134+
TableInfo.HasCheckPredicate = true;
11331135
}
11341136

11351137
// Emits table entries to decode the singleton.
@@ -1180,6 +1182,8 @@ void DecoderTableBuilder::emitSingletonTableEntry(
11801182
const Record *InstDef = Encodings[EncodingID].getInstruction()->TheDef;
11811183
TableInfo.Table.insertULEB128(Target.getInstrIntValue(InstDef));
11821184
TableInfo.Table.insertULEB128(DecoderIndex);
1185+
if (DecoderOp == OPC_TryDecode)
1186+
TableInfo.HasTryDecode = true;
11831187
}
11841188

11851189
std::unique_ptr<Filter>
@@ -1523,11 +1527,7 @@ void DecoderTableBuilder::emitTableEntries(const FilterChooser &FC) const {
15231527
// emitDecodeInstruction - Emit the templated helper function
15241528
// decodeInstruction().
15251529
static void emitDecodeInstruction(formatted_raw_ostream &OS, bool IsVarLenInst,
1526-
unsigned OpcodeMask) {
1527-
const bool HasTryDecode = OpcodeMask & (1 << OPC_TryDecode);
1528-
const bool HasCheckPredicate = OpcodeMask & (1 << OPC_CheckPredicate);
1529-
const bool HasSoftFail = OpcodeMask & (1 << OPC_SoftFail);
1530-
1530+
const DecoderTableInfo &TableInfo) {
15311531
OS << R"(
15321532
static unsigned decodeNumToSkip(const uint8_t *&Ptr) {
15331533
unsigned NumToSkip = *Ptr++;
@@ -1548,7 +1548,7 @@ static DecodeStatus decodeInstruction(const uint8_t DecodeTable[], MCInst &MI,
15481548
"llvm::function_ref<void(APInt &, uint64_t)> makeUp";
15491549
}
15501550
OS << ") {\n";
1551-
if (HasCheckPredicate)
1551+
if (TableInfo.HasCheckPredicate)
15521552
OS << " const FeatureBitset &Bits = STI.getFeatureBits();\n";
15531553
OS << " const uint8_t *Ptr = DecodeTable;\n";
15541554

@@ -1657,7 +1657,7 @@ static DecodeStatus decodeInstruction(const uint8_t DecodeTable[], MCInst &MI,
16571657
}
16581658
break;
16591659
})";
1660-
if (HasCheckPredicate) {
1660+
if (TableInfo.HasCheckPredicate) {
16611661
OS << R"(
16621662
case OPC_CheckPredicate: {
16631663
// Decode the Predicate Index value.
@@ -1701,7 +1701,7 @@ static DecodeStatus decodeInstruction(const uint8_t DecodeTable[], MCInst &MI,
17011701
<< (S != MCDisassembler::Fail ? "PASS\n" : "FAIL\n"));
17021702
return S;
17031703
})";
1704-
if (HasTryDecode) {
1704+
if (TableInfo.HasTryDecode) {
17051705
OS << R"(
17061706
case OPC_TryDecode: {
17071707
// Decode the Opcode value.
@@ -1735,7 +1735,7 @@ static DecodeStatus decodeInstruction(const uint8_t DecodeTable[], MCInst &MI,
17351735
break;
17361736
})";
17371737
}
1738-
if (HasSoftFail) {
1738+
if (TableInfo.HasSoftFail) {
17391739
OS << R"(
17401740
case OPC_SoftFail: {
17411741
// Decode the mask values.
@@ -1994,9 +1994,8 @@ template <typename T> constexpr uint32_t InsnBitWidth = 0;
19941994

19951995
// Entries in `EncMap` are already sorted by bitwidth. So bucketing per
19961996
// bitwidth can be done on-the-fly as we iterate over the map.
1997-
DecoderTableInfo TableInfo;
1997+
DecoderTableInfo TableInfo{};
19981998
DecoderTableBuilder TableBuilder(Target, Encodings, TableInfo);
1999-
unsigned OpcodeMask = 0;
20001999

20012000
bool HasConflict = false;
20022001
for (const auto &[BitWidth, BWMap] : EncMap) {
@@ -2021,8 +2020,8 @@ template <typename T> constexpr uint32_t InsnBitWidth = 0;
20212020
TableBuilder.buildTable(FC, BitWidth);
20222021

20232022
// Print the table to the output stream.
2024-
OpcodeMask |= emitTable(OS, TableInfo.Table, DecoderNamespace, HwModeID,
2025-
BitWidth, EncodingIDs);
2023+
emitTable(OS, TableInfo, DecoderNamespace, HwModeID, BitWidth,
2024+
EncodingIDs);
20262025
}
20272026

20282027
// Each BitWidth get's its own decoders and decoder function if
@@ -2041,14 +2040,12 @@ template <typename T> constexpr uint32_t InsnBitWidth = 0;
20412040
if (!SpecializeDecodersPerBitwidth)
20422041
emitDecoderFunction(OS, TableInfo.Decoders, 0);
20432042

2044-
const bool HasCheckPredicate = OpcodeMask & (1 << OPC_CheckPredicate);
2045-
20462043
// Emit the predicate function.
2047-
if (HasCheckPredicate)
2044+
if (TableInfo.HasCheckPredicate)
20482045
emitPredicateFunction(OS, TableInfo.Predicates);
20492046

20502047
// Emit the main entry point for the decoder, decodeInstruction().
2051-
emitDecodeInstruction(OS, IsVarLenInst, OpcodeMask);
2048+
emitDecodeInstruction(OS, IsVarLenInst, TableInfo);
20522049

20532050
OS << "\n} // namespace\n";
20542051
}

0 commit comments

Comments
 (0)