diff --git a/mlir/docs/DefiningDialects/AttributesAndTypes.md b/mlir/docs/DefiningDialects/AttributesAndTypes.md --- a/mlir/docs/DefiningDialects/AttributesAndTypes.md +++ b/mlir/docs/DefiningDialects/AttributesAndTypes.md @@ -48,6 +48,10 @@ examples for both. If necessary, a section will explicitly call out any distinct differences. +One difference is that generating C++ classes from declarative TableGen +definitions will require adding additional targets to your `CMakeLists.txt`. +This is not necessary for custom types. The details are outlined further below. + ### Adding a new Attribute or Type definition As described above, C++ Attribute and Type objects in MLIR are value-typed and @@ -168,6 +172,26 @@ added above, we would get C++ classes named `IntegerType` and `IntegerAttr` respectively. This can be explicitly overridden via the `cppClassName` field. +### CMake Targets + +If you added your dialect using `add_mlir_dialect()` in your `CMakeLists.txt`, +the above mentioned classes will automatically get generated for custom +_types_. They will be output in a file named `Types.h.inc`. + +To also generate the classes for custom _attributes_, you will need to add +two additional TableGen targets to your `CMakeLists.txt`: + +```cmake +mlir_tablegen(AttrDefs.h.inc -gen-attrdef-decls + -attrdefs-dialect=) +mlir_tablegen(AttrDefs.cpp.inc -gen-attrdef-defs + -attrdefs-dialect=) +add_public_tablegen_target(AttrDefsIncGen) +``` + +The generated `AttrDefs.h.inc` will need to be included whereever +you are referencing the custom attribute types. + ### Documentation The `summary` and `description` fields allow for providing user documentation