[TableGen] Add support for variable length instruction in decoder generator
authorSheng <ox59616e@gmail.com>
Mon, 2 May 2022 19:26:55 +0000 (03:26 +0800)
committerSheng <ox59616e@gmail.com>
Mon, 2 May 2022 19:37:13 +0000 (03:37 +0800)
commit28e850a8da51336bb85343e7c106953b5dbe5b15
treed46734d095d655f3fa030d30bdc2d172bdd29530
parent522d90528e5a49393b7293204e20b311e789a913
[TableGen] Add support for variable length instruction in decoder generator

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.

Reviewed By: myhsu

Differential Revision: https://reviews.llvm.org/D120958
llvm/test/TableGen/VarLenDecoder.td [new file with mode: 0644]
llvm/utils/TableGen/FixedLenDecoderEmitter.cpp
llvm/utils/TableGen/VarLenCodeEmitterGen.cpp
llvm/utils/TableGen/VarLenCodeEmitterGen.h