This is an archive of the discontinued LLVM Phabricator instance.

[mlir][tblgen] Refact mlir-tblgen main into its own library
ClosedPublic

Authored by zero9178 on Aug 3 2022, 1:30 PM.

Details

Summary

This has previously been done for mlir-opt and mlir-reduce and roughly the same approach has been done here.

The use case for having a separate library is that it is easier for downstream to make custom TableGen backends/executable that work on top of the utilities that are defined in mlir/TableGen.
The customization point here is the same one as for any upstream TableGen backends: One can add a new generator by simply creating a global instance of mlir::GenRegistration.

Diff Detail

Event Timeline

zero9178 created this revision.Aug 3 2022, 1:30 PM
zero9178 requested review of this revision.Aug 3 2022, 1:30 PM

LGTM, but please wait for Jacques or River to also have a look.

Thanks!

jpienaar accepted this revision.Aug 3 2022, 2:21 PM

Thanks, this make the mlir-hs usage also nicer (was in my TODO list and then slipped off). This looks good refactoring step.

This revision is now accepted and ready to land.Aug 3 2022, 2:21 PM
Mogball accepted this revision.Aug 3 2022, 2:23 PM

This is a superset of your other diff. You can put this one on top and land that one first.

This is a superset of your other diff. You can put this one on top and land that one first.

I don't like the other diff in itself, and I don't see a strong reason to connect them or land this change as two commits: do you see a good reason to?

rriddle accepted this revision.Aug 3 2022, 3:08 PM

Looks like a fine move.

mlir/lib/TableGen/GenInfo.cpp
12

Can we align the name of the cpp and the header?

20

Is the mlir:: necessary here?

mlir/lib/Tools/mlir-tblgen/MlirTblgenMain.cpp
117–119

Is the static necessary here?

131

Can you use cl::location on the generator option instead of this?

zero9178 marked 3 inline comments as done.Aug 3 2022, 3:24 PM
zero9178 added inline comments.
mlir/lib/TableGen/GenInfo.cpp
12

I am assuming you are referring to the fact that this file is called GenInfo.cpp and not GenNameParser.cpp?

This is essentially just because both mlir::GenRegistration and mlir::GenNameParser require access to the generatorRegistry here. We'd otherwise have to make this variable global and I did not want to unnecessarily deviate from the original implementation.

I opted for GenInfo.cpp since I felt like the implementation of mlir::GenRegistration was of more significance (which is declared in GenInfo.h). I don't feel too strongly about this so I can change it if you prefer.

zero9178 updated this revision to Diff 449804.Aug 3 2022, 3:25 PM

Address review comments

The other diff makes sense because it's fixing the location of the definition of some functions. I wasn't correct that the functions were declared in a header belonging to MLIRTableGen lib but was defined in the binary!

So if the purpose is to address that problem, the diff makes sense to me