-
Notifications
You must be signed in to change notification settings - Fork 786
PostAssemblyScript: Handle balanced retains involving allocations #2833
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
Conversation
While this should be good, I made this a draft for now just in case. Going to validate with the AS test suite and see if there's anything else to consider. |
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.
No concerns on the binaryen/C++ side (but I didn't think carefully about the AssemblyScript language logic here).
@@ -364,8 +364,16 @@ struct OptimizeARC : public WalkerPass<PostWalker<OptimizeARC>> { | |||
return (*releaseLocation)->cast<Call>()->operands[0]->cast<LocalGet>(); | |||
} | |||
|
|||
// Tests if the given retain is generally eliminable (does not retain an | |||
// allocation and does not reach an escape) | |||
bool testRetainEliminable(LocalSet* retain, AliasGraph& graph) { |
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.
can the AliasGraph here be const AliasGraph&
?
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.
Gave this a try, including updating the called functions herein, but the compiler then barks at me on []
accesses (no such operator) like graph.setInfluences[...]
and graph.getSetses[...]
in the called functions, as if std::map
etc. can't be used this way. Might be missing something, as usual :)
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 think the issue is that map[key]
can have side effects, it doesn't just do a read, but it also creates the entry (with a default value) if it isn't there.
You can do map.at(key)
if you know the key must be there. that will not change the map, and it will also check it actually exists, so it's better (but again, only if you know the key must be there).
With the passes removed meanwhile, this PR is not necessary anymore. |
Adds handling of a new edge case to the PostAssemblyScript pass, with the pass no longer considering retains balanced if one of the retain patterns involved retains an allocation (allocations must never drop below RC=1 while in use). A new test case
keeps.balancedRetainsWithAllocation
that is otherwise identical toeliminates.balancedRetains
but includes such an allocation verifies the expected behavior.