aboutsummaryrefslogtreecommitdiffstats
path: root/lib/compiler/src/beam_peep.erl
AgeCommit message (Collapse)Author
2018-06-18Update copyright yearHenrik Nord
2018-04-29Introduce is_map_key/2 guard BIFMichał Muskała
This complements the `map_get/2` guard BIF introduced in #1784. Rationale. `map_get/2` allows accessing map fields in guards, but it might be problematic in more complex guard expressions, for example: foo(X) when map_get(a, X) =:= 1 or is_list(X) -> ... The `is_list/1` part of the guard could never succeed since the `map_get/2` guard would fail the whole guard expression. In this situation, this could be solved by using `;` instead of `or` to separate the guards, but it is not possible in every case. To solve this situation, this PR proposes a `is_map_key/2` guard that allows to check if a map has key inside a guard before trying to access that key. When combined with `is_map/1` this allows to construct a purely boolean guard expression testing a value of a key in a map. Implementation. Given the use case motivating the introduction of this function, the PR contains compiler optimisations that produce optimial code for the following guard expression: foo(X) when is_map(X) and is_map_key(a, X) and map_get(a, X) =:= 1 -> ok; foo(_) -> error. Given all three tests share the failure label, the `is_map_key/2` and `is_map/2` tests are optimised away. As with `map_get/2` the `is_map_key/2` BIF is allowed in match specs.
2017-12-08Use the new syntax for retrieving stack tracesBjörn Gustavsson
2017-08-26Enhance optimisations in beam_peepMichał Muskała
When cleaning selects, it might happen we're left with only one pair. In such case convert to a regular test + jump.
2017-01-12Add specs for the beam_*:module/2 functionsBjörn Gustavsson
2016-04-18Merge branch 'bjorn/compiler/misc-opt'Björn Gustavsson
* bjorn/compiler/misc-opt: v3_kernel: Construct literal lists properly Use the register map in %live in beam_utils:is_killed_block/2 Teach beam_utils to check liveness for put_map instructions beam_peep: Help out beam_jump
2016-04-11beam_peep: Help out beam_jumpBjörn Gustavsson
beam_jump fails to optimize the following: jump 2 label 1 label 2 Since this situation is rare, instead of complicating beam_jump, add the optimization to beam_peep. It will always succeed, since adjacent labels have been coalesced.
2016-03-15update copyright-yearHenrik Nord
2015-09-28Move select_val optimization from beam_clean to beam_peepBjörn Gustavsson
There is an optimization in beam_clean that will remove values having the same label as the failure label in a select_val instruction. Conceptually, this optimization is in the wrong module since ideally beam_clean is a mandatory pass that should not do optimizations. Furthermore, this part of beam_clean is called three times (from beam_dead, beam_peep, and as a compiler pass from the 'compile' module), but it only does useful one of the times it is called. Therefore, move this optimization to the beam_peep pass. The same optimization is done in beam_dead, but unfortunately it misses some opportunities for optimization because the code sharing optimization in beam_jump (share/1) runs after beam_dead. It would be more satisfactory to have this optimization only in beam_dead, but it turned out not to be trivial. If we try to run beam_jump:share/1 before beam_dead, some optimizations will no longer work in beam_dead because fallthroughs have been eliminated. For the moment, the possible solutions to this problem seems to involve more work and more complicated code than the gain from eliminating the duplicated optimization would gain.
2015-08-21Move rewriting of select_val to is_boolean from beam_peep to beam_deadBjörn Gustavsson
We can rewrite more instances of select_val to is_boolean because it is not necessary that a particular label follows the select_val.
2015-06-18Change license text to APLv2Bruce Yinhe
2015-03-09beam_peep: Optimize away redundant use of is_boolean testsBjörn Gustavsson
2013-01-25Update copyright yearsBjörn-Egil Dahlberg
2012-10-10Rewrite select_val and select_tuple_arity to a select instructionBjörn Gustavsson
Eliminate some code bloat.
2010-06-02Merge branch 'bg/compiler' into devErlang/OTP
* bg/compiler: beam_peep: Remove optimization already done by beam_dead beam_dead: Combine is_eq_exact instructions into select_val instructions Evaluate is_record/3 at compile-time using type information Evaluate element/2 at compile-time using type information erl_expand_records: Replace is_record() with matching OTP-8668 bg/compiler The compiler optimizes record operations better.
2010-06-02beam_peep: Remove optimization already done by beam_deadBjörn Gustavsson
2009-11-20The R13B03 release.OTP_R13B03Erlang/OTP