[llvm] [LLVM][MC][DecoderEmitter] Fail fatally if `Insn` and decoder table bitwidths mismatch (PR #156734)
Sergei Barannikov via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 3 14:50:42 PDT 2025
================
@@ -2108,9 +2121,22 @@ static DecodeStatus decodeInstruction(const uint8_t DecodeTable[], MCInst &MI,
if (HasCheckPredicate)
OS << " const FeatureBitset &Bits = STI.getFeatureBits();\n";
OS << " using namespace llvm::MCD;\n";
+ OS << " const uint8_t *Ptr = DecodeTable;\n";
+
+ if (SpecializeDecodersPerBitwidth) {
+ // Return early if the decoder table's bitwidth does not match `InsnType`
+ // bitwidth.
+ OS << R"(
+ uint32_t BitWidth = decodeULEB128AndIncUnsafe(Ptr);
+ if (InsnBitWidth<InsnType> != BitWidth) {
+ LLVM_DEBUG({
+ dbgs() << "Mismatch between table bitwidth and instruction bitwidth";
+ });
+ return MCDisassembler::Fail;
----------------
s-barannikov wrote:
IMHO returning Fail isn't much better than accepting an invalid table. The developer will still have to use the debugger to figure out what the issue is (or at least enable debug prints, but those can't be enabled in llvm-objdump).
The comment you quoted doesn't look related. I think what it is saying is that instead of trying every table, pre-decode instruction to figure out its size and choose the correct table(s). This saves time on decoding.
It doesn't seem related to table/size mismatch; you will still have to pass insn of the correct type when using a particular table.
https://github.com/llvm/llvm-project/pull/156734
More information about the llvm-commits
mailing list