@@ -78,11 +78,11 @@ static cl::opt<SuppressLevel> DecoderEmitterSuppressDuplicates(
78
78
" significantly reducing Table Duplications" )),
79
79
cl::init(SUPPRESSION_DISABLE), cl::cat(DisassemblerEmitterCat));
80
80
81
- static cl::opt<uint32_t >
82
- NumToSkipSizeInBytes ( " num-to-skip-size " ,
83
- cl::desc (" number of bytes to use for num-to-skip "
84
- " entries in the decoder table (2 or 3) " ),
85
- cl::init(2 ), cl::cat(DisassemblerEmitterCat));
81
+ static cl::opt<bool > LargeTable (
82
+ " large-decoder-table " ,
83
+ cl::desc (" Use large decoder table format. This uses 24 bits for offset \n "
84
+ " in the table instead of the default 16 bits. " ),
85
+ cl::init(false ), cl::cat(DisassemblerEmitterCat));
86
86
87
87
STATISTIC (NumEncodings, " Number of encodings considered" );
88
88
STATISTIC (NumEncodingsLackingDisasm,
@@ -93,6 +93,8 @@ STATISTIC(NumEncodingsOmitted, "Number of encodings omitted");
93
93
94
94
namespace {
95
95
96
+ unsigned getNumToSkipInBytes () { return LargeTable ? 3 : 2 ; }
97
+
96
98
struct EncodingField {
97
99
unsigned Base, Width, Offset;
98
100
EncodingField (unsigned B, unsigned W, unsigned O)
@@ -138,25 +140,25 @@ struct DecoderTable : public std::vector<uint8_t> {
138
140
// in the table for patching.
139
141
size_t insertNumToSkip () {
140
142
size_t Size = size ();
141
- insert (end (), NumToSkipSizeInBytes , 0 );
143
+ insert (end (), getNumToSkipInBytes () , 0 );
142
144
return Size;
143
145
}
144
146
145
147
void patchNumToSkip (size_t FixupIdx, uint32_t DestIdx) {
146
148
// Calculate the distance from the byte following the fixup entry byte
147
149
// to the destination. The Target is calculated from after the
148
- // `NumToSkipSizeInBytes `-byte NumToSkip entry itself, so subtract
149
- // `NumToSkipSizeInBytes ` from the displacement here to account for that.
150
- assert (DestIdx >= FixupIdx + NumToSkipSizeInBytes &&
150
+ // `getNumToSkipInBytes() `-byte NumToSkip entry itself, so subtract
151
+ // `getNumToSkipInBytes() ` from the displacement here to account for that.
152
+ assert (DestIdx >= FixupIdx + getNumToSkipInBytes () &&
151
153
" Expecting a forward jump in the decoding table" );
152
- uint32_t Delta = DestIdx - FixupIdx - NumToSkipSizeInBytes ;
153
- if (!isUIntN (8 * NumToSkipSizeInBytes , Delta))
154
+ uint32_t Delta = DestIdx - FixupIdx - getNumToSkipInBytes () ;
155
+ if (!isUIntN (8 * getNumToSkipInBytes () , Delta))
154
156
PrintFatalError (
155
- " disassembler decoding table too large, try --num-to-skip-size=3 " );
157
+ " disassembler decoding table too large, try --large-decoder-table " );
156
158
157
159
(*this )[FixupIdx] = static_cast <uint8_t >(Delta);
158
160
(*this )[FixupIdx + 1 ] = static_cast <uint8_t >(Delta >> 8 );
159
- if (NumToSkipSizeInBytes == 3 )
161
+ if (getNumToSkipInBytes () == 3 )
160
162
(*this )[FixupIdx + 2 ] = static_cast <uint8_t >(Delta >> 16 );
161
163
}
162
164
};
@@ -824,7 +826,7 @@ void DecoderEmitter::emitTable(formatted_raw_ostream &OS, DecoderTable &Table,
824
826
OS << (unsigned )*I++ << " , " ;
825
827
};
826
828
827
- // Emit `NumToSkipSizeInBytes `-byte numtoskip value to OS, returning the
829
+ // Emit `getNumToSkipInBytes() `-byte numtoskip value to OS, returning the
828
830
// NumToSkip value.
829
831
auto emitNumToSkip = [](DecoderTable::const_iterator &I,
830
832
formatted_raw_ostream &OS) {
@@ -834,7 +836,7 @@ void DecoderEmitter::emitTable(formatted_raw_ostream &OS, DecoderTable &Table,
834
836
Byte = *I++;
835
837
OS << (unsigned )Byte << " , " ;
836
838
NumToSkip |= Byte << 8 ;
837
- if (NumToSkipSizeInBytes == 3 ) {
839
+ if (getNumToSkipInBytes () == 3 ) {
838
840
Byte = *I++;
839
841
OS << (unsigned )(Byte) << " , " ;
840
842
NumToSkip |= Byte << 16 ;
@@ -879,7 +881,6 @@ void DecoderEmitter::emitTable(formatted_raw_ostream &OS, DecoderTable &Table,
879
881
// The filter value is ULEB128 encoded.
880
882
emitULEB128 (I, OS);
881
883
882
- // numtoskip value.
883
884
uint32_t NumToSkip = emitNumToSkip (I, OS);
884
885
OS << " // Skip to: " << ((I - Table.begin ()) + NumToSkip) << " \n " ;
885
886
break ;
@@ -894,7 +895,6 @@ void DecoderEmitter::emitTable(formatted_raw_ostream &OS, DecoderTable &Table,
894
895
// ULEB128 encoded field value.
895
896
emitULEB128 (I, OS);
896
897
897
- // numtoskip value.
898
898
uint32_t NumToSkip = emitNumToSkip (I, OS);
899
899
OS << " // Skip to: " << ((I - Table.begin ()) + NumToSkip) << " \n " ;
900
900
break ;
@@ -903,7 +903,6 @@ void DecoderEmitter::emitTable(formatted_raw_ostream &OS, DecoderTable &Table,
903
903
OS << Indent << " MCD::OPC_CheckPredicate, " ;
904
904
emitULEB128 (I, OS);
905
905
906
- // numtoskip value.
907
906
uint32_t NumToSkip = emitNumToSkip (I, OS);
908
907
OS << " // Skip to: " << ((I - Table.begin ()) + NumToSkip) << " \n " ;
909
908
break ;
@@ -933,7 +932,6 @@ void DecoderEmitter::emitTable(formatted_raw_ostream &OS, DecoderTable &Table,
933
932
934
933
// Fallthrough for OPC_TryDecode.
935
934
936
- // numtoskip value.
937
935
uint32_t NumToSkip = emitNumToSkip (I, OS);
938
936
939
937
OS << " // Opcode: " << NumberedEncodings[EncodingID]
@@ -1405,9 +1403,8 @@ void FilterChooser::emitSingletonTableEntry(DecoderTableInfo &TableInfo,
1405
1403
TableInfo.Table .push_back (NumBits);
1406
1404
TableInfo.Table .insertULEB128 (Ilnd.FieldVal );
1407
1405
1408
- // Allocate space in the table for fixup (NumToSkipSizeInBytes) so all
1409
- // our relative position calculations work OK even before we fully
1410
- // resolve the real value here.
1406
+ // Allocate space in the table for fixup so all our relative position
1407
+ // calculations work OK even before we fully resolve the real value here.
1411
1408
1412
1409
// Push location for NumToSkip backpatching.
1413
1410
TableInfo.FixupStack .back ().push_back (TableInfo.Table .insertNumToSkip ());
@@ -2151,16 +2148,14 @@ insertBits(InsnType &field, uint64_t bits, unsigned startBit, unsigned numBits)
2151
2148
// decodeInstruction().
2152
2149
static void emitDecodeInstruction (formatted_raw_ostream &OS,
2153
2150
bool IsVarLenInst) {
2154
- OS << formatv (" \n constexpr unsigned NumToSkipSizeInBytes = {};\n " ,
2155
- NumToSkipSizeInBytes);
2156
-
2157
2151
OS << R"(
2158
- inline unsigned decodeNumToSkip(const uint8_t *&Ptr) {
2152
+ static unsigned decodeNumToSkip(const uint8_t *&Ptr) {
2159
2153
unsigned NumToSkip = *Ptr++;
2160
2154
NumToSkip |= (*Ptr++) << 8;
2161
- if constexpr (NumToSkipSizeInBytes == 3)
2162
- NumToSkip |= (*Ptr++) << 16;
2163
- return NumToSkip;
2155
+ )" ;
2156
+ if (getNumToSkipInBytes () == 3 )
2157
+ OS << " NumToSkip |= (*Ptr++) << 16;\n " ;
2158
+ OS << R"( return NumToSkip;
2164
2159
}
2165
2160
2166
2161
template <typename InsnType>
@@ -2399,9 +2394,6 @@ handleHwModesUnrelatedEncodings(const CodeGenInstruction *Instr,
2399
2394
2400
2395
// Emits disassembler code for instruction decoding.
2401
2396
void DecoderEmitter::run (raw_ostream &o) {
2402
- if (NumToSkipSizeInBytes != 2 && NumToSkipSizeInBytes != 3 )
2403
- PrintFatalError (" Invalid value for num-to-skip-size, must be 2 or 3" );
2404
-
2405
2397
formatted_raw_ostream OS (o);
2406
2398
OS << R"(
2407
2399
#include "llvm/MC/MCInst.h"
0 commit comments