@@ -78,11 +78,11 @@ static cl::opt<SuppressLevel> DecoderEmitterSuppressDuplicates(
7878 " significantly reducing Table Duplications" )),
7979 cl::init(SUPPRESSION_DISABLE), cl::cat(DisassemblerEmitterCat));
8080
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));
8686
8787STATISTIC (NumEncodings, " Number of encodings considered" );
8888STATISTIC (NumEncodingsLackingDisasm,
@@ -93,6 +93,8 @@ STATISTIC(NumEncodingsOmitted, "Number of encodings omitted");
9393
9494namespace {
9595
96+ unsigned getNumToSkipInBytes () { return LargeTable ? 3 : 2 ; }
97+
9698struct EncodingField {
9799 unsigned Base, Width, Offset;
98100 EncodingField (unsigned B, unsigned W, unsigned O)
@@ -138,25 +140,25 @@ struct DecoderTable : public std::vector<uint8_t> {
138140 // in the table for patching.
139141 size_t insertNumToSkip () {
140142 size_t Size = size ();
141- insert (end (), NumToSkipSizeInBytes , 0 );
143+ insert (end (), getNumToSkipInBytes () , 0 );
142144 return Size;
143145 }
144146
145147 void patchNumToSkip (size_t FixupIdx, uint32_t DestIdx) {
146148 // Calculate the distance from the byte following the fixup entry byte
147149 // 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 () &&
151153 " 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))
154156 PrintFatalError (
155- " disassembler decoding table too large, try --num-to-skip-size=3 " );
157+ " disassembler decoding table too large, try --large-decoder-table " );
156158
157159 (*this )[FixupIdx] = static_cast <uint8_t >(Delta);
158160 (*this )[FixupIdx + 1 ] = static_cast <uint8_t >(Delta >> 8 );
159- if (NumToSkipSizeInBytes == 3 )
161+ if (getNumToSkipInBytes () == 3 )
160162 (*this )[FixupIdx + 2 ] = static_cast <uint8_t >(Delta >> 16 );
161163 }
162164};
@@ -824,7 +826,7 @@ void DecoderEmitter::emitTable(formatted_raw_ostream &OS, DecoderTable &Table,
824826 OS << (unsigned )*I++ << " , " ;
825827 };
826828
827- // Emit `NumToSkipSizeInBytes `-byte numtoskip value to OS, returning the
829+ // Emit `getNumToSkipInBytes() `-byte numtoskip value to OS, returning the
828830 // NumToSkip value.
829831 auto emitNumToSkip = [](DecoderTable::const_iterator &I,
830832 formatted_raw_ostream &OS) {
@@ -834,7 +836,7 @@ void DecoderEmitter::emitTable(formatted_raw_ostream &OS, DecoderTable &Table,
834836 Byte = *I++;
835837 OS << (unsigned )Byte << " , " ;
836838 NumToSkip |= Byte << 8 ;
837- if (NumToSkipSizeInBytes == 3 ) {
839+ if (getNumToSkipInBytes () == 3 ) {
838840 Byte = *I++;
839841 OS << (unsigned )(Byte) << " , " ;
840842 NumToSkip |= Byte << 16 ;
@@ -879,7 +881,6 @@ void DecoderEmitter::emitTable(formatted_raw_ostream &OS, DecoderTable &Table,
879881 // The filter value is ULEB128 encoded.
880882 emitULEB128 (I, OS);
881883
882- // numtoskip value.
883884 uint32_t NumToSkip = emitNumToSkip (I, OS);
884885 OS << " // Skip to: " << ((I - Table.begin ()) + NumToSkip) << " \n " ;
885886 break ;
@@ -894,7 +895,6 @@ void DecoderEmitter::emitTable(formatted_raw_ostream &OS, DecoderTable &Table,
894895 // ULEB128 encoded field value.
895896 emitULEB128 (I, OS);
896897
897- // numtoskip value.
898898 uint32_t NumToSkip = emitNumToSkip (I, OS);
899899 OS << " // Skip to: " << ((I - Table.begin ()) + NumToSkip) << " \n " ;
900900 break ;
@@ -903,7 +903,6 @@ void DecoderEmitter::emitTable(formatted_raw_ostream &OS, DecoderTable &Table,
903903 OS << Indent << " MCD::OPC_CheckPredicate, " ;
904904 emitULEB128 (I, OS);
905905
906- // numtoskip value.
907906 uint32_t NumToSkip = emitNumToSkip (I, OS);
908907 OS << " // Skip to: " << ((I - Table.begin ()) + NumToSkip) << " \n " ;
909908 break ;
@@ -933,7 +932,6 @@ void DecoderEmitter::emitTable(formatted_raw_ostream &OS, DecoderTable &Table,
933932
934933 // Fallthrough for OPC_TryDecode.
935934
936- // numtoskip value.
937935 uint32_t NumToSkip = emitNumToSkip (I, OS);
938936
939937 OS << " // Opcode: " << NumberedEncodings[EncodingID]
@@ -1405,9 +1403,8 @@ void FilterChooser::emitSingletonTableEntry(DecoderTableInfo &TableInfo,
14051403 TableInfo.Table .push_back (NumBits);
14061404 TableInfo.Table .insertULEB128 (Ilnd.FieldVal );
14071405
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.
14111408
14121409 // Push location for NumToSkip backpatching.
14131410 TableInfo.FixupStack .back ().push_back (TableInfo.Table .insertNumToSkip ());
@@ -2151,16 +2148,14 @@ insertBits(InsnType &field, uint64_t bits, unsigned startBit, unsigned numBits)
21512148// decodeInstruction().
21522149static void emitDecodeInstruction (formatted_raw_ostream &OS,
21532150 bool IsVarLenInst) {
2154- OS << formatv (" \n constexpr unsigned NumToSkipSizeInBytes = {};\n " ,
2155- NumToSkipSizeInBytes);
2156-
21572151 OS << R"(
2158- inline unsigned decodeNumToSkip(const uint8_t *&Ptr) {
2152+ static unsigned decodeNumToSkip(const uint8_t *&Ptr) {
21592153 unsigned NumToSkip = *Ptr++;
21602154 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;
21642159}
21652160
21662161template <typename InsnType>
@@ -2399,9 +2394,6 @@ handleHwModesUnrelatedEncodings(const CodeGenInstruction *Instr,
23992394
24002395// Emits disassembler code for instruction decoding.
24012396void 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-
24052397 formatted_raw_ostream OS (o);
24062398 OS << R"(
24072399#include "llvm/MC/MCInst.h"
0 commit comments