This is an archive of the discontinued LLVM Phabricator instance.

[mlir][ods] Allow specifying return types of builders
ClosedPublic

Authored by Mogball on Jul 14 2022, 11:38 AM.

Details

Summary

This patch allows custom attribute and type builders to return
something other than the C++ type of the attribute or type.

This is useful for attributes or types that may perform extra work during
construction (e.g. canonicalization) that could result in a different
kind of attribute or type being returned.

Diff Detail

Event Timeline

Mogball created this revision.Jul 14 2022, 11:38 AM
Mogball requested review of this revision.Jul 14 2022, 11:38 AM

Could you also add rationale to the description? (Especially as one now has a attribute with a C++ type that you'd want to build using a different C++ type, makes me wonder, why not just define the attribute that way to begin with)

Mogball edited the summary of this revision. (Show Details)Jul 14 2022, 11:44 AM

Added a justification.

lattner accepted this revision.Jul 14 2022, 12:39 PM
lattner added a subscriber: darthscsi.

Nice, this is super useful for attributes whose get() methods can fold them into simpler operators, like these in CIRCT:
https://github.com/llvm/circt/blob/main/include/circt/Dialect/HW/HWAttributes.td#L258

@darthscsi fyi

This revision is now accepted and ready to land.Jul 14 2022, 12:39 PM
rriddle requested changes to this revision.Jul 14 2022, 12:43 PM

This is missing documentation in AttributesAndTypes.md

mlir/lib/TableGen/AttrOrTypeDef.cpp
87

This looks unrelated, why was this dropped? AFAICT this commit doesn't address the TODO here.

This revision now requires changes to proceed.Jul 14 2022, 12:43 PM
Mogball updated this revision to Diff 445155.Jul 15 2022, 3:57 PM
Mogball marked an inline comment as done.

Update docs and remove extraneous diff

rriddle accepted this revision.Jul 15 2022, 4:51 PM

LG, nice work!

This revision is now accepted and ready to land.Jul 15 2022, 4:51 PM
This revision was landed with ongoing or failed builds.Jul 15 2022, 6:00 PM
This revision was automatically updated to reflect the committed changes.