[PATCH] D138323: [TableGen] RegisterInfo backend - Add abstraction layer between code generation logic and syntax output

Nicolai Hähnle via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 23 01:25:44 PST 2023


nhaehnle added a comment.

>> Ideally, you'd just use CodeGenTarget from a new printer, and potentially augment that class with additional features you may need.
>
> I agree that this is the way to go for backends which emit mostly unprocessed information from the `CodeGenTarget`.
> But it is complicated for backends like the `DecoderEmitter`.
> This backend generates a state machine for decoding instructions and emits the C++ version of it. But the whole state machine generation logic is mixed together with the code printing.
> So it is not possible to build a printer solely on top of the state-machine generation logic.
>
> And maintaining an altered copy of it is maintenance heavy.
>
> Would you say that in such a case this abstraction would be of use? Or should the state-machine generation be move to the `CodeGenTarget` in you opinion (as target-independent code generation algorithm I guess)?
>
> My underling problem is that the `Emitter` backends don't just emit syntax. But quite often process (sometimes heavily) the information given by `CodeGenTarget` and the `Records` but don't make the result accessible.

Yes, that's indeed an issue for what you're trying to do. IMHO it is also an issue for the maintainability of these backends as they are today. So I'd say we should try to separate the state-machine generation code from the printing code. It could be moved to `CodeGenTarget`, though I think it'd be better to keep things slightly more modular and instead split up the current `DecoderEmitter` into parts:

- A `Decoder` class contains all the state-machine description. Think of it as an "intermediate representation for a decoder/disassembler": it contains the data describing the decoder, but essentially no logic.
- A separate `createDecoder` function creates a `Decoder` given a `CodeGenTarget`
- The `emitDecoder` function writes out the generated C++ for a given `Decoder` object

Does that make sense to you?


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D138323/new/

https://reviews.llvm.org/D138323



More information about the llvm-commits mailing list