Skip to content

Sink CodeInfo transformation into transform_result_for_cache, continued #57375

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Mar 4, 2025

Conversation

serenity4
Copy link
Member

Continuation of the work started in #56897.

cc @Keno

Several downstream consumers want to cache IRCode rather than CodeInfo.
Right now they need to override both `finish!` and `transform_result_for_cache`.
With this change, only overriding the latter should be sufficient.
As a nice bonus, we can avoid doing the work of converting to CodeInfo
for interpreters that don't cache at all such as the REPL interpreter.
@topolarity
Copy link
Member

Does this supersede #56897, or in addition to it?

@serenity4
Copy link
Member Author

serenity4 commented Feb 12, 2025

It probably supersedes it. The idea was to test a few changes on top of it, this PR is the same but with a few more bugfixes.

@serenity4
Copy link
Member Author

Test failures seem quite unrelated to me, this should be good for final review.

@Keno
Copy link
Member

Keno commented Feb 17, 2025

Test failure in the reduce test on x86_64-linux-gnuassertrr seems possibly related. Could you take a look? Note that the IR verifier does not run unless you're building with assertions.

@serenity4
Copy link
Member Author

Indeed, seems like we hit a corner case that slipped through #52224, which should be fixed by b6bf593.

Due to relying on cfg_simplify! in the pipeline (more so than before), it is possible that similar bugs surface in unexpected places. Are we comfortable with that?

@Keno
Copy link
Member

Keno commented Mar 2, 2025

The doctest is unhappy with this change. I'm fine updating the test or looking into whether there's a cfg_simplify! missing from that entry path somewhere.

@serenity4
Copy link
Member Author

I had changed it before adding cfg_simplify!, should be good now after #57375 (comment)

@Keno Keno merged commit c2370b3 into JuliaLang:master Mar 4, 2025
6 of 7 checks passed
serenity4 added a commit to serenity4/Cthulhu.jl that referenced this pull request Mar 17, 2025
aviatesk pushed a commit to JuliaDebug/Cthulhu.jl that referenced this pull request Mar 18, 2025
Co-authored-by: Cédric Belmant <cedric.belmant@juliahub.com>
Comment on lines +978 to +985
function retrieve_ir_for_inlining(mi::MethodInstance, opt::OptimizationState, preserve_local_sources::Bool)
result = opt.result
if result !== nothing
!result.simplified && simplify_ir!(result)
return retrieve_ir_for_inlining(mi, result.ir, preserve_local_sources)
end
retrieve_ir_for_inlining(mi, opt.src, preserve_local_sources)
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this new retrieve_ir_for_inlining (and the new OptimizationState handler of src_inlining_policy) tested somewhere? IIUC any test that would hit this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Never mind, because transform_result_for_cache in finish! is only applied to result that will be cached (due to isdefined(result, :ci)), inference local results and will keep the OptimizationState as is. So these new inlining code should be actually hit during the native compilation.

@aviatesk
Copy link
Member

As mentioned in this comment, this PR successfully removes unnecessary conversions from OptimizationState to CodeInfo for the inference local cache. Because of this, it might improve performance a bit. Also, since cfg_simplify! is delayed until inlining happens, the performance impact from cfg_simplify! should be significantly reduced. I think this is a great PR.

Keno pushed a commit that referenced this pull request Apr 2, 2025
…ze` (#57640)

As a follow-up to #57193 now that #57375 is merged.

---------

Co-authored-by: Cédric Belmant <cedric.belmant@juliahub.com>
@topolarity
Copy link
Member

Backport to 1.12?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants