aboutsummaryrefslogtreecommitdiffstats
path: root/lib/compiler
AgeCommit message (Collapse)Author
2019-01-11beam_ssa_codegen: Correct label generation for 'or'Björn Gustavsson
Code generation for 'or' with {z,0} destination could generate duplicate new labels. The bug was introduced in eb571f8951bd.
2019-01-11beam_ssa_pre_codegen: Don't use z registers for 'xor' and 'is_record'Björn Gustavsson
There is no easy way to convert xor or is_record/2 to test operations.
2019-01-11beam_ssa_pre_codegen: Correct short-lived optimizationBjörn Gustavsson
2019-01-11beam_ssa_type: Properly eliminate 'succeeded' instructionsBjörn Gustavsson
When an instruction has been eliminated, the 'succeeded' instruction must be eliminated.
2019-01-11erl_bif: Mark is_map/1 as safeBjörn Gustavsson
2019-01-07Merge branch 'maint'Björn Gustavsson
* maint: Remove unsafe optimization for delaying creation of stackframe Conflicts: lib/compiler/src/v3_codegen.erl
2019-01-07Merge branch 'bjorn/compiler/interim-tuple-bug/OTP-15501/ERL-807' into maintBjörn Gustavsson
* bjorn/compiler/interim-tuple-bug/OTP-15501/ERL-807: Remove unsafe optimization for delaying creation of stackframe
2019-01-07Remove unsafe optimization for delaying creation of stackframeBjörn Gustavsson
b89044a800c4 introduced an optimization that tries to delay creation of stack frames. It turns out that this optimization is not always safe. (See the new test case for an example.) Since the code generator is completely rewritten in the `master` branch for the upcoming OTP 22 release, it does not make sense trying to mend this optimization. It is better to remove it. Out of a sample of about 1000 modules in OTP, about 50 of them are changed as a result of removing this optimization. The compiler in OTP 22 will do the same optimization in a cleaner, safer, and more effective way. https://bugs.erlang.org/browse/ERL-807
2018-12-18Make all compiler options work in the option listBjörn Gustavsson
Before OTP 22, the option `{nowarn_deprecated_function,MFAs}` was only recognized when given in the file with the attribute `-compile()`. (The option `{nowarn_unused_function,FAs}` was incorrectly documented to only work in a file, but it also worked when given in the option list.) Starting from OTP 22, all options that can be given in the file can also be given in the option list.
2018-12-13Merge branch 'maint'Sverker Eriksson
2018-12-13Merge branch 'bjorn/cuddle-with-tests'Björn Gustavsson
* bjorn/cuddle-with-tests: Cover code in beam_ssa_opt Cover code in beam_ssa_dead Cover code in beam_trim Eliminate warnings for unused variables regressions_SUITE: Fix exports map_SUITE: Test for mixed map creation map_SUITE: Fix indentation
2018-12-12Add empty 'since' attribute for old modules and functionsSverker Eriksson
2018-12-11Add "since" attributes in xml for new functions and modulesSverker Eriksson
introduced after OTP_R13B03.
2018-12-11Merge branch 'maint'Henrik Nord
* maint: Updated OTP version Prepare release
2018-12-10Prepare releaseErlang/OTP
2018-12-06Merge branch 'maint'Björn Gustavsson
* maint: Fix unsafe optimization of stack trace building
2018-12-06Merge pull request #2043 from bjorng/bjorn/compiler/tuple_sizeBjörn Gustavsson
beam_ssa_pre_codegen: Fix an internal consistency failure
2018-12-05Fix unsafe optimization of stack trace buildingBjörn Gustavsson
The `sys_core_fold` pass of the compiler would optimize away the building of the stacktrace in code such as: try ... catch C:R:Stk -> erlang:raise(C, {R,Stk}, Stk) end That optimization is unsafe and would cause a crash in a later compiler pass.
2018-12-05beam_ssa_pre_codegen: Fix an internal consistency failureBjörn Gustavsson
The following function: is_two_tuple(Arg) -> case is_tuple(Arg) of false -> false; true -> tuple_size(Arg) == 2 end. would cause an internal consistency failure: Internal consistency check failed - please report this bug. Instruction: {bif,tuple_size,{f,0},[{x,0}],{z,0}} Error: {invalid_store,{z,0},{integer,[]}}:
2018-11-30Cover code in beam_ssa_optBjörn Gustavsson
2018-11-30beam_validator: Don't discard fragilityBjörn Gustavsson
Be more careful when updating types so that fragility is not lost.
2018-11-30Cover code in beam_ssa_deadBjörn Gustavsson
2018-11-30Cover code in beam_trimBjörn Gustavsson
2018-11-29Eliminate warnings for unused variablesBjörn Gustavsson
2018-11-29regressions_SUITE: Fix exportsBjörn Gustavsson
2018-11-29map_SUITE: Test for mixed map creationBjörn Gustavsson
2018-11-29map_SUITE: Fix indentationBjörn Gustavsson
2018-11-28Cover more code in beam_jumpBjörn Gustavsson
The previous optimizations caused some code in beam_jump to become uncovered. Add tests to cover more code. Also remove a clause in beam_jump:opt/3 that does not seem possible to cover anymore (this is safe, because the clause was an optimization).
2018-11-28beam_jump: Eliminate jumps to return instructionsBjörn Gustavsson
Eliminate a jump to a return sequence, replacing the jump with the return sequence. This optimization always save execution time and may also save code space.
2018-11-28beam_jump: Remove the unused #st.index fieldBjörn Gustavsson
181cfc4ef9d1 stopping used #st.index.
2018-11-28Cover some code in beam_peepBjörn Gustavsson
Some lines in beam_peep were no longer covered when the sharing optimization was added to beam_ssa_opt. Also remove some code from beam_peep that no longer seems possible to cover.
2018-11-28Share the code for semantically equivalent blocksBjörn Gustavsson
Share code for semantically equivalent blocks referred to to by `br` and `switch` instructions. A similar optimization is done in `beam_jump`, but doing it here as well is beneficial as it may enable other optimizations. Also, if there are many semantically equivalent clauses, this optimization can substanstially decrease compilation times.
2018-11-21Merge branch 'maint'Björn Gustavsson
* maint: Fix internal consistency failure for is_function/2 Conflicts: lib/compiler/src/beam_utils.erl
2018-11-21Sort move instructions on the Y registerBjörn Gustavsson
Sort sequences of `move` instructions on the Y register. When moving from X registers to Y registers, having the instructions sorted on Y registers give the loader more opportunities to use `move_window{3,4,5}` instructions. For examples, the following five instructions: move_xy x(2) y(0) move_xy x(1) y(1) move_xy x(0) y(2) move_xy x(5) y(3) move_xy x(4) y(4) can be replaced with: move_window5_xxxxxy x(2) x(1) x(0) x(5) x(4) y(0) When the Y registers are not ordered so that `move_window5` can be used, the loader would typically combine the first three moves to a `move3_xyxyxy` instruction and the last two moves to a `move2_par_xyxy` instruction. When moving from Y registers to X registers, sorting on the Y registers could potentially be more cache-friendly. It could also be worthwhile investigating a new `move_window` instruction in the BEAM interpreter that could move values from contiguous Y registers to X registers. Note that `scripts/diffable` can generate diffable dissambly files for the loaded BEAM code: $ scripts/diffable --dis 0 $ scripts/diffable --dis 1 $ diff -u 0 1
2018-11-20Fix internal consistency failure for is_function/2Björn Gustavsson
There could be an internal consistency failure when using is_function/2, because an optimization did not take into account that is_function/2 can fail. https://bugs.erlang.org/browse/ERL-778
2018-11-19beam_ssa_pre_codegen: Improve reuse of Y registersBjörn Gustavsson
Enhance the copy_retval/1 optimization to allow Y registers to be reused in more circumstances. Reusing Y register can often reduce the size of the stack frame.
2018-11-19beam_ssa_codegen: Improve optimization of allocate instructionsBjörn Gustavsson
There could be `allocate_zero` instructions where `allocate` would suffice or superfluous `init` instructions because all possible initializations of Y registers were not taken into account. While at it, also add some more comments.
2018-11-18Add get_map_element to beam_ssa:no_side_effect/1Björn Gustavsson
The `get_map_element` instruction has no side effects, and should be removed if its value is not used.
2018-11-16Merge branch 'maint'John Högberg
* maint: Updated OTP version Prepare release
2018-11-16Merge branch 'maint-21' into maintJohn Högberg
* maint-21: Updated OTP version Prepare release
2018-11-15beam_ssa_dead: Speed up optimization of switch instructionsBjörn Gustavsson
`beam_ssa_dead` can waste a lot of time trying to optimize an unoptimizable `switch` instruction. By being a little bit smarter when optimizing `switch` instructions, the runtime for the beam_ssa_dead pass was reduced approximately by half on my computer for this module: https://github.com/aggelgian/cuter/blob/master/src/cuter_binlib.erl Noticed-by: Kostis Sagonas
2018-11-15beam_ssa_pre_codegen: Eliminate a bottleneck in linear scanBjörn Gustavsson
The linear scan algorithm keeps unhandled intervals in two separate lists: one for intervals with reserved registers and one for intervals without reserved registers. When collecting the available free registers all unhandled intervals with reserved registers must be checked for overlap. Unhandled intervals that had a preferred register were put into the list of intervals with reserved registers, leading to a lot of unecessary overlap checking if there were many intervals with preferred registers. Changing the partition code to put intervals with preferred registers into the general list of unhandled intervals will reduce the compilation time if there are many preferred registers. On my computer, this change reduced the time of the linear scan pass from about 20 seconds down to about 0.5 seconds for this module: https://github.com/aggelgian/cuter/blob/master/src/cuter_binlib.erl Noticed-by: Kostis Sagonas
2018-11-15beam_ssa_type: Speed up type analysis for huge functionsBjörn Gustavsson
The type analysis pass (`beam_ssa_type`) keeps the type information for all variables that are in scope. For huge functions, the `join_types/2` function could get really slow when joining two maps with thousands of variables in each. Use a conservative approach to discard type information for variables only used once by a `br` or `switch` in the same block as the variable is defined in. This approach reduces the runtime for the `beam_ssa_type` pass from a few minutes down to few seconds for this module: https://github.com/aggelgian/cuter/blob/master/src/cuter_binlib.erl Rejected approach: Calculate liveness information for all variables and discard type information for any variable that would not be used again. That turned out to not work because some optimizations would invalidate the liveness (in particular, substitutions could lengthen the lifetime for a variable). Trying to update the liveness information when doing the optimizations would be tricky. Noticed-by: Kostis Sagonas
2018-11-15Prepare releaseErlang/OTP
2018-11-06beam_trim: Add comments about how all this worksBjörn Gustavsson
Also rename a few functions in attempt to make it clearer.
2018-11-06beam_trim: Recognize more safe labelsBjörn Gustavsson
Recognize more safe labels to enable stack trimming in more circumstances.
2018-11-06beam_trim: Handle the new binary matching instructionsBjörn Gustavsson
2018-11-06beam_utils: Remove unused API functionsBjörn Gustavsson
Remove the now unused beam_utils:is_not_used/3 and beam_utils:is_killed/3 functions and friends. Starting out as simple functions a long time ago, those functions have grown and grown to support more optimizations. The number of bugs found and fixed in beam_utils has also grown over time.
2018-11-06beam_trim: Stop using beam_utils:is_not_used/3Björn Gustavsson
Eliminate the use of beam_utils:is_not_used/3 by implementing a simple is_not_used() function in beam_trim itself. The new version actually makes trimming possible in more circumstances, because beam_utils:is_not_used/3 was too conservative for the purpose of stack trimming (it was previously used for optimizations where it was necessary to be more conservative). Alternatives considered: I tried to implement stack trimming in beam_ssa_codegen but it turned out to be a total mess. Not surprisingly, it turns out that an optimization that renumbers Y registers is hard to do on an intermediate representation that still use variables instead of BEAM registers.
2018-11-06beam_jump: Stop using beam_utils:is_killed/3Björn Gustavsson
Prior to this commit, the optimizations using beam_utils:is_killed/3 were only executed a few times in the entire compiler test suite.