This is an archive of the discontinued LLVM Phabricator instance.

[mlir][ods] Add support for custom directive in attr/type formats
ClosedPublic

Authored by Mogball on Mar 3 2022, 3:02 PM.

Details

Summary

This patch adds support for custom directives in attribute and type formats. Custom directives dispatch calls to user-defined parser and printer functions.

For example, the assembly format "custom<Foo>($foo, ref($bar))" expects a function with the signature

LogicalResult parseFoo(AsmParser &parser, FailureOr<FooT> &foo, BarT bar);
void printFoo(AsmPrinter &printer, FooT foo, BarT bar);

Diff Detail

Event Timeline

Mogball created this revision.Mar 3 2022, 3:02 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 3 2022, 3:02 PM
Mogball requested review of this revision.Mar 3 2022, 3:02 PM

Thanks Jeff! Great work as always.

mlir/docs/Tutorials/DefiningAttributesAndTypes.md
669

Can you add an example for say, a StringRef? It would be nice to have more complex/non-primitive test cases. StringRef as before is a good one, and so would something that is "expensive" to copy/non-trivially copyable/etc.

mlir/tools/mlir-tblgen/AttrOrTypeFormatGen.cpp
803–807
993–1000
1045

unfinished sentence: Collect

mlir/tools/mlir-tblgen/FormatGen.h
341

? To avoid saying reference twice.

Mogball marked 5 inline comments as done.Mar 7 2022, 1:17 PM
Mogball updated this revision to Diff 413613.Mar 7 2022, 1:21 PM

Review comments. And added a test case with StringRefParameter

rriddle requested changes to this revision.Mar 10 2022, 12:39 PM
rriddle added inline comments.
mlir/docs/Tutorials/DefiningAttributesAndTypes.md
688

Missing a & here?

mlir/test/lib/Dialect/Test/TestTypes.cpp
227

nit: Drop trivial braces here.

239

nit: Spell out auto here.

mlir/tools/mlir-tblgen/AttrOrTypeFormatGen.cpp
1118

Missing test coverage for all of these new error messages?

This revision now requires changes to proceed.Mar 10 2022, 12:39 PM
Mogball updated this revision to Diff 414493.Mar 10 2022, 2:04 PM
Mogball marked 4 inline comments as done.

Review comments

rriddle accepted this revision.Mar 11 2022, 1:14 AM
rriddle added inline comments.
mlir/tools/mlir-tblgen/AttrOrTypeFormatGen.cpp
1068

Missing coverage for this?

This revision is now accepted and ready to land.Mar 11 2022, 1:14 AM
Mogball updated this revision to Diff 415334.Mar 15 2022, 12:14 AM
Mogball marked an inline comment as done.

add missing test coverage

This revision was landed with ongoing or failed builds.Mar 15 2022, 12:15 AM
This revision was automatically updated to reflect the committed changes.