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

Rahul Joshi via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 21 09:28:59 PDT 2025


jurahul wrote:

Ok, I am seeing some success with a variation of the idea I had before and implementation wise it seems much simpler than this PR. Basically, we add C++ code to "cull" cases in the generated `decodeToMCinst` based on the bitwidth. So, say if a particular decoder is used only for 32-bit insts, we modify the generated case to use:

```
case 300:
   if constexpr (InsnBitWidth != 32)
        llvm_unreachable()
```

So if the decoder is instantiated multiple times with different `InsnType` (root cause of this issue), specific instantiations will have this code deleted without having to actually generate different versions of the code. So this is essentially template instantiation time culling of decoders that are not active/relevant of the current bitwidth. Some data is as follows:

```
                        Trunk              DecoderCulling off       Decoder Culling ON         %reduction/increase
AMDGPU .text            611351                  820791					276887					55% decrease
AMDGPU .rodata          373928                  380744					365592					3% decrease
 
RISCV .text             47279                    98023					49091					3% increase
RISCV .rodata           35850                    38618					37306					4% increase
```

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


More information about the llvm-commits mailing list