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

Speed up alias analysis #7528

Merged
merged 6 commits into from
Aug 11, 2023
Merged

Conversation

frej
Copy link
Contributor

@frej frej commented Aug 2, 2023

Combined with improved kill-set calculation (8545471) and an improved data
structure for describing the alias status of variables (c389665), this patch series provides a substantial reduction of the time required for alias analysis. For the set of modules compiled by scripts/diffable the time spent in alias analysis is reduced by approximately 55%. For the example in Issue #7432, provided by José Valim, which has a large number of variables, the reduction is even more dramatic. The time spent in the alias analysis pass is reduced by 97%.

@github-actions
Copy link
Contributor

github-actions bot commented Aug 2, 2023

CT Test Results

       2 files     294 suites   11m 7s ⏱️
   779 tests    765 ✔️ 14 💤 0
4 843 runs  4 829 ✔️ 14 💤 0

Results for commit 0e97f10.

♻️ This comment has been updated with latest results.

To speed up review, make sure that you have read Contributing to Erlang/OTP and that all checks pass.

See the TESTING and DEVELOPMENT HowTo guides for details about how to run test locally.

Artifacts

// Erlang/OTP Github Action Bot

Switch from the standard fixpoint algorithm for calculating liveness
and from that deriving kill sets to a one-pass algorithm which
calculates the kill sets directly.

The algorithm traverses the basic blocks of the CFG post-order. It
traverses the instructions within a basic block in reverse order,
starting with the terminator. When starting the traversal of a basic
block, the set of variables that are live is initialized to the
variables that are live-in to the block's successors. When a def for a
variable is found, it is pruned from the live set. When a use which is
not in the live-set is found, it is a kill. The killed variable is
added to the kill set for the current instruction and added to the
live set.

As the only back-edges occurring in BEAM are for receives and
constructing terms are not allowed within the receive loop, back-edges
can be safely ignored as they won't change the alias status of any
variable.

Acknowledgments to José Valim for suggesting that kill sets could be
calculated directly.
Nothing happening in the exception block can propagate to the other
blocks as it has no successors.
erlang:exit/1 will never return, so nothing that happens after the
call can influence the aliasing status of a variable.
Variables which die in a basic block cannot influence the alias status
of variables in successor blocks. By pruning dead variables, which are
not part of a parent-child derivation relationship of live variables,
the size of the active sharing state is reduced. The reduction in size
speeds up subsequent `aa_merge_ss/3` operations.

Combined with improved kill-set calculation
(8545471) and an improved data
structure for describing the alias status of
variables (c389665), this patch
provides a substantial reduction of the time required for alias
analysis. For the set of modules compiled by `scripts/diffable` the
time spent in alias analysis is reduced by approximately 55%. For the
example in Issue erlang#7432 [1], provided by José Valim, which has a large
number of variables, the reduction is even more dramatic. The time
spent in the alias analysis pass is reduced by 97%.

[1] erlang#7432

Closes: erlang#7432
@frej frej force-pushed the frej/alias-analysis-speedup branch from add4fe5 to 786277f Compare August 3, 2023 07:47
@frej
Copy link
Contributor Author

frej commented Aug 3, 2023

Fixed Dialyzer error and rebase to pick up CI-fixes.

Remove commented out code and turn trace printouts into proper
?DP()-invocations.
@frej frej force-pushed the frej/alias-analysis-speedup branch from 786277f to 0e97f10 Compare August 3, 2023 08:17
@jhogberg jhogberg self-assigned this Aug 7, 2023
@jhogberg jhogberg added team:VM Assigned to OTP team VM enhancement testing currently being tested, tag is used by OTP internal CI labels Aug 7, 2023
@jhogberg jhogberg merged commit b102fad into erlang:master Aug 11, 2023
15 checks passed
@jhogberg
Copy link
Contributor

Merged, thanks for the PR!

@frej frej deleted the frej/alias-analysis-speedup branch August 11, 2023 07:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement team:VM Assigned to OTP team VM testing currently being tested, tag is used by OTP internal CI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants