This is an archive of the discontinued LLVM Phabricator instance.

[ODS/AsmParser] Don't pass MLIRContext with DialectAsmParser.
ClosedPublic

Authored by lattner on Sep 29 2021, 5:47 PM.

Details

Summary

The former is redundant because the later carries it as part of
its builder. Add a getContext() helper method to DialectAsmParser
to make this more convenient, and stop passing the context around
explicitly. This simplifies ODS generated parser hooks for attrs
and types.

This resolves PR51985

Diff Detail

Event Timeline

lattner created this revision.Sep 29 2021, 5:47 PM
Herald added a reviewer: rriddle. · View Herald Transcript
Herald added a reviewer: aartbik. · View Herald Transcript
Herald added a reviewer: ftynse. · View Herald Transcript
Herald added a reviewer: aartbik. · View Herald Transcript
Herald added a project: Restricted Project. · View Herald Transcript
lattner requested review of this revision.Sep 29 2021, 5:47 PM
rriddle accepted this revision.Sep 29 2021, 6:10 PM
rriddle added inline comments.
mlir/include/mlir/IR/OpImplementation.h
20–21

Can we remove this?

572–587

Can we add a get version of these and use it in the places we are generally using getContext in this patch? Kind of like what we have on Builder (https://github.com/llvm/llvm-project/blob/27451a05ed4d13294182ec7e999a9d4f90bc0d12/mlir/include/mlir/IR/Builders.h#L85)

This revision is now accepted and ready to land.Sep 29 2021, 6:10 PM
lattner updated this revision to Diff 376096.Sep 29 2021, 9:33 PM

Remove commented out #include I inadvertantly left in.

lattner added inline comments.Sep 29 2021, 9:35 PM
mlir/include/mlir/IR/OpImplementation.h
20–21

Yeah of course, good catch thanks.

572–587

Perhaps, but you're merely talking to the boilerplate garbage man, not to the design guy here. Why does AsmParser have these methods in the first place?

How would such a think work with get methods that don't take a context parameter? In any case, such a thing would be a different patch. Can you file a bugzilla and cc me on it if you think this is a good thing, I can investigate.

In fact, I wasn't aware of, and I've never seen code that uses that builder.getType<Thing>(... method. Most of the cases touched in this patch would be better off using parser.getBuilder().getIntType(..) or whatever, rather than passing context's around. I don't know that the getType<> thing is a very general pattern.

rriddle added inline comments.Sep 29 2021, 9:42 PM
mlir/include/mlir/IR/OpImplementation.h
572–587

The getChecked ones are there to better facilitate verifying attributes/types during parsing (the verification errors get emitted via the parser, which is the lambda being passed in).

How would such a think work with get methods that don't take a context parameter?

It wouldn't be used for such get methods. The only intention of it would be (much like what Builder::getType is/was intended for) to remove the need to explicitly pass in the context for the get methods that do (the ones that don't should keep using the MyType::get methods like normal.

This revision was landed with ongoing or failed builds.Sep 29 2021, 9:43 PM
This revision was automatically updated to reflect the committed changes.

sorry I had to revert, this broke the bot: https://lab.llvm.org/buildbot/#/builders/61/builds/15454

Likely due to -DDBUILD_SHARED_LIBS=ON being stricter on dependencies (I haven't look with more details yet)

It looks like we just crossed each other, I committed a change, which will pretty surely be broken now. Could you help get both applied again? I'm not sure how to do the git-fu.

OK, I just cherry-picked your original commit on top of main and pushed it again as-is: git cherry-pick 4b32f8bac40dcd1535bfe95757c3de0911bf6d1a

Thank you! You need to delete the implementation of AsmParser::getContext() in Parser.cpp. I'll take care of it.

Thank you Mehdi!