This is an archive of the discontinued LLVM Phabricator instance.

[AsmParser] Avoid instantiating LLVMContext if not needed. NFC
ClosedPublic

Authored by yrouban on Jan 27 2023, 2:35 AM.

Diff Detail

Event Timeline

yrouban created this revision.Jan 27 2023, 2:35 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 27 2023, 2:35 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
yrouban requested review of this revision.Jan 27 2023, 2:35 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 27 2023, 2:35 AM
jsilvanus added inline comments.Jan 27 2023, 2:44 AM
llvm/lib/AsmParser/Parser.cpp
36

Instead of duplicating the call, maybe you can do something like

std::optional<LLVMContext> OptContext;
return LLParser(F.getBuffer(), SM, Err, M, Index,
                M ? M->getContext() : OptContext.emplace(), Slots)
arsenm added a subscriber: arsenm.Jan 27 2023, 4:10 AM

Can you reupload the patch with full context?

So this is recycling an existing, already used context? I keep running into bugs caused by doing that

yrouban updated this revision to Diff 492712.Jan 27 2023, 5:19 AM
yrouban marked an inline comment as done.

accepted the suggested snippet.

I'm ready to land it as soon as it gets lgtm.

The local change itself looks now good to me, but @arsenm may have general concerns with the approach here, so please address his comment first.

yrouban updated this revision to Diff 493238.Jan 30 2023, 1:37 AM

I have added the diff with its full context.

yrouban added a comment.EditedJan 30 2023, 1:42 AM

Can you reupload the patch with full context?

Done

So this is recycling an existing, already used context? I keep running into bugs caused by doing that

Can you elaborate? What bugs do you see? I'm currently investigating a crash during deletion of modules and functions after parsing, but my case does not use that local LLVMContext. So I just saw this extra instantiation and proposed to get rid of it.

So this is recycling an existing, already used context? I keep running into bugs caused by doing that

Please take a look at D143487. Could it be your case?

This revision was not accepted when it landed; it landed in state Needs Review.Mar 20 2023, 12:57 AM
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
yrouban updated this revision to Diff 506875.Mar 21 2023, 1:55 AM

The deleted copy constructor LLVMContext(LLVMContext &) got its
parameter changed to const to allow the latest clang compiler to
instantiatiate template std::optional<LLVMContext>.

yrouban reopened this revision.Mar 22 2023, 2:47 AM

@arsenm are you OK with this now?

@jsilvanus , @arsenm, please take a look.

@arsenm are you OK with this now?

@jsilvanus, do you mind if I land the patch? I believe @arsenm just misunderstood the change. The given context is not recycled. The local context is recycled as it used to be. The only change is that the new local context is created only if it is really needed.

jsilvanus accepted this revision.Mar 23 2023, 1:02 AM

LGTM.

This should be a strict improvement over the existing state, as we avoid unnecessary creations of contexts in some cases.

This revision is now accepted and ready to land.Mar 23 2023, 1:02 AM