-
Notifications
You must be signed in to change notification settings - Fork 89
Delete unused local allocation regions in Flambda 2 #809
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
Delete unused local allocation regions in Flambda 2 #809
Conversation
67e107b
to
df3bd9a
Compare
As a note I'm not planning on implementing full support for these enhancements in |
ce96d72
to
e51b319
Compare
This PR also now aims to ensure that we don't end up with |
0d177ce
to
d54b424
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've left a number of comments, some of them applying to code that wasn't modified by this PR.
The only one that I think is serious is the one in to_cmm_env.ml
about the extra binding for my_region
.
4749264
to
bd807d5
Compare
Flambda 2 can't currently delete unused
Begin_region
andEnd_region
constructs (unlike the equivalent in Flambda 1), which I suspect is leaving some amount of unnecessary code around, together with inhibiting code motion inTo_cmm
.This patch aims to rectify this. It equips the primitives that allocate (and
Set_of_closures
) with region variables identifying which region is to be allocated in (this will always be the most recent by construction, and will remain that way throughout the pipeline). Functions now take amy_region
parameter which is substituted for the current region upon inlining.Begin_region
is now marked as having only generative effects rather than arbitrary effects, which still inhibits code motion inTo_cmm
(until such time as we figure out how to do that safely for these constructs), but allows deletion when the region variable it returns is unused.End_region
remains as having arbitrary effects but a special case is added (inSimplify_let_expr
andExpr_builder
) to do two things. Firstly for the purposes ofData_flow
the region variable inEnd_region
is not counted as a use. Secondly when rebuilding aLet
binding anEnd_region
we consultData_flow
to see if the region variable (the argument toEnd_region
) was actually used. If it was unused, then theEnd_region
is dropped, which will in turn cause theBegin_region
to be cleaned up without further ado.There is one outstanding problem relating to the region stack during CPS conversion (
Lambda_to_flambda
) not containing thetry_region
variable. Currently there is a hack in place so I can try some examples but this needs to be fixed properly. There are also a few things to fix inFexpr
.