[llvm] [TableGen][DecoderEmitter] Add option to emit type-specialized `decodeToMCInst` (PR #146593)
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 3 11:44:57 PDT 2025
topperc 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)
I meant make decodeMCInst16, decodeMCInst32, and decodeMCInst48 for RISC-V using just the bitwidth from the instructions. And have them called by decodeInstruction16, decodeInstruction32, and decodeInstruction48. Update RISCVDisassembler.cpp to call decodeInstruction16/32/48 instead of decodeInstruction.
That decreases the size of the switch in each of the decodeMCInst functions. But the cost is the duplication of of decodeInstruction for targets that use the same CPP type for all instructions. On targets the use different cpp types, decodeInstruction was already duplicated by the templating.
https://github.com/llvm/llvm-project/pull/146593
More information about the llvm-commits
mailing list