@@ -226,6 +226,9 @@ struct DecoderTableInfo {
226
226
DecoderTable Table;
227
227
PredicateSet Predicates;
228
228
DecoderSet Decoders;
229
+ bool HasCheckPredicate;
230
+ bool HasSoftFail;
231
+ bool HasTryDecode;
229
232
230
233
void insertPredicate (StringRef Predicate) {
231
234
Predicates.insert (CachedHashString (Predicate));
@@ -266,11 +269,10 @@ class DecoderEmitter {
266
269
267
270
const CodeGenTarget &getTarget () const { return Target; }
268
271
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 ;
274
276
void emitInstrLenTable (formatted_raw_ostream &OS,
275
277
ArrayRef<unsigned > InstrLen) const ;
276
278
void emitPredicateFunction (formatted_raw_ostream &OS,
@@ -629,12 +631,11 @@ static StringRef getDecoderOpName(DecoderOps Op) {
629
631
llvm_unreachable (" Unknown decoder op" );
630
632
}
631
633
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 {
638
639
// We'll need to be able to map from a decoded opcode into the corresponding
639
640
// EncodingID for this specific combination of BitWidth and Namespace. This
640
641
// is used below to index into Encodings.
@@ -648,7 +649,7 @@ unsigned DecoderEmitter::emitTable(formatted_raw_ostream &OS,
648
649
OS << " static const uint8_t DecoderTable" << Namespace;
649
650
if (HwModeID != DefaultMode)
650
651
OS << ' _' << Target.getHwModes ().getModeName (HwModeID);
651
- OS << BitWidth << " [" << Table.size () << " ] = {\n " ;
652
+ OS << BitWidth << " [" << TableInfo. Table .size () << " ] = {\n " ;
652
653
653
654
// Emit ULEB128 encoded value to OS, returning the number of bytes emitted.
654
655
auto EmitULEB128 = [](DecoderTable::const_iterator &I,
@@ -678,6 +679,7 @@ unsigned DecoderEmitter::emitTable(formatted_raw_ostream &OS,
678
679
679
680
// FIXME: We may be able to use the NumToSkip values to recover
680
681
// appropriate indentation levels.
682
+ DecoderTable &Table = TableInfo.Table ;
681
683
DecoderTable::const_iterator I = Table.begin ();
682
684
DecoderTable::const_iterator E = Table.end ();
683
685
const uint8_t *const EndPtr = Table.data () + Table.size ();
@@ -719,15 +721,12 @@ unsigned DecoderEmitter::emitTable(formatted_raw_ostream &OS,
719
721
return Value;
720
722
};
721
723
722
- unsigned OpcodeMask = 0 ;
723
-
724
724
while (I != E) {
725
725
assert (I < E && " incomplete decode table entry!" );
726
726
727
727
uint32_t Pos = I - Table.begin ();
728
728
EmitPos (Pos);
729
729
const uint8_t DecoderOp = *I++;
730
- OpcodeMask |= (1 << DecoderOp);
731
730
OS << getDecoderOpName (static_cast <DecoderOps>(DecoderOp)) << " , " ;
732
731
switch (DecoderOp) {
733
732
default :
@@ -826,8 +825,6 @@ unsigned DecoderEmitter::emitTable(formatted_raw_ostream &OS,
826
825
OS << ' \n ' ;
827
826
}
828
827
OS << " };\n\n " ;
829
-
830
- return OpcodeMask;
831
828
}
832
829
833
830
void DecoderEmitter::emitInstrLenTable (formatted_raw_ostream &OS,
@@ -1114,6 +1111,7 @@ void DecoderTableBuilder::emitPredicateTableEntry(unsigned EncodingID) const {
1114
1111
1115
1112
TableInfo.Table .insertOpcode (OPC_CheckPredicate);
1116
1113
TableInfo.Table .insertULEB128 (PredicateIndex);
1114
+ TableInfo.HasCheckPredicate = true ;
1117
1115
}
1118
1116
1119
1117
void DecoderTableBuilder::emitSoftFailTableEntry (unsigned EncodingID) const {
@@ -1130,6 +1128,7 @@ void DecoderTableBuilder::emitSoftFailTableEntry(unsigned EncodingID) const {
1130
1128
TableInfo.Table .insertOpcode (OPC_SoftFail);
1131
1129
TableInfo.Table .insertULEB128 (PositiveMask.getZExtValue ());
1132
1130
TableInfo.Table .insertULEB128 (NegativeMask.getZExtValue ());
1131
+ TableInfo.HasSoftFail = true ;
1133
1132
}
1134
1133
1135
1134
// Emits table entries to decode the singleton.
@@ -1180,6 +1179,7 @@ void DecoderTableBuilder::emitSingletonTableEntry(
1180
1179
const Record *InstDef = Encodings[EncodingID].getInstruction ()->TheDef ;
1181
1180
TableInfo.Table .insertULEB128 (Target.getInstrIntValue (InstDef));
1182
1181
TableInfo.Table .insertULEB128 (DecoderIndex);
1182
+ TableInfo.HasTryDecode |= DecoderOp == OPC_TryDecode;
1183
1183
}
1184
1184
1185
1185
std::unique_ptr<Filter>
@@ -1523,11 +1523,7 @@ void DecoderTableBuilder::emitTableEntries(const FilterChooser &FC) const {
1523
1523
// emitDecodeInstruction - Emit the templated helper function
1524
1524
// decodeInstruction().
1525
1525
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
-
1526
+ const DecoderTableInfo &TableInfo) {
1531
1527
OS << R"(
1532
1528
static unsigned decodeNumToSkip(const uint8_t *&Ptr) {
1533
1529
unsigned NumToSkip = *Ptr++;
@@ -1548,7 +1544,7 @@ static DecodeStatus decodeInstruction(const uint8_t DecodeTable[], MCInst &MI,
1548
1544
" llvm::function_ref<void(APInt &, uint64_t)> makeUp" ;
1549
1545
}
1550
1546
OS << " ) {\n " ;
1551
- if (HasCheckPredicate)
1547
+ if (TableInfo. HasCheckPredicate )
1552
1548
OS << " const FeatureBitset &Bits = STI.getFeatureBits();\n " ;
1553
1549
OS << " const uint8_t *Ptr = DecodeTable;\n " ;
1554
1550
@@ -1657,7 +1653,7 @@ static DecodeStatus decodeInstruction(const uint8_t DecodeTable[], MCInst &MI,
1657
1653
}
1658
1654
break;
1659
1655
})" ;
1660
- if (HasCheckPredicate) {
1656
+ if (TableInfo. HasCheckPredicate ) {
1661
1657
OS << R"(
1662
1658
case OPC_CheckPredicate: {
1663
1659
// Decode the Predicate Index value.
@@ -1701,7 +1697,7 @@ static DecodeStatus decodeInstruction(const uint8_t DecodeTable[], MCInst &MI,
1701
1697
<< (S != MCDisassembler::Fail ? "PASS\n" : "FAIL\n"));
1702
1698
return S;
1703
1699
})" ;
1704
- if (HasTryDecode) {
1700
+ if (TableInfo. HasTryDecode ) {
1705
1701
OS << R"(
1706
1702
case OPC_TryDecode: {
1707
1703
// Decode the Opcode value.
@@ -1735,7 +1731,7 @@ static DecodeStatus decodeInstruction(const uint8_t DecodeTable[], MCInst &MI,
1735
1731
break;
1736
1732
})" ;
1737
1733
}
1738
- if (HasSoftFail) {
1734
+ if (TableInfo. HasSoftFail ) {
1739
1735
OS << R"(
1740
1736
case OPC_SoftFail: {
1741
1737
// Decode the mask values.
@@ -1994,9 +1990,8 @@ template <typename T> constexpr uint32_t InsnBitWidth = 0;
1994
1990
1995
1991
// Entries in `EncMap` are already sorted by bitwidth. So bucketing per
1996
1992
// bitwidth can be done on-the-fly as we iterate over the map.
1997
- DecoderTableInfo TableInfo;
1993
+ DecoderTableInfo TableInfo{} ;
1998
1994
DecoderTableBuilder TableBuilder (Target, Encodings, TableInfo);
1999
- unsigned OpcodeMask = 0 ;
2000
1995
2001
1996
bool HasConflict = false ;
2002
1997
for (const auto &[BitWidth, BWMap] : EncMap) {
@@ -2021,8 +2016,8 @@ template <typename T> constexpr uint32_t InsnBitWidth = 0;
2021
2016
TableBuilder.buildTable (FC, BitWidth);
2022
2017
2023
2018
// Print the table to the output stream.
2024
- OpcodeMask |= emitTable (OS, TableInfo. Table , DecoderNamespace, HwModeID,
2025
- BitWidth, EncodingIDs);
2019
+ emitTable (OS, TableInfo, DecoderNamespace, HwModeID, BitWidth ,
2020
+ EncodingIDs);
2026
2021
}
2027
2022
2028
2023
// Each BitWidth get's its own decoders and decoder function if
@@ -2041,14 +2036,12 @@ template <typename T> constexpr uint32_t InsnBitWidth = 0;
2041
2036
if (!SpecializeDecodersPerBitwidth)
2042
2037
emitDecoderFunction (OS, TableInfo.Decoders , 0 );
2043
2038
2044
- const bool HasCheckPredicate = OpcodeMask & (1 << OPC_CheckPredicate);
2045
-
2046
2039
// Emit the predicate function.
2047
- if (HasCheckPredicate)
2040
+ if (TableInfo. HasCheckPredicate )
2048
2041
emitPredicateFunction (OS, TableInfo.Predicates );
2049
2042
2050
2043
// Emit the main entry point for the decoder, decodeInstruction().
2051
- emitDecodeInstruction (OS, IsVarLenInst, OpcodeMask );
2044
+ emitDecodeInstruction (OS, IsVarLenInst, TableInfo );
2052
2045
2053
2046
OS << " \n } // namespace\n " ;
2054
2047
}
0 commit comments