Skip to content

Increase occurrence counts within recursive continuation handlers #744

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

Closed
wants to merge 1 commit into from

Conversation

lthls
Copy link
Contributor

@lthls lthls commented Jul 21, 2022

This follows a discussion with @Gbury and @Keryan-dev on unboxing for Classic mode, where it's useful to handle occurrences of a variable inside a loop as if there were multiple occurrences.
It's not clear that it's useful for anything except regular variables, so the implementation may be tweaked to reflect that (and maybe avoid re-allocation in some cases).

@mshinwell mshinwell added the flambda2 Prerequisite for, or part of, flambda2 label Jul 22, 2022
@lthls
Copy link
Contributor Author

lthls commented Jul 22, 2022

A bit of context:
In To_cmm, bindings that are used exactly once are aggressively inlined, to take advantage of the peephole optimisations performed in Cmm_helpers. This is of course restricted to cases where the semantics allow it (preserving evaluation order), but typically any expression with no effects, and at most generative effects, benefits from being inlined.
However, these expressions might not be cheap, so by default we don't want to inline them inside loops. Currently this is done by flushing the delayed bindings before a recursive continuation, as we don't know if any of them might be used in the recursive handler, but it prevents us from inlining the uses that are in the body of the Let_cont.

It gets even more tricky with our work on unboxing as we want to inline some primitives even if it duplicates them at runtime (typically, boxed number allocations and closure projections), but the argument to these primitives must not be duplicated, so we need to know as soon as possible whether the primitive is going to be effectively run once (in which case we can inline the arguments, potentially allowing simplifications later), or if we need to bind the argument and the primitive separately.

This PR would allow us to rely on the fact that a variable marked as having one use in the free names is only used once at runtime, so we never need to backtrack our decisions for loops.

@Gbury
Copy link
Contributor

Gbury commented Oct 5, 2022

Note: this patch is included in #807

@mshinwell
Copy link
Collaborator

This has been merged as part of #905

@mshinwell mshinwell closed this Oct 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flambda2 Prerequisite for, or part of, flambda2
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants