# Tools for Learning LLVM TableGen

DevFeed: [Tools for Learning LLVM TableGen](<https://devfeed.tech/articles/tools-for-learning-llvm-tablegen-43098.md>)

Original publisher: [Read original article](<https://blog.llvm.org/posts/2023-12-07-tools-for-learning-llvm-tablegen/>)

Author: David Spickett

Published: 2023-12-07T00:00:00Z

Content type: tutorial

Language: en

Sources: [LLVM Project](<https://devfeed.tech/sources/the-llvm-project-blog.md>)

Topics: [Compiler](<https://devfeed.tech/topics/compiler.md>), [domain-specific language](<https://devfeed.tech/topics/domain-specific-language.md>), [LLVM](<https://devfeed.tech/topics/llvm.md>), [Code](<https://devfeed.tech/topics/code.md>), [Documentation](<https://devfeed.tech/topics/documentation.md>), [Repository](<https://devfeed.tech/topics/repository.md>), [toolchain](<https://devfeed.tech/topics/toolchain.md>), [cpu](<https://devfeed.tech/topics/cpu.md>), [Learning](<https://devfeed.tech/topics/learning.md>), [mlir](<https://devfeed.tech/topics/mlir.md>), [C++](<https://devfeed.tech/topics/c-plus-plus.md>), [Hackathon-Kit](<https://devfeed.tech/topics/hackathon-kit.md>)

Tags: [c](<https://devfeed.tech/tags/c.md>), [c-plus-plus](<https://devfeed.tech/tags/c-plus-plus.md>), [code-documentation](<https://devfeed.tech/tags/code-documentation.md>), [compiler](<https://devfeed.tech/tags/compiler.md>), [contributing](<https://devfeed.tech/tags/contributing.md>), [data](<https://devfeed.tech/tags/data.md>), [documentation](<https://devfeed.tech/tags/documentation.md>), [domain-specific-language](<https://devfeed.tech/tags/domain-specific-language.md>), [dsl](<https://devfeed.tech/tags/dsl.md>), [introduction](<https://devfeed.tech/tags/introduction.md>), [language](<https://devfeed.tech/tags/language.md>), [llvm](<https://devfeed.tech/tags/llvm.md>), [llvm-ir](<https://devfeed.tech/tags/llvm-ir.md>), [mlir](<https://devfeed.tech/tags/mlir.md>), [repository](<https://devfeed.tech/tags/repository.md>), [tablegen](<https://devfeed.tech/tags/tablegen.md>)

## AI overview

A tutorial introduces LLVM TableGen, a domain-specific language used to generate files such as C++ code, documentation, command-line options, and architecture instruction definitions. It explains TableGen's compiler, intermediate representation, and backends, including examples involving Arm's AArch64 registers and outputs such as C++ code, C headers, and reStructuredText documentation.

## Source excerpt

TableGenis a language used within the LLVM project for generating a variety of files,when manual maintenance would be very difficult. For example, it is used to define all of the instructions that can be used on aparticular architecture. The information is defined in TableGen and we canproduce many things based on that single source file. C++ code, documentation,command line options, and so on. TableGen has been in existence sincebeforethe first official release of LLVM, over 20 years ago. Today in the LLVM project repository there areover a thousand TableGen source files totalling over 500,000 lines of code.Making it the 5th most popular language in the repository. LanguagefilesblankcommentcodeC++2964295854218701015544445C/C++ Header118443168064998451486165C1053525990016035941011269Assembly106944780351222315820236TableGen13129411283616580289 (Counted fromthis commit,rest of table omitted) With projects such as MLIRembracing TableGen,it is only going to grow. So if you are contributing to LLVM, you will encounterit at some point. Which might be a problem as TableGen only exists within LLVM. Unlike a languagesuch as C++, TableGen does not have a large array of resources. So, as well as joining a new project, you also need to learn a newDomain Specific Language (DSL). You did not come to LLVM to learn a DSL, youprobably came here to write a compiler. I cannot say when this problem might be solved, but the situation is not asbleak as it appears. There have been big improvements in TableGen toolsrecently, which means you can put more of your energy into the goals thatbrought you to LLVM in the first place. A Brief Introduction to TableGen Imagine you wanted to represent the registers of an architecture. I am going touse Arm's AArch64 in particular here. You could describe them in TableGen as: $ cat register.tdclass Register<int _size, string _alias=""> { int size = _size; string alias = _alias;}// 64 bit general purpose registers are X<N>.def X0: Register<8> {}// Some h