Age | Commit message (Collapse) | Author |
|
Moving away this optimization makes beam_block do one thing
and one thing only -- creating blocks.
|
|
The only caller of bif_to_test/3 is beam_ssa_codegen.
|
|
Disallow a literal map source for get_map_elements. There is currently
runtime support for get_map with a literal map source, but by
forbidding it in OTP 22, the runtime support could be removed in a
future release (perhaps OTP 24).
Also verify that the source arguments for get_list, get_hd, get_tl,
and get_tuple_element are not literals. Literals are not supported for
those instructions in the runtime system; verifying it in
beam_validator is a convenience so that this kind of bug will
be detected already during compilation.
|
|
The source map for `get_map_element` is not supposed to be a literal,
and the sanitization code is supposed to ensure that.
The sanitization incorrectly translated this code:
Map = get_tuple_element literal {ok,#{key=>value}}, literal 1
Var = get_map_element Map, literal {a,key}
To this code:
Var = get_map_element literal #{key=>value}, literal {a,key}
Make sure to substitute the arguments for `get_map_element` before
looking for a literal source map.
|
|
|
|
Using maps and cerl_sets instead of dict and sets will slightly
speed up the beam_clean pass for modules with many functions
and/or calls to local functions.
|
|
It is not necessary to combine get_hd and get_tl instruction to
a get_list instruction. It will be done in beam_z.
After this change, beam_flatten does nothing more than eliminating
the blocks.
|
|
Continuing the simplification of beam_flatten, move the optimization
that eliminates a test_heap instruction following a binary construction
by incorporating the allocation of the heap space into the bs_init*
instruction itself.
This change does not change the generated code in any way.
Also remove beam_utils:combine_heap_needs/2, because beam_flatten
was the last user of it.
|
|
The purpose of beam_flatten is to eliminate the blocks created by
beam_block, but it also does a few optimizations because at the
time the optimizations were added, beam_flatten was the most
convenient place.
Move the optimization that places `{move,Something,{x,0}}` before
`call` instructions from beam_flatten to beam_ssa_codegen.
This change will very slightly improve compilation times, and it
will also apply the optimization in more places. In particular,
a `{move,Literal,{x,0}}` would never be moved passed a `trim`
instruction before this change. Now it will.
|
|
jhogberg/john/compiler/validator-aliased-type-fixes/ERL-735
beam_validator: Use set_aliased_type in more operations
|
|
The following code broke because aliases weren't tracked for hd/1:
bug(Bool) ->
Bug = remote:call(),
if
Bool -> %% Branch of some kind.
_ = hd(Bug),
remote:call(),
hd(Bug)
end.
Related to 1f221b27f1336e747f7409692f260055dd3ddf79
|
|
|
|
|
|
|
|
get_anno/3: as get_anno but with a default value
definitions/1-2: returns a map of variable definitions (#b_set{})
uses/1-2: returns a map of all uses of a given variable
mapfold_blocks_rpo/4: mapfolds over blocks
|
|
The upcoming beam_ssa_bsm pass makes this redundant.
|
|
Clean up variable-related cruft in new SSA passes
|
|
|
|
|
|
Now that variables are represented as #b_var{}, there's no longer
any risk of colliding with anything else.
|
|
We chose to refer to variables through their var_name() because we
anticipated the need to annotate them, but it turned out we didn't
really need that, and many things become a lot cleaner if the
entire #b_var{} is used to represent variables.
|
|
Replace beam_dead with beam_ssa_dead
|
|
* maint:
Updated OTP version
Update release notes
Update version numbers
Fix include-path regression caused by dd0a39c
|
|
* maint-20:
Updated OTP version
Update release notes
Update version numbers
Fix include-path regression caused by dd0a39c
|
|
Most of the optimizations in beam_dead have been superseded
by the optimizations in beam_ssa_dead.
The forward/1 pass of beam_dead has been moved to beam_jump.
The beam_split pass splits blocks that contain instructions with
non-zero labels. Because there are no optimizations left that optimize
instructions within blocks, beam_block never needs to put such
instructions into blocks in the first place. beam_split also moved
'move' instructions out block to help beam_dead. That is no longer
necessary since beam_dead no longer exists.
|
|
Add beam_ssa_dead to perform the main optimizations done
by beam_dead:
* Shortcut branches that jump to another block with a branch.
If it can be seen that the second branch will always branch
to a specific block, replace the target of the first branch.
* Combined nested sequences of '=:=' tests and switch
instructions operating on the same variable to a single switch.
Diffing the compiler output, it seems that beam_ssa_dead finds
many more opportunities for optimizations than beam_dead,
although it does not find all opportunities that beam_dead does.
In total, beam_ssa_dead is such improvement over beam_dead that
there is no reason to keep beam_dead as well as beam_ssa_dead.
Note that beam_ssa_dead does not attempt to optimize away
redundant bs_context_binary instructions, because that instruction
will be superseded by new instructions in the near future.
|
|
Omitting `kill` instructions before BIFs that throw exceptions
will reduce the code size. This optimization supersedes the same
optimizations in beam_dead.
|
|
|
|
In beam_ssa_type, do substitutions similar to what ssa_opt_misc does
to get rid of variables that evaluate to constant values. That
somewhat simplifies the code of beam_ssa_type, and could improve
performance of the compiler since instructions and variables are
eliminated, reducing the amount of work for later passes.
|
|
|
|
Remove the following clause from the `fun` clauses in arith_op_types/2
because it cannot possibly match:
(_, any) -> number;
Here is why it cannot match:
The second argument is the accumulator for lists:foldl/3.
Its initial value is `unknown`.
None of the clauses will update the accumulator to `any`, including
the clause that matches `any` in the first argument -- it will set the
accumulator to `number`.
Thus, the accumulator (second argument) can never be `any` and
the clause can never match. QED.
|
|
The floating point optimization relies on heavily on the block
order in the lineararized representation. A new optimization
could easily break the optimization, for example so that no
`fcheckerror` instructions were emitted.
Rewrite the optimization to avoid dependencies on the linear
block order.
|
|
* maint:
Updated OTP version
Update release notes
Update version numbers
erts: Fix "Prevent inconsistent node lists" fix
Fix include-path regression caused by dd0a39c
Restore default SIGTERM behaviour for port programs
|
|
* maint-21:
Updated OTP version
Update release notes
Update version numbers
erts: Fix "Prevent inconsistent node lists" fix
Fix include-path regression caused by dd0a39c
Restore default SIGTERM behaviour for port programs
|
|
Not doing CSE for tuple_size/1 seems to generate slightly better
code in most cases.
|
|
|
|
Phi nodes with only literals are fairly common, so it's worthwhile
to optimize this case.
|
|
This optimization working on the SSA format will replace
the similar optimization in beam_dead. See the comment
for an explanation of what the new optimization does.
|
|
When the argument for a #b_switch{} comes from a phi node
with only literal values, the switch list could be pruned to
only contain the possible values. It could also be possible
to eliminate the failure label.
Also simplify a switch with a single value list or switch that can be
replaced with an is_boolean test.
|
|
Nested cases can led to code such as this:
10:
_1 = phi {literal value1, label 8}, {Var, label 9}
br 11
11:
_2 = phi {_1, label 10}, {literal false, label 3}
The phi nodes can be coalesced like this:
11:
_2 = phi {literal value1, label 8}, {Var, label 9},
{literal false, label 3}
Coalescing can help other optimizations, and can in some cases reduce
register shuffling (if the phi variables for two phi nodes happens to
be allocated to different registers).
|
|
Add more instructions to the list of functions that can be safely
removed if their values are not used. This is necessary for
correctness when doing more aggressive optimizations. Without this
change, the 'succeeded' instruction could be optimized away leaving
just the instruction followed by an unconditional branch, which the
beam_ssa_codegen does not know how to handle. Here is an example:
_3 = bs_start_match _1
br label 13
By adding bs_start_match to the list, the bs_start_match instruction
will be removed too. (If the result of bs_start_match is actually
used, the succeeded instruction would not be removed.)
While we are it, rename the misnamed function is_pure/1 to
no_side_effect/1 and move it to beam_ssa. is_pure/1 is a bad name
because bif:get has no side effect, but is not pure.
|
|
A select_val instruction that test whether a register is a boolean
like this:
{select_val,Reg,{f,Fail},{list,[{atom,true},Lbl,{atom,false},Lbl]}}.
can be replaced with an is_boolean test:
{test,is_boolean,{f,Fail},[Reg]}.
{jump,{f,Lbl}}.
This optimization is currently done in beam_dead. However, if done in
the beam_peep, it can catch more opportunities to do the optimization,
because after having run beam_jump, labels that were different have
been coalesced.
|
|
Those optimizations are unsafe if beam_dead has been run before.
|
|
This functionality will soon be needed.
|
|
The 'move' instruction can be eliminated in code such as:
{test,is_eq_exact,{f,42},[{x,0},{atom,value}]}.
{move,{atom,value},{x,0}}.
Move that optimization from beam_dead to beam_a. The optimization
will be simpler because the 'move' instruction has not yet
been moved into a block. Getting rid of 'move' earlier will
also save work for later passes.
Also move the optimization that eliminates instructions such
as from beam_dead to beam_a:
{test_is_eq_exact,{f,42},[{x,0},{x,0}]}.
|
|
It is faster to use cerl_sets instead of gb_sets to keep track of
seen blocks.
|
|
Add trim_unreachable/1 to remove unreachable blocks
and adjust phi nodes.
|
|
Since beam_ssa:linearize/1 may remove blocks that are unreachable,
adjust phi nodes to make sure that they don't refer to discarded
blocks or to blocks that no longer branch to the phi node in
question.
|
|
|
|
|