PSA: Dialects now require a generated `MyOpsDialect.cpp.inc` file to be included

If you do not have out-of-tree dialects or you do not use Tablegen to define your Dialect class, you can stop reading.

Historically, tablegen dialect definitions only produced a MyOpsDialect.h.inc header file. With ⚙ D105070 [mlir] Generare .cpp.inc files for dialects., it is now required to include a new, generated MyOpsDialect.cpp.inc file in your dialect’s CPP file.

Since there have been several vintages of how to define dialects, out of tree projects are likely not completely consistent. If, upon integrating the above revision, you start to get errors about vtable/key methods being undefined at link time for your dialect classes, you will need to take action.

MyOps.cpp changes

Typically, your lib/Dialect/MyDialect/IR/MyOps.cpp file will need to be edited to add the additional include file. Example:

#include "mlir/Dialect/MyOps/IR/MyOpsDialect.cpp.inc"

For dialects defined to modern standards, this is the only change needed. It should go at the top of the file after any normal includes.

CMake changes required

Typically, your include/project/Dialect/IR/CMakeLists.txt file will generate your dialect via a call like: add_mlir_dialect(AffineOps affine). If this is the case, no CMake changes are needed.

Some older dialects do not use the above macro and/or have custom machinery to generate their tablegen assets. Here is an example:

mlir_tablegen(OpsDialect.h.inc -gen-dialect-decls)
mlir_tablegen(OpsDialect.cpp.inc -gen-dialect-defs)

In this case, prior to this revision, you will only have the first line and will need to add the second line equivalent manually.

Thanks. Feel free to PM with questions, but this should be a mechanical change for downstreams. Hopefully this post serves to eliminate some time wondering what the change should be. I considered making this backwards compatible, but as it only took me 5-10 minutes to churn through changes for dozens of dialects, I considered it a reasonable thing to impose in one step.

I will be landing this shortly.

1 Like

Thank you for adding this Stella! This will help clean many things up