[llvm] [TableGen][DecoderEmitter] Add option to emit type-specialized `decodeToMCInst` (PR #146593)

Rahul Joshi via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 3 10:15:13 PDT 2025


jurahul wrote:

> > What if we duplicated decodeMCInst and decodeInstruction based on bitwidth but left them as template functions. That would remove the unused switch cases in each decodeMCInst. Unfortunately, we'd have to update targets to call the correct decodeInstruction with the bitwidth in the name.
> 
> I don't understand this. Can you elaborate? Do you mean something like:
> 
> ```
> template <typename InsnType>
> std::enable_if<sizeof(InsnType) == 32); /// use the proper syntax here
> decodeToMCInst(...) {
>   // just 32-bit decoder cases
> }
> 
> template <typename InsnType>
> std::enable_if<sizeof(InsnType) == 64); /// use the proper syntax here
> decodeToMCInst(...) {
>   // just 64-bit decoder cases
> }
> ```
> 
> ? So based on the actual size of the template type used, its automatically routed to the appropriate variant? And then there is no change in any .td files? May be just a bool CL option to opt-in into this.
> 
> Or this could also be just a if constexpr ()... in the decodeInstruction function to route to the appropriate variant on non-templated decodeMCInst

Actually, this won't work because we know that the sizeoof(CPPType) may not always match the inst size (for example, using of uint64_t for 48 bit insts)

https://github.com/llvm/llvm-project/pull/146593


More information about the llvm-commits mailing list