This is an archive of the discontinued LLVM Phabricator instance.

[mlir][tblgen] Generate builders with inferred return types and unwrapped attributes
ClosedPublic

Authored by jfurtek on Apr 19 2022, 1:59 PM.

Details

Summary

This diff causes mlir-tblgen to generate code for an additional builder for an
operation argument with a return type that can be inferred *AND* an attribute in
the argument list can be "unwrapped." (Previously, the unwrapped build function
was only generated for builders with explicit return types in separate or
aggregate form.) As an example, this builder might be used by code that creates
operations that implement the SameOperandsAndResultType interface. A test case
was created.

Diff Detail

Event Timeline

jfurtek created this revision.Apr 19 2022, 1:59 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 19 2022, 1:59 PM
jfurtek requested review of this revision.Apr 19 2022, 1:59 PM

Adding @mehdi_amini and @rriddle to reviewers to either review or suggest a reviewer...

jpienaar accepted this revision.Apr 21 2022, 4:46 PM

Nice, thanks (I need to remove the hard coding on SameElement... there but that's not related here directly)

mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
1656

if any attribute ? (just to avoid a reading that all needs to be unwrappable)

1690

Is the lambda even needed? Seems like we could just have it inlined here with returns changed to continue and horizontal whitespace reduced. Alternatively I'd avoid the array and do

emit(AttrParamKind::WrappedAttr);
if (canGenerateUnwrappedBuilder(op)))

emit(AttrParamKind::UnwrappedValue);

to make it more locally obvious

This revision is now accepted and ready to land.Apr 21 2022, 4:46 PM
jfurtek updated this revision to Diff 424547.Apr 22 2022, 11:31 AM
  • Improve code flow and rebase
jfurtek marked 2 inline comments as done.Apr 22 2022, 11:36 AM
jfurtek added inline comments.
mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
1690

I was mimicking the code in genSeparateArgParamBuilder() - but that has a more elaborate emit() scenario. I agree that your suggestion is better - changed in updated commit.

jfurtek updated this revision to Diff 424987.Apr 25 2022, 11:39 AM
jfurtek marked an inline comment as done.
  • Rebase
This revision was landed with ongoing or failed builds.Apr 25 2022, 12:00 PM
This revision was automatically updated to reflect the committed changes.