[llvm-branch-commits] [llvm] [TableGen][AsmMatcher] Support generated register coercion logic (PR #241022)

Sam Elliott via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Wed Nov 11 12:54:54 PST 2026


lenary wrote:

> Add a new `CoerceFromRegClass` field on `RegisterClass` so TableGen can generate the `MCRegister` conversion in `convertToMCInst` automatically. So now we can run this before we call `validateTargetOperandClass` and can avoid mutating partially parsed operands.

We agree we don't want `validateTargetOperandClass` to modify the `MCParsedAsmOperand &AsmOp`, because it's really a predicate that's evaluated on each operand in turn.

I think I'm confused by the sequencing your message suggests, but I don't know what you mean by "run this before", especially when reading the implementation.

This seems to:
- choose different Match Class Kinds, but not via the coercion information - I don't understand why the `yinst YGPR, GPR` is looking for `[AnyGPR, GPR]` rather than `[GPR, GPR]` when matching.
- skip the `RenderMethod` when there's a coercion (instead hard-coding how the operand is coerced and added)

I think how I envisioned this working was:
- `validateTargetOperandClass(R, MCK_GPRPair)` would accept `R == RISCV::X0` (but not `R == RISCV::X1`). The spelling-based reg/reg mapping generated here is probably a long way to helping.
- Then we would implement a lot of `RenderMethod = 'addGPRPairSpelledWithGPR'` and in that renderer call the mapper to do the modification, so if we need to do more complex work when adding a register to instruction, we can.

I accept that what I envisioned was not going to be as tablegen-driven as this solution is, but I think I don't fully understand the sequencing.

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


More information about the llvm-branch-commits mailing list