aboutsummaryrefslogtreecommitdiffstats
path: root/lib/compiler
AgeCommit message (Collapse)Author
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.
2018-11-06beam_trim, beam_jump: Print Name/Arity if there is a crashBjörn Gustavsson
This will help investigation of compiler bugs.
2018-11-06beam_trim: Use maps/cerl_sets instead of gb_trees/gb_setsBjörn Gustavsson
2018-11-02Merge branch 'maint'Björn Gustavsson
* maint: Fix bug when beam_jump removes put_tuple instructions Conflicts: lib/compiler/src/beam_jump.erl lib/compiler/test/beam_jump_SUITE.erl
2018-11-02Merge pull request #2011 from bjorng/bjorn/compiler/beam_exceptBjörn Gustavsson
beam_except: Generalize translation to func_info instructions
2018-11-01Merge branch 'bjorn/compiler/diffable'Björn Gustavsson
* bjorn/compiler/diffable: scripts/diffable: Correct the number of modules being compiled scripts/diffable: Use the diffable compiler option Add a diffable option for the compiler scripts/diffable: Refactor option parsing
2018-10-31Fix bug when beam_jump removes put_tuple instructionsBjörn Gustavsson
`beam_jump` could remove a `put_tuple` instruction when the tuple would not be used, but it would leave the following `put` instructions. Make sure they are removed. https://bugs.erlang.org/browse/ERL-759
2018-10-30beam_except: Generalize translation to func_info instructionsBjörn Gustavsson
The `beam_except` pass replaces some calls to `erlang:error/1` or `erlang:error/2` with specialized instructions in order to reduce the size of the BEAM code. In functions that do binary matching, `beam_except` would fail to translate the instructions that generate a `function_clause` exception. Here is an example: bsum(<<H:16,T/binary>>, Acc) -> bsum(T, Acc+H); bsum(<<>>, Acc) -> Acc. The BEAM code that generates the `function_clause` exception looks like this: {label,4}. {test_heap,2,3}. {put_list,{x,1},nil,{x,1}}. %% The following two instructions prevents the translation. {bs_set_position,{x,2},{x,0}}. {bs_get_tail,{x,2},{x,0},3}. {test_heap,2,2}. {put_list,{x,0},{x,1},{x,1}}. {move,{atom,function_clause},{x,0}}. {line,...}. {call_ext,2,{extfunc,erlang,error,2}}. Make the translation of `function_clause` exceptions smarter, so that the following code will be produced: {label,4}. {bs_set_position,{x,2},{x,0}}. {bs_get_tail,{x,2},{x,0},3}. {jump,{f,1}}. %Jump to `func_info` instruction. (This issue was noticed when looking at the code generated by https://github.com/tomas-abrahamsson/gpb.)
2018-10-23Add a diffable option for the compilerBjörn Gustavsson
Add the `diffable` option to produce a more diff-friendly output in a .S file. In a diffable .S file, label numbers starts from 1 in each function and local function calls use function names instead of labels. scripts/diffable produces diff-friendly files but only for a hard-coded sub set of files in OTP. Having the option directly in the compiler makes is easier to diff the BEAM code for arbitrary source modules.
2018-10-22Make the move elimination optimization in beam_jump safeBjörn Gustavsson
The `beam_jump` pass could eliminate `move` instructions when it was not safe to do so. See the new test case `unsafe_move_elimination/1` for an example. Reported-by: Michał Muskała