Tablegen: add custom field to Instruction description

Hi,

Is it possible to add a custom field to the Instructions description, so I can read it from a MCInstrDesc in C++ code.
For example, I have a lot of PUSH instructions with different . It would be great to add field size to its description, like this:

class MyInst<int sz, ...>  : Instruction {
    ...
    let size = sz;
}

And use it from code:

MI.getDesc().getSize();

Instead of this:

switch (MI.getOpcode) {
  case PUSH1: ...
  case PUSH2: ...
  ...
}

Thanks.

There is a uint64_t in the MCInstrDesc called TSFlags which stands for “target specific flags”. This field also exists on the Instruction class in tablegen. You can partition those 64 bits up however you want.

See the RVInst class in RISCVInstrFormats.td and the RISCVII enum in RISCVBaseInfo.h for examples.

1 Like

Got it! Thank you topperc