[llvm] [NFC][TableGen] Print DecodeIdx for DecodeOps in DecoderEmitter (PR #142963)
Rahul Joshi via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 5 06:35:36 PDT 2025
https://github.com/jurahul created https://github.com/llvm/llvm-project/pull/142963
Print DecodeIdx associated with Decode MCD ops in the generated decoder tables. This can help in debugging decode failures by first mapping the Op -> DecodeIdx and then inspecting the code in `decodeToMCInst` associated with that DecodeIdx.
>From 17e1470f7e462119d2cc8bef62c25b16b87aca1d Mon Sep 17 00:00:00 2001
From: Rahul Joshi <rjoshi at nvidia.com>
Date: Thu, 5 Jun 2025 06:30:17 -0700
Subject: [PATCH] [NFC][TableGen] Print DecodeIdx for DecodeOps in
DecoderEmitter
Print DecodeIdx associated with Decode MCD ops in the generated
decoder tables. This can help in debugging decode failures by
first mapping the Op -> DecodeIdx and then inspecting the code
in `decodeToMCInst` associated with that DecodeIdx.
---
llvm/utils/TableGen/DecoderEmitter.cpp | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
diff --git a/llvm/utils/TableGen/DecoderEmitter.cpp b/llvm/utils/TableGen/DecoderEmitter.cpp
index 3990836e9077f..7717d1340e7a3 100644
--- a/llvm/utils/TableGen/DecoderEmitter.cpp
+++ b/llvm/utils/TableGen/DecoderEmitter.cpp
@@ -975,25 +975,26 @@ void DecoderEmitter::emitTable(formatted_raw_ostream &OS, DecoderTable &Table,
emitULEB128(I, OS);
// Decoder index.
+ unsigned DecodeIdx = decodeULEB128(&*I, nullptr, EndPtr, &ErrMsg);
+ assert(ErrMsg == nullptr && "ULEB128 value too large!");
emitULEB128(I, OS);
auto EncI = OpcodeToEncodingID.find(Opc);
assert(EncI != OpcodeToEncodingID.end() && "no encoding entry");
auto EncodingID = EncI->second;
+ OS << "// Opcode: " << NumberedEncodings[EncodingID]
+ << ", DecodeIdx: " << DecodeIdx;
+
if (!IsTry) {
- OS << "// Opcode: " << NumberedEncodings[EncodingID] << "\n";
+ OS << '\n';
break;
}
// Fallthrough for OPC_TryDecode.
-
if (!IsFail) {
uint32_t NumToSkip = emitNumToSkip(I, OS);
- OS << "// Opcode: " << NumberedEncodings[EncodingID];
emitNumToSkipComment(NumToSkip, /*InComment=*/true);
- } else {
- OS << "// Opcode: " << NumberedEncodings[EncodingID];
}
OS << '\n';
break;
More information about the llvm-commits
mailing list