Skip to content

Commit 6182015

Browse files
authored
[NFC][LLVM][TableGen] Adjust pointer increments in DecoderEmitter (llvm#136230)
- In both `emitTable` and the generated `decodeInstruction` function increment the pointer to the decoder op as a part of the switch statement instead of later on in each case.
1 parent f5947ba commit 6182015

File tree

1 file changed

+12
-18
lines changed

1 file changed

+12
-18
lines changed

llvm/utils/TableGen/DecoderEmitter.cpp

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -841,11 +841,11 @@ void DecoderEmitter::emitTable(formatted_raw_ostream &OS, DecoderTable &Table,
841841
OS << "/* " << Pos << " */";
842842
OS.PadToColumn(12);
843843

844-
switch (*I) {
844+
const uint8_t DecoderOp = *I++;
845+
switch (DecoderOp) {
845846
default:
846-
PrintFatalError("invalid decode table opcode");
847+
PrintFatalError("Invalid decode table opcode: " + Twine(DecoderOp));
847848
case MCD::OPC_ExtractField: {
848-
++I;
849849
OS << Indent << "MCD::OPC_ExtractField, ";
850850

851851
// ULEB128 encoded start value.
@@ -862,7 +862,6 @@ void DecoderEmitter::emitTable(formatted_raw_ostream &OS, DecoderTable &Table,
862862
break;
863863
}
864864
case MCD::OPC_FilterValue: {
865-
++I;
866865
OS << Indent << "MCD::OPC_FilterValue, ";
867866
// The filter value is ULEB128 encoded.
868867
emitULEB128(I, OS);
@@ -873,7 +872,6 @@ void DecoderEmitter::emitTable(formatted_raw_ostream &OS, DecoderTable &Table,
873872
break;
874873
}
875874
case MCD::OPC_CheckField: {
876-
++I;
877875
OS << Indent << "MCD::OPC_CheckField, ";
878876
// ULEB128 encoded start value.
879877
emitULEB128(I, OS);
@@ -889,7 +887,6 @@ void DecoderEmitter::emitTable(formatted_raw_ostream &OS, DecoderTable &Table,
889887
break;
890888
}
891889
case MCD::OPC_CheckPredicate: {
892-
++I;
893890
OS << Indent << "MCD::OPC_CheckPredicate, ";
894891
emitULEB128(I, OS);
895892

@@ -900,8 +897,7 @@ void DecoderEmitter::emitTable(formatted_raw_ostream &OS, DecoderTable &Table,
900897
}
901898
case MCD::OPC_Decode:
902899
case MCD::OPC_TryDecode: {
903-
bool IsTry = *I == MCD::OPC_TryDecode;
904-
++I;
900+
bool IsTry = DecoderOp == MCD::OPC_TryDecode;
905901
// Decode the Opcode value.
906902
const char *ErrMsg = nullptr;
907903
unsigned Opc = decodeULEB128(&*I, nullptr, EndPtr, &ErrMsg);
@@ -932,7 +928,6 @@ void DecoderEmitter::emitTable(formatted_raw_ostream &OS, DecoderTable &Table,
932928
break;
933929
}
934930
case MCD::OPC_SoftFail: {
935-
++I;
936931
OS << Indent << "MCD::OPC_SoftFail, ";
937932
// Decode the positive mask.
938933
const char *ErrMsg = nullptr;
@@ -952,7 +947,6 @@ void DecoderEmitter::emitTable(formatted_raw_ostream &OS, DecoderTable &Table,
952947
break;
953948
}
954949
case MCD::OPC_Fail: {
955-
++I;
956950
OS << Indent << "MCD::OPC_Fail,\n";
957951
break;
958952
}
@@ -2162,13 +2156,13 @@ static DecodeStatus decodeInstruction(const uint8_t DecodeTable[], MCInst &MI,
21622156
DecodeStatus S = MCDisassembler::Success;
21632157
while (true) {
21642158
ptrdiff_t Loc = Ptr - DecodeTable;
2165-
switch (*Ptr) {
2159+
switch (*Ptr++) {
21662160
default:
21672161
errs() << Loc << ": Unexpected decode table opcode!\n";
21682162
return MCDisassembler::Fail;
21692163
case MCD::OPC_ExtractField: {
21702164
// Decode the start value.
2171-
unsigned Start = decodeULEB128AndIncUnsafe(++Ptr);
2165+
unsigned Start = decodeULEB128AndIncUnsafe(Ptr);
21722166
unsigned Len = *Ptr++;)";
21732167
if (IsVarLenInst)
21742168
OS << "\n makeUp(insn, Start + Len);";
@@ -2180,7 +2174,7 @@ static DecodeStatus decodeInstruction(const uint8_t DecodeTable[], MCInst &MI,
21802174
}
21812175
case MCD::OPC_FilterValue: {
21822176
// Decode the field value.
2183-
uint64_t Val = decodeULEB128AndIncUnsafe(++Ptr);
2177+
uint64_t Val = decodeULEB128AndIncUnsafe(Ptr);
21842178
bool Failed = Val != CurFieldValue;
21852179
// NumToSkip is a plain 24-bit integer.
21862180
unsigned NumToSkip = *Ptr++;
@@ -2198,7 +2192,7 @@ static DecodeStatus decodeInstruction(const uint8_t DecodeTable[], MCInst &MI,
21982192
}
21992193
case MCD::OPC_CheckField: {
22002194
// Decode the start value.
2201-
unsigned Start = decodeULEB128AndIncUnsafe(++Ptr);
2195+
unsigned Start = decodeULEB128AndIncUnsafe(Ptr);
22022196
unsigned Len = *Ptr;)";
22032197
if (IsVarLenInst)
22042198
OS << "\n makeUp(insn, Start + Len);";
@@ -2226,7 +2220,7 @@ static DecodeStatus decodeInstruction(const uint8_t DecodeTable[], MCInst &MI,
22262220
}
22272221
case MCD::OPC_CheckPredicate: {
22282222
// Decode the Predicate Index value.
2229-
unsigned PIdx = decodeULEB128AndIncUnsafe(++Ptr);
2223+
unsigned PIdx = decodeULEB128AndIncUnsafe(Ptr);
22302224
// NumToSkip is a plain 24-bit integer.
22312225
unsigned NumToSkip = *Ptr++;
22322226
NumToSkip |= (*Ptr++) << 8;
@@ -2242,7 +2236,7 @@ static DecodeStatus decodeInstruction(const uint8_t DecodeTable[], MCInst &MI,
22422236
}
22432237
case MCD::OPC_Decode: {
22442238
// Decode the Opcode value.
2245-
unsigned Opc = decodeULEB128AndIncUnsafe(++Ptr);
2239+
unsigned Opc = decodeULEB128AndIncUnsafe(Ptr);
22462240
unsigned DecodeIdx = decodeULEB128AndIncUnsafe(Ptr);
22472241
22482242
MI.clear();
@@ -2263,7 +2257,7 @@ static DecodeStatus decodeInstruction(const uint8_t DecodeTable[], MCInst &MI,
22632257
}
22642258
case MCD::OPC_TryDecode: {
22652259
// Decode the Opcode value.
2266-
unsigned Opc = decodeULEB128AndIncUnsafe(++Ptr);
2260+
unsigned Opc = decodeULEB128AndIncUnsafe(Ptr);
22672261
unsigned DecodeIdx = decodeULEB128AndIncUnsafe(Ptr);
22682262
// NumToSkip is a plain 24-bit integer.
22692263
unsigned NumToSkip = *Ptr++;
@@ -2296,7 +2290,7 @@ static DecodeStatus decodeInstruction(const uint8_t DecodeTable[], MCInst &MI,
22962290
}
22972291
case MCD::OPC_SoftFail: {
22982292
// Decode the mask values.
2299-
uint64_t PositiveMask = decodeULEB128AndIncUnsafe(++Ptr);
2293+
uint64_t PositiveMask = decodeULEB128AndIncUnsafe(Ptr);
23002294
uint64_t NegativeMask = decodeULEB128AndIncUnsafe(Ptr);
23012295
bool Fail = (insn & PositiveMask) != 0 || (~insn & NegativeMask) != 0;
23022296
if (Fail)

0 commit comments

Comments
 (0)