This is an archive of the discontinued LLVM Phabricator instance.

[mlir][tblgen] Add support for extraClassDefinition in AttrDef
ClosedPublic

Authored by bhatuzdaname on Jul 12 2022, 9:36 AM.

Details

Summary

For AttrDef declarations, place specified code in extraClassDefinition into the generated *.cpp.inc file.

Diff Detail

Event Timeline

bhatuzdaname created this revision.Jul 12 2022, 9:36 AM
bhatuzdaname requested review of this revision.Jul 12 2022, 9:36 AM
rriddle requested changes to this revision.Jul 12 2022, 1:09 PM

Please add a test in attrdefs.td and add documentation to docs/AttributesAndTypes.md.

mlir/include/mlir/IR/AttrTypeBase.td
228

Use class instead of attribute, this tablegen class is for both attributes and types.

This revision now requires changes to proceed.Jul 12 2022, 1:09 PM

addressed comment, added test, clang-formatted files.

bhatuzdaname marked an inline comment as done.Jul 13 2022, 8:49 AM
rriddle accepted this revision.Jul 13 2022, 10:24 AM

LG, thanks!

mlir/docs/AttributesAndTypes.md
1064

?

mlir/include/mlir/TableGen/AttrOrTypeDef.h
118

This looks unrelated, and I think this is also causing the debian builder to fail (it's failing on clang format)

This revision is now accepted and ready to land.Jul 13 2022, 10:24 AM

Fix clang-format issue, improve documentation

bhatuzdaname marked 2 inline comments as done.Jul 13 2022, 10:35 AM

Thanks for the review! Could you commit it for me? I do not have commit access.

mlir/include/mlir/TableGen/AttrOrTypeDef.h
118

Weird. Might've come from the clang-format on my system. Reverted it.

Mogball requested changes to this revision.Jul 14 2022, 9:06 AM
Mogball added inline comments.
mlir/tools/mlir-tblgen/AttrOrTypeDefGen.cpp
160–161

This doesn't need to be declared as a class field.

233–236

Can you add the extra definitions here instead?

This revision now requires changes to proceed.Jul 14 2022, 9:06 AM
bhatuzdaname marked an inline comment as done.Jul 14 2022, 9:23 AM
bhatuzdaname added inline comments.
mlir/tools/mlir-tblgen/AttrOrTypeDefGen.cpp
233–236

I had initially done that but ran into some lifetime issue with the underlying string for the definition which resulted in printing of a lot of garbage in the generated .inc file. So that's why I moved it into the class definition. I'll look into this again, maybe I missed something then

Mogball added inline comments.Jul 15 2022, 9:44 AM
mlir/tools/mlir-tblgen/AttrOrTypeDefGen.cpp
233–236

The field is a StringRef so you can change that in ExtraClassDeclaration.

Remove extraclass string field, add decl+def in a single go.

bhatuzdaname marked an inline comment as done.Jul 18 2022, 12:26 AM
bhatuzdaname added inline comments.
mlir/tools/mlir-tblgen/AttrOrTypeDefGen.cpp
233–236

done, thank you!

Mogball accepted this revision.Jul 18 2022, 12:35 AM

Two minor comments. Otherwise LG. Thanks for making this!

mlir/include/mlir/TableGen/Class.h
557

extraClassDeclaration doesn't need to be std::string since it has no format requirements and can reference the TableGen string safely

mlir/tools/mlir-tblgen/AttrOrTypeDefGen.cpp
235

The string isn't needed afterwards and can be moved into the object

This revision is now accepted and ready to land.Jul 18 2022, 12:35 AM

Addressed additional comments. Thanks for the review! Could you please commit it for me?

This revision was landed with ongoing or failed builds.Jul 19 2022, 9:13 AM
This revision was automatically updated to reflect the committed changes.