This is an archive of the discontinued LLVM Phabricator instance.

[mlir][IR] Use tablegen for the BuiltinDialect and operations
ClosedPublic

Authored by rriddle on Nov 16 2020, 2:59 PM.

Details

Summary

This has been a long standing TODO, and cleans up a bit of IR/. This will also make it easier to move FuncOp out of IR/ at some point in the future. For now, Module.h and Function.h just forward BuiltinDialect.h. These files will be removed in a followup.

Diff Detail

Event Timeline

rriddle created this revision.Nov 16 2020, 2:59 PM
rriddle requested review of this revision.Nov 16 2020, 2:59 PM

I was funnily looking at this this morning, so yay :-) (just scanned but didn't review yet, just wanted to remark as timing is perfect :-))

This revision is now accepted and ready to land.Nov 16 2020, 4:05 PM
jpienaar accepted this revision.Nov 16 2020, 8:52 PM

Nice, only small nits.

mlir/include/mlir/IR/BuiltinOps.td
150

OOC what parts doesn't work with the ASM syntax here?

221

"The summary should be short and concise. It should be a one-liner without trailing punctuation."
https://mlir.llvm.org/docs/OpDefinitions/#operation-documentation

(of course we have an example in that file that violates this sigh)

mlir/lib/TableGen/OpClass.cpp
308

Why was this one needed?

rriddle updated this revision to Diff 305678.Nov 17 2020, 12:37 AM
rriddle marked 3 inline comments as done.

Resolve comments

rriddle added inline comments.Nov 17 2020, 12:43 AM
mlir/include/mlir/IR/BuiltinOps.td
150

The declarative syntax won't be able to do all of the crazy signature handling(e.g. argument/result attributes, argument printing, etc.) that is necessary, so a majority of it would need to be written using C++ anyways. We've already factored all of that into a common place so the necessary work here is trivial.

mlir/lib/TableGen/OpClass.cpp
308

It's required to be able to call the base Op::print methods, i.e. the ones that actually print the operation and not the ones used to define the declarative syntax. If we don't inherit them, they get hidden given that Op classes declare a new print method. tldr; this lets you do:

FuncOp foo = ...;
foo.print(llvm::errs());
This revision was landed with ongoing or failed builds.Nov 17 2020, 1:03 AM
This revision was automatically updated to reflect the committed changes.

I think the builtin dialect isn't documented anywhere:
https://mlir.llvm.org/docs/Dialects/
(Crazy question: do we really need to even call it a dialect? Can't it just be BuiltinOps.h?)

mlir/include/mlir/IR/BuiltinOps.td
199

Typo.

mlir/lib/IR/BuiltinDialect.cpp
45–46

I think this comment should go on the top (or be replicated) as the file comment, which is missing: here and even on BuiltinDialect.h. I think the purpose of this dialect and why something is in this dialect isn't spelt out anywhere but here.

rriddle marked 2 inline comments as done.Nov 19 2020, 11:15 AM

I think the builtin dialect isn't documented anywhere:
https://mlir.llvm.org/docs/Dialects/
(Crazy question: do we really need to even call it a dialect? Can't it just be BuiltinOps.h?)

Thanks Uday! Addressed comments in 65fcddff24d68e2b75a5fa820b6664b6ea78b1de. Moved the ops to BuiltinOps.h, but I kept BuiltinDialect because I think it's important that it is a publicly visible thing. Right now there are places that kind of just assume that an empty dialect namespace means the builtin dialect, which is kind of weird.

mlir/lib/IR/MLIRContext.cpp