[Tablegen] How to specify type of register mask argument

Hi

I am working on the CHERI fork of LLVM, in order to implement a new calling convention.
As a part of this I need to emit 4 consecutive register clearing instructions, looking like this:

cclear 0, <mask>
cclear 1, <mask>
cclear 2, <mask>
cclear 3, <mask> 

The <mask> represents an 8 bit immediate bitmask.

To produce these instructions, I defined a new target specific SelectionDAG node CLEAR_REGS.
This node then gets pattern matched to a pseudo instruction PseudoCClear. I defined the translation in tablegen like this:

def SDT_RISCVClearRegs : SDTypeProfile<0, 0, []>;
def riscv_clear_regs : SDNode<"RISCVISD::CLEAR_REGS", SDT_RISCVClearRegs, [SDNPHasChain, SDNPOptInGlue, SDNPOutGlue]>;

let Predicates = [HasCheri, IsCapMode], hasSideEffects = 1 in
def PseudoCClear : Pseudo<(outs), (ins $mask), [(riscv_clear_regs $mask)]>;

I am having trouble assigning the correct type to the $mask argument of the pseudo instruction.
Without annotating a type the compiler complains about an illegal operand:

RISCVInstrInfoXCheri.td:1125:1: error: Illegal operand for the 'PseudoCClear' instruction!
def PseudoCClear : Pseudo<(outs), (ins $mask), [(riscv_clear_regs $mask)]>;
^

Can anyone help me figure out how to type $mask?
General feedback on my approach is also welcome.

Thanks,

Elias

Well it’s a uimm8 so you probably want to use a uimm8 type? Also your SDT_RISCVClearRegs is defined to have no operands.

You should probably also talk to us (Department of Computer Science and Technology: CHERI Mailing Lists / Department of Computer Science and Technology: CHERI-CPU Slack) if you’re working on CHERI LLVM.

I forgot to mention the PseudoCClear instruction gets expanded into the four CClear instructions in RISCVExpandPseudoInsts.cpp. It is there that the four uimm8 type operands get calculated.

My goal is to pass a register mask operand down like is done in the call instruction (an array of bitmasks). This is to give me more flexibility in how I calculate the uimm8 operands.

Thanks for referring me to the Slack, I have joined!