3 ms·
TableGen has been the most annoying part of working with LLVM, it is unfortunate thy doubled down on it for MLIR. If you want to generate code, define a better
by fooker 3y ago
TableGen has been the most annoying part of working with LLVM, it is unfortunate thy doubled down on it for MLIR.
If you want to generate code, define a better language and write a good compiler.
TableGen tries to be similar to C++, but is different enough that it is annoying.
And god help you if something goes wrong, error messages are straight up misleading.
- UncleOxidant 3y ago> TableGen tries to be similar to C++, but is different enough that it is annoying. It seemed to me that TableGen was trying to be a pure functional language more like Haskell than C++.
- fooker 3y agotrying is the keyword here!
- j2kun 3y agoIt's not entirely doubled down on. There is work on IRDL, a domain-specific language for dialect definitions, and PDL, a language for pattern definitions. In theory, those could replace tablegen one day. I haven't looked into either too deeply, though.
- fooker 3y agoThese are research projects you don't want to touch for anything other than publishing papers until they are adopted by $BIGCO and has ~5 man years of engineering effort.
- j2kun 3y agoThey are upstreamed in LLVM and work today, though they are feature incomplete. From what I understand, the main reason you shouldn't use them is that development is stalled because the people who were working on them went to work at Modular.
- fooker 3y agoThey don't work today, give it a try. The core dialects are upstreamed so that people don't reinvent them, but all tools to utilize any of it aren't. Some of it isn't even open source. For example, nothing else in MLIR uses PDL right now.
- jcranmer 3y agoTableGen isn't trying to be similar to C++, it's trying to be a language that makes it easy to specify highly redundant data tables. Now, when you're writing an LLVM backend, these tables are immediately consumed by another tool that tries to write a very complex state machine based on these tables, and the formats of the tables that said tool expects is essentially undocumented and confusing, and the error messages tend to range from confusing to, well, straight up misleading. But technically that's not the fault of TableGen, that's the fault of that TableGen-based tool.
- fooker 3y agoI don't doubt the 'what', clearly it's needed. My point was about the 'how'. See the following example code from the manual and tell me it doesn't resemble C++ if you squint. class PersonName<string name> { assert ... string Name = name; } class Person<string name, int age> : PersonName<name> { assert ... int Age = age; } def Rec20 : Person<"Donald Knuth", 60> { ... }
- pjmlp 3y agoMuch better than other even more arcane tools, like DSLs based on C macros. It has been ages since I delved into GCC internals, think GCC vs egcs days, but if I am not mistaken it was either DSL based on C macros, or some variation of GIMPLE.