This is an archive of the discontinued LLVM Phabricator instance.

[mlir] Refactor how parser/printers are specified for AttrDef/TypeDef
ClosedPublic

Authored by rriddle on Mar 11 2022, 7:09 PM.

Details

Summary

There is currently an awkwardly complex set of rules for how a
parser/printer is generated for AttrDef/TypeDef. It can change depending on if a
mnemonic was specified, if there are parameters, if using the assemblyFormat, if
individual parser/printer code blocks were specified, etc. This commit refactors
this to make what the attribute/type wants more explicit, and to better align
with how formats are specified for operations.

Firstly, the parser/printer code blocks are removed in favor of a
hasCustomAssemblyFormat bit field. This aligns with the operation format
specification (and is nice to remove code blocks from ODS).

This commit also adds a requirement to explicitly set assemblyFormat or
hasCustomAssemblyFormat when the mnemonic is set and the attr/type
has no parameters. This removes the weird implicit matrix of behavior,
and also encourages the author to make a conscious choice of either C++
or declarative format instead of implicitly opting them into the C++
format (we should be pushing towards declarative when possible).

Depends on D120011

Diff Detail

Event Timeline

rriddle created this revision.Mar 11 2022, 7:09 PM
Herald added a reviewer: ftynse. · View Herald Transcript
Herald added a reviewer: aartbik. · View Herald Transcript
Herald added projects: Restricted Project, Restricted Project. · View Herald Transcript
rriddle requested review of this revision.Mar 11 2022, 7:09 PM
mehdi_amini accepted this revision.Mar 14 2022, 8:29 PM
mehdi_amini added inline comments.
mlir/test/lib/Dialect/Test/TestTypeDefs.td
123

You could have used the "extraClassDefinitions" to provide it as an example of inline definition, but it may not have been the intent here anyway

This revision is now accepted and ready to land.Mar 14 2022, 8:29 PM
rriddle marked an inline comment as done.Mar 15 2022, 12:50 AM
rriddle added inline comments.
mlir/test/lib/Dialect/Test/TestTypeDefs.td
123

Yeah, I've been strongly leaning towards just removing code out of tablegen unless we really need it.

This revision was automatically updated to reflect the committed changes.
rriddle marked an inline comment as done.