Skip to content
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

Make constant propagation and branch removal per-method, on-demand and called from MarkStep #1733

Closed
3 tasks done
vitek-karas opened this issue Jan 8, 2021 · 1 comment
Closed
3 tasks done
Assignees
Milestone

Comments

@vitek-karas
Copy link
Member

vitek-karas commented Jan 8, 2021

The changes made to solve #1164 will mean that we can't run the constant propagation and branch removal before MarkStep as not all assemblies will be loaded at that time. It also means the algorithm can't rely on having visibility into all assemblies at the same time.

So we need to change it to be:

  • per-method - it could be per-assembly, but it doesn't help much (not a big difference between per-method and per-assembly) and would be wasteful
  • on-demand - only compute the constant propagation and branch removal when needed - this is basically a fallback of making assembly loading on-demand
  • called from MarkStep right before ProcessMethod - this is basically an optimization to only perform the computations for methods which are actually going to be marked (no need to compute this for methods which will be trimmed from the app)

To do this the plan is to:

  • - refactor the RemoveUnreachableBlocksStep so that it doesn't precompute constant returns for all methods - do this on-demand from TryInlineBodyDependencies. But keep the iterative algorithm - meaning we will go over all methods multiple times to perform the recursive propagation. Only compute if method returns a constant when needed #1734
  • - refactor the RemoveUnreachableBlocksStep to perform constant propagation and branch removal truly on-demand - so basically introduce a method which will do it for a single method - remove the iterative part of the algorithm. Constant propagation without iterations and stack based #1756
    This will probably mean to:
    • Introduce a queue of methods which must be processed
    • When reaching a method call to a method which hasn't been processed, add it to the queue and re-try the current method later on (this is basically avoiding recursion - and replacing it with re-try and a queue)
    • Ideally reduce the number of methods this needs to happen on even more
  • - remove the RemoveUnreachableBlocksStep completely and instead call the functionality from MarkStep right before ProcessMethod. So that it only happens on marked methods (but before we actually go and mark the method's body). Constant propagation directly from MarkStep #1771

/cc @sbomer @marek-safar

@vitek-karas
Copy link
Member Author

With the merging of #1771 this should be done - closing the issue.

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

No branches or pull requests

2 participants