Learning how to use TableGen for LLVM backends
LLVM uses the record-oriented language TableGen to describe information used in several compiler stages. For example, in Chapter 4, The Frontend, we briefly discussed how TableGen files (with the .td
extension) are used to describe different diagnostics of the frontend. TableGen was originally written by the LLVM team to help programmers write LLVM backends. Even though the code generator libraries' design emphasizes a clean separation of concerns between target characteristics, for example, using a different class to reflect register information and another for instructions, the backend programmer eventually ends up writing code that reflects the same machine aspect in several different files. The problem with this approach is that, despite the extra effort to write the backend code, it introduces information redundancy in the code that must be manually synchronized.
For example, if you want to change how the backend deals with a register,...