To support variable length instructions, I think of them as fixed length instructions with the "maximum length". For example, if there're three instructions with 2, 6 and 9 bytes, we can fit them into the algorithm by treating them all as 9 bytes.
Also, since we can't know the length of the instruction in advance, there is a function object with type void(APInt &, uint64_t) added in the parameter list of decodeInstruction and fieldFromInstruction. We can use this to supply the additional bits the decoder needs after we know the opcode of the instruction.
Finally, InstrLenTable is added to let the decoder know the length of the instructions.
See D120960 for its usage.
Is 244 the index into the instruction table where FOO16 is expected to reside?
This check on OPC_Decode seems extremely brittle. If there are any additions either in the upstream Target.td or in a downstream Target.td, won't this check and the one on line 52 will break?