This is an archive of the discontinued LLVM Phabricator instance.

[mlir][ods] Add ArrayOfAttr for creating custom array attributes
ClosedPublic

Authored by Mogball on Sep 1 2022, 10:40 AM.

Details

Summary

ArrayOfAttr can be used to easily create an attribute that just
contains an array of something. The elements can be other attributes,
in which case the custom parsers and printers are invoked directly for
nice syntax, or any C++ type that supports parsing and printing, either
though custom printer and parser methods or FieldParser.

An array of integers:

def ArrayOfInts : ArrayOfAttr<Test_Dialect, "ArrayOfInts", "array_of_ints",
                              "int32_t">;

When embedded in an op's assembly format, it will look like

foo.ints value = [1, 2, 3]

An array of enums, when embedded in an op's assembly format, will look
like:

foo.enums value = [first, second, last]

Diff Detail

Event Timeline

Mogball created this revision.Sep 1 2022, 10:40 AM
Mogball requested review of this revision.Sep 1 2022, 10:40 AM
Mogball added a comment.EditedSep 1 2022, 10:49 AM

@mehdi_amini The generic syntax is "OK" (#foo<ints[1, 2, 3]>) but in theory you could instantiate this class multiple times to get bare integer arrays with no extra stuff

mehdi_amini accepted this revision.Sep 1 2022, 1:32 PM

@mehdi_amini The generic syntax is "OK" (#foo<ints[1, 2, 3]>) but in theory you could instantiate this class multiple times to get bare integer arrays with no extra stuff

I don't quite get what you mean?

This revision is now accepted and ready to land.Sep 1 2022, 1:32 PM

(Tangential to the overall patch, which is useful for many things esp enum array attrs). What I'm saying is that as long as you don't care about the generic syntax of the attribute very much, this is a viable alternative to the DenseArrayAttr subclasses.