aboutsummaryrefslogtreecommitdiffstats
path: root/lib/compiler/src/beam_flatten.erl
diff options
context:
space:
mode:
authorBjörn Gustavsson <[email protected]>2018-09-20 04:23:12 +0200
committerBjörn Gustavsson <[email protected]>2018-09-26 12:19:56 +0200
commit60d4e673149aaa34e977e42aabeef3efd4b7c34e (patch)
tree8f8cae8c43a56876625c117fe3ae1b2f93ad2fbd /lib/compiler/src/beam_flatten.erl
parent08ef38b2c9f84ed118e693bff38efa69fc2c7eb8 (diff)
downloadotp-60d4e673149aaa34e977e42aabeef3efd4b7c34e.tar.gz
otp-60d4e673149aaa34e977e42aabeef3efd4b7c34e.tar.bz2
otp-60d4e673149aaa34e977e42aabeef3efd4b7c34e.zip
Move optimization of 'move' from beam_flatten to beam_ssa_codegen
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.
Diffstat (limited to 'lib/compiler/src/beam_flatten.erl')
-rw-r--r--lib/compiler/src/beam_flatten.erl33
1 files changed, 1 insertions, 32 deletions
diff --git a/lib/compiler/src/beam_flatten.erl b/lib/compiler/src/beam_flatten.erl
index 973d16a1bc..c8bc1b7b84 100644
--- a/lib/compiler/src/beam_flatten.erl
+++ b/lib/compiler/src/beam_flatten.erl
@@ -32,8 +32,7 @@ module({Mod,Exp,Attr,Fs,Lc}, _Opt) ->
{ok,{Mod,Exp,Attr,[function(F) || F <- Fs],Lc}}.
function({function,Name,Arity,CLabel,Is0}) ->
- Is1 = block(Is0),
- Is = opt(Is1),
+ Is = block(Is0),
{function,Name,Arity,CLabel,Is}.
block(Is) ->
@@ -115,33 +114,3 @@ insert_alloc_1([{bs_init=Op,Fail,Info0,Live,Ss,Dst}|Is],
reverse(Acc, [I|Is]);
insert_alloc_1([{bs_put,_,_,_}=I|Is], Alloc, Acc) ->
insert_alloc_1(Is, Alloc, [I|Acc]).
-
-%% opt(Is0) -> Is
-%% Simple peep-hole optimization to move a {move,Any,{x,0}} past
-%% any kill up to the next call instruction. (To give the loader
-%% an opportunity to combine the 'move' and the 'call' instructions.)
-%%
-opt(Is) ->
- opt_1(Is, []).
-
-opt_1([{move,_,{x,0}}=I|Is0], Acc0) ->
- case move_past_kill(Is0, I, Acc0) of
- impossible -> opt_1(Is0, [I|Acc0]);
- {Is,Acc} -> opt_1(Is, Acc)
- end;
-opt_1([I|Is], Acc) ->
- opt_1(Is, [I|Acc]);
-opt_1([], Acc) -> reverse(Acc).
-
-move_past_kill([{kill,Src}|_], {move,Src,_}, _) ->
- impossible;
-move_past_kill([{kill,_}=I|Is], Move, Acc) ->
- move_past_kill(Is, Move, [I|Acc]);
-move_past_kill([{trim,N,_}=I|Is], {move,Src,Dst}=Move, Acc) ->
- case Src of
- {y,Y} when Y < N-> impossible;
- {y,Y} -> {Is,[{move,{y,Y-N},Dst},I|Acc]};
- _ -> {Is,[Move,I|Acc]}
- end;
-move_past_kill(Is, Move, Acc) ->
- {Is,[Move|Acc]}.