aboutsummaryrefslogtreecommitdiffstats
path: root/lib/compiler
AgeCommit message (Collapse)Author
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
2018-10-19 Merge branch 'john/compiler/list_to_integer_2-is-pure'John Högberg
* john/compiler/list_to_integer_2-is-pure: compiler: list_to_integer/2 is pure
2018-10-18compiler: list_to_integer/2 is pureJohn Högberg
2018-10-16Merge branch 'maint'John Högberg
* maint: beam_utils: Handle bs_start_match2 in anno_defs
2018-10-16Merge branch 'john/compiler/bs_match-anno-liveness-fix/OTP-15353/ERL-753' ↵John Högberg
into maint * john/compiler/bs_match-anno-liveness-fix/OTP-15353/ERL-753: beam_utils: Handle bs_start_match2 in anno_defs
2018-10-15beam_utils: Handle bs_start_match2 in anno_defsJohn Högberg
2018-10-12Merge branch 'maint'Rickard Green
* maint: Updated OTP version Prepare release erts: Fix UNC path handling on Windows erts: Fix a compiler warning eldap: Fix race at socket close Fix bug for sockopt pktoptions on BSD erts: Fix memory leak on file read errors
2018-10-12Merge branch 'maint-21' into maintRickard Green
* maint-21: Updated OTP version Prepare release erts: Fix UNC path handling on Windows erts: Fix a compiler warning eldap: Fix race at socket close Fix bug for sockopt pktoptions on BSD erts: Fix memory leak on file read errors
2018-10-12Prepare releaseErlang/OTP
2018-10-08Merge branch 'maint'John Högberg
* maint: compiler: Forward +source flag to epp and fix bug in +deterministic epp: Allow user to set source name independently of input file name
2018-10-05beam_ssa_pre_codegen: Literal funs need stack frames tooJohn Högberg
Fixes a crash during code generation of the following code: call_atom() -> fun({send = Send}) -> Send() end.
2018-10-05compiler: Forward +source flag to epp and fix bug in +deterministicJohn Högberg
The source file path as given to `erlc` was included in an implicit file attribute inserted by epp, even when the +source flag was set to something else which was a bit surprising. It was also included when +deterministic was specified, breaking the flag's promise. This commit forwards the +source flag to epp so it inserts the right information, and if +deterministic is given it will be shaved to just the base name of the file, guaranteeing the same result regardless of how the input is reached.
2018-10-04Merge branch 'bjorn/compiler/misc-fixes'Björn Gustavsson
* bjorn/compiler/misc-fixes: beam_ssa: Remove unnecessary beam_ssa: prefixes beam_ssa_bsm: Fix replacement of variables in a remote call
2018-10-04beam_ssa: Remove unnecessary beam_ssa: prefixesBjörn Gustavsson
2018-10-04beam_ssa_bsm: Fix replacement of variables in a remote callBjörn Gustavsson
Co-authored-by: John Högberg <[email protected]>
2018-10-04Merge pull request #1973 from ↵John Högberg
jhogberg/john/compiler/improve-named-funs/OTP-15273/ERL-639 Optimize named funs and fun-wrapped macros
2018-10-03Merge pull request #1972 from josevalim/jv-nospawn_processBjörn Gustavsson
Introduce the no_spawn_compiler_process option
2018-10-03Optimize named funs and fun-wrapped macrosJohn Högberg
If a fun is defined locally and only used for calls, it can be replaced with direct calls to the relevant function. This greatly speeds up "named functions" (which rely on make_fun to recreate themselves) and macros that wrap their body in a fun.
2018-10-03Merge branch 'maint'Björn Gustavsson
* maint: Fix rare bug in binary matching (again) Conflicts: lib/compiler/src/beam_bsm.erl lib/compiler/src/sys_core_bsm.erl
2018-10-01Introduce the no_spawn_compiler_process optionJosé Valim
By default, all code is compiled in a separate process which is terminated at the end of compilation. However, some tools, like Dialyzer or compilers for other BEAM languages, may already manage their own worker processes and spawning an extra process may slow the compilation down. In such scenarios, you can pass this option to stop the compiler from spawning an additional process. This generalizes commit 657760e18087b0cdbaecc5e96e46f6f66bc9497a.
2018-10-01Merge branch 'bjorn/compiler/fix-r21-option'Björn Gustavsson
* bjorn/compiler/fix-r21-option: Fix code generation of binary instructions with the r21 option
2018-10-01Merge pull request #1965 from bjorng/bjorn/compiler/misc-cleanupsBjörn Gustavsson
Minor cleanups and bug fixes of the compiler
2018-09-28Fix code generation of binary instructions with the r21 optionBjörn Gustavsson
OTP 22 extends the binary instructions to support a Y register destination. When giving an option to compile for an earlier release, make sure that binary instructions don't use a Y register destination, by rewriting the binary instructions to use an X register destination and adding a `move` instruction to move the value to the Y register.
2018-09-28Merge pull request #1958 from jhogberg/john/compiler/ssa-bsm-optJohn Högberg
Rewrite BSM optimizations in the new SSA-based intermediate format
2018-09-28Remove unused instruction bs_context_to_binary from the compilerJohn Högberg
This has been superseded by bs_get_tail/3. Note that it is NOT removed from the emulator or beam_disasm, as old modules are still legal.
2018-09-28beam_ssa_pre_codegen: Remove unused variable aliasing supportBjörn Gustavsson
Remove the variable aliasing support that was needed for the old beam_bsm pass.
2018-09-28Improve coverage of 21 compatibilityBjörn Gustavsson
2018-09-28beam_ssa_opt: Eliminate redundant match alignment testsJohn Högberg
The beam_ssa_bsm pass welds chained matches together, but the match expressions themselves are unchanged and if there's a tail alignment check it will be done each time. This subpass figures out the checks we've already done and deletes the redundant ones.
2018-09-28Rewrite BSM optimizations in the new SSA-based intermediate formatJohn Högberg
This commit improves the bit-syntax match optimization pass, leveraging the new SSA intermediate format to perform much more aggressive optimizations. Some highlights: * Watch contexts can be reused even after being passed to a function or being used in a try block. * Sub-binaries are no longer eagerly extracted, making it far easier to keep "happy paths" free from binary creation. * Trivial wrapper functions no longer disable context reuse.