Skip to content

Commit b81bfea

Browse files
[llvm][TableGen] Add a README to the main TableGen folder (#69943)
Though I doubt that many people will land here directly, I thought it odd that we didn't have one we can at least reference in response to questions. The intro I've copied from the programmer's reference and added a simple example. Then some links to resources and tools, which is the main reason to have this page.
1 parent 4baeed8 commit b81bfea

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

llvm/utils/TableGen/README.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# LLVM TableGen
2+
3+
The purpose of TableGen is to generate complex output files based on information
4+
from source files that are significantly easier to code than the output files would be, and also easier to maintain and modify over time.
5+
6+
The information is coded in a declarative style involving classes and records,
7+
which are then processed by TableGen.
8+
9+
```
10+
class Hello <string _msg> {
11+
string msg = !strconcat("Hello ", _msg);
12+
}
13+
14+
def HelloWorld: Hello<"world!"> {}
15+
```
16+
```
17+
------------- Classes -----------------
18+
class Hello<string Hello:_msg = ?> {
19+
string msg = !strconcat("Hello ", Hello:_msg);
20+
}
21+
------------- Defs -----------------
22+
def HelloWorld { // Hello
23+
string msg = "Hello world!";
24+
}
25+
```
26+
27+
The internalized records are passed on to various backends, which extract
28+
information from a subset of the records and generate one or more output files.
29+
30+
These output files are typically .inc files for C++, but may be any type of file
31+
that the backend developer needs.
32+
33+
Resources for learning the language:
34+
* [TableGen Overview](https://llvm.org/docs/TableGen/index.html)
35+
* [Programmer's reference guide](https://llvm.org/docs/TableGen/ProgRef.html)
36+
* [Tutorial](jupyter/tablegen_tutorial_part_1.ipynb)
37+
* [Lessons in TableGen](https://www.youtube.com/watch?v=45gmF77JFBY) (video),
38+
[slides](https://archive.fosdem.org/2019/schedule/event/llvm_tablegen/attachments/slides/3304/export/events/attachments/llvm_tablegen/slides/3304/tablegen.pdf)
39+
* [Improving Your TableGen Descriptions](https://www.youtube.com/watch?v=dIEVUlsiktQ)
40+
(video), [slides](https://llvm.org/devmtg/2019-10/slides/Absar-ImprovingYourTableGenDescription.pdf)
41+
42+
Writing TableGen backends:
43+
* [TableGen Backend Developer's Guide](https://llvm.org/docs/TableGen/BackGuide.html)
44+
* [How to write a TableGen backend](https://www.youtube.com/watch?v=UP-LBRbvI_U)
45+
(video), [slides](https://llvm.org/devmtg/2021-11/slides/2021-how-to-write-a-tablegen-backend.pdf), also available as a
46+
[notebook](jupyter/sql_query_backend.ipynb).
47+
48+
TableGen in MLIR:
49+
* [Operation Definition Specification](https://mlir.llvm.org/docs/DefiningDialects/Operations/)
50+
* [Defining Dialect Attributes and Types](https://mlir.llvm.org/docs/DefiningDialects/AttributesAndTypes/)
51+
52+
Useful tools:
53+
* [TableGen Jupyter Kernel](jupyter/)
54+
* [TableGen LSP Language Server](https://mlir.llvm.org/docs/Tools/MLIRLSP/#tablegen-lsp-language-server--tblgen-lsp-server)
55+

0 commit comments

Comments
 (0)