Skip to content

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

Closed

Conversation

dcodeIO
Copy link
Contributor

@dcodeIO dcodeIO commented May 6, 2020

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 to eliminates.balancedRetains but includes such an allocation verifies the expected behavior.

@dcodeIO dcodeIO marked this pull request as draft May 7, 2020 10:09
@dcodeIO
Copy link
Contributor Author

dcodeIO commented May 7, 2020

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.

Copy link
Member

@kripken kripken left a 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) {
Copy link
Member

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&?

Copy link
Contributor Author

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 :)

Copy link
Member

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).

@dcodeIO
Copy link
Contributor Author

dcodeIO commented Apr 7, 2021

With the passes removed meanwhile, this PR is not necessary anymore.

@dcodeIO dcodeIO closed this Apr 7, 2021
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.

2 participants