diff options
author | Rahul Joshi <rjoshi@nvidia.com> | 2025-04-18 10:08:00 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-04-18 10:08:00 -0700 |
commit | 61820156980ff20ca6e8a7a43a1e9debb950db85 (patch) | |
tree | 44ed3e92cb5880a919d0d5b9fbe57d7fbc4a5c00 /llvm/utils/TableGen/DecoderEmitter.cpp | |
parent | f5947ba5a659d6b3ed62761a7afdf1626435abcb (diff) | |
download | llvm-61820156980ff20ca6e8a7a43a1e9debb950db85.zip llvm-61820156980ff20ca6e8a7a43a1e9debb950db85.tar.gz llvm-61820156980ff20ca6e8a7a43a1e9debb950db85.tar.bz2 |
[NFC][LLVM][TableGen] Adjust pointer increments in DecoderEmitter (#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.
Diffstat (limited to 'llvm/utils/TableGen/DecoderEmitter.cpp')
-rw-r--r-- | llvm/utils/TableGen/DecoderEmitter.cpp | 30 |
1 files changed, 12 insertions, 18 deletions
diff --git a/llvm/utils/TableGen/DecoderEmitter.cpp b/llvm/utils/TableGen/DecoderEmitter.cpp index 485647d..7d63126 100644 --- a/llvm/utils/TableGen/DecoderEmitter.cpp +++ b/llvm/utils/TableGen/DecoderEmitter.cpp @@ -841,11 +841,11 @@ void DecoderEmitter::emitTable(formatted_raw_ostream &OS, DecoderTable &Table, OS << "/* " << Pos << " */"; OS.PadToColumn(12); - switch (*I) { + const uint8_t DecoderOp = *I++; + switch (DecoderOp) { default: - PrintFatalError("invalid decode table opcode"); + PrintFatalError("Invalid decode table opcode: " + Twine(DecoderOp)); case MCD::OPC_ExtractField: { - ++I; OS << Indent << "MCD::OPC_ExtractField, "; // ULEB128 encoded start value. @@ -862,7 +862,6 @@ void DecoderEmitter::emitTable(formatted_raw_ostream &OS, DecoderTable &Table, break; } case MCD::OPC_FilterValue: { - ++I; OS << Indent << "MCD::OPC_FilterValue, "; // The filter value is ULEB128 encoded. emitULEB128(I, OS); @@ -873,7 +872,6 @@ void DecoderEmitter::emitTable(formatted_raw_ostream &OS, DecoderTable &Table, break; } case MCD::OPC_CheckField: { - ++I; OS << Indent << "MCD::OPC_CheckField, "; // ULEB128 encoded start value. emitULEB128(I, OS); @@ -889,7 +887,6 @@ void DecoderEmitter::emitTable(formatted_raw_ostream &OS, DecoderTable &Table, break; } case MCD::OPC_CheckPredicate: { - ++I; OS << Indent << "MCD::OPC_CheckPredicate, "; emitULEB128(I, OS); @@ -900,8 +897,7 @@ void DecoderEmitter::emitTable(formatted_raw_ostream &OS, DecoderTable &Table, } case MCD::OPC_Decode: case MCD::OPC_TryDecode: { - bool IsTry = *I == MCD::OPC_TryDecode; - ++I; + bool IsTry = DecoderOp == MCD::OPC_TryDecode; // Decode the Opcode value. const char *ErrMsg = nullptr; unsigned Opc = decodeULEB128(&*I, nullptr, EndPtr, &ErrMsg); @@ -932,7 +928,6 @@ void DecoderEmitter::emitTable(formatted_raw_ostream &OS, DecoderTable &Table, break; } case MCD::OPC_SoftFail: { - ++I; OS << Indent << "MCD::OPC_SoftFail, "; // Decode the positive mask. const char *ErrMsg = nullptr; @@ -952,7 +947,6 @@ void DecoderEmitter::emitTable(formatted_raw_ostream &OS, DecoderTable &Table, break; } case MCD::OPC_Fail: { - ++I; OS << Indent << "MCD::OPC_Fail,\n"; break; } @@ -2162,13 +2156,13 @@ static DecodeStatus decodeInstruction(const uint8_t DecodeTable[], MCInst &MI, DecodeStatus S = MCDisassembler::Success; while (true) { ptrdiff_t Loc = Ptr - DecodeTable; - switch (*Ptr) { + switch (*Ptr++) { default: errs() << Loc << ": Unexpected decode table opcode!\n"; return MCDisassembler::Fail; case MCD::OPC_ExtractField: { // Decode the start value. - unsigned Start = decodeULEB128AndIncUnsafe(++Ptr); + unsigned Start = decodeULEB128AndIncUnsafe(Ptr); unsigned Len = *Ptr++;)"; if (IsVarLenInst) OS << "\n makeUp(insn, Start + Len);"; @@ -2180,7 +2174,7 @@ static DecodeStatus decodeInstruction(const uint8_t DecodeTable[], MCInst &MI, } case MCD::OPC_FilterValue: { // Decode the field value. - uint64_t Val = decodeULEB128AndIncUnsafe(++Ptr); + uint64_t Val = decodeULEB128AndIncUnsafe(Ptr); bool Failed = Val != CurFieldValue; // NumToSkip is a plain 24-bit integer. unsigned NumToSkip = *Ptr++; @@ -2198,7 +2192,7 @@ static DecodeStatus decodeInstruction(const uint8_t DecodeTable[], MCInst &MI, } case MCD::OPC_CheckField: { // Decode the start value. - unsigned Start = decodeULEB128AndIncUnsafe(++Ptr); + unsigned Start = decodeULEB128AndIncUnsafe(Ptr); unsigned Len = *Ptr;)"; if (IsVarLenInst) OS << "\n makeUp(insn, Start + Len);"; @@ -2226,7 +2220,7 @@ static DecodeStatus decodeInstruction(const uint8_t DecodeTable[], MCInst &MI, } case MCD::OPC_CheckPredicate: { // Decode the Predicate Index value. - unsigned PIdx = decodeULEB128AndIncUnsafe(++Ptr); + unsigned PIdx = decodeULEB128AndIncUnsafe(Ptr); // NumToSkip is a plain 24-bit integer. unsigned NumToSkip = *Ptr++; NumToSkip |= (*Ptr++) << 8; @@ -2242,7 +2236,7 @@ static DecodeStatus decodeInstruction(const uint8_t DecodeTable[], MCInst &MI, } case MCD::OPC_Decode: { // Decode the Opcode value. - unsigned Opc = decodeULEB128AndIncUnsafe(++Ptr); + unsigned Opc = decodeULEB128AndIncUnsafe(Ptr); unsigned DecodeIdx = decodeULEB128AndIncUnsafe(Ptr); MI.clear(); @@ -2263,7 +2257,7 @@ static DecodeStatus decodeInstruction(const uint8_t DecodeTable[], MCInst &MI, } case MCD::OPC_TryDecode: { // Decode the Opcode value. - unsigned Opc = decodeULEB128AndIncUnsafe(++Ptr); + unsigned Opc = decodeULEB128AndIncUnsafe(Ptr); unsigned DecodeIdx = decodeULEB128AndIncUnsafe(Ptr); // NumToSkip is a plain 24-bit integer. unsigned NumToSkip = *Ptr++; @@ -2296,7 +2290,7 @@ static DecodeStatus decodeInstruction(const uint8_t DecodeTable[], MCInst &MI, } case MCD::OPC_SoftFail: { // Decode the mask values. - uint64_t PositiveMask = decodeULEB128AndIncUnsafe(++Ptr); + uint64_t PositiveMask = decodeULEB128AndIncUnsafe(Ptr); uint64_t NegativeMask = decodeULEB128AndIncUnsafe(Ptr); bool Fail = (insn & PositiveMask) != 0 || (~insn & NegativeMask) != 0; if (Fail) |