diff options
author | Björn Gustavsson <[email protected]> | 2018-10-04 10:01:17 +0200 |
---|---|---|
committer | Björn Gustavsson <[email protected]> | 2018-10-04 10:01:17 +0200 |
commit | f862407dfe09b9ca4a505c1d2dc562b1a67dea69 (patch) | |
tree | 34d560601afb573f207bc508f6b60fc9831b70bb /lib/compiler/src | |
parent | a4c2d2389e09273e3d9509c592dc01d5260e112a (diff) | |
parent | a8c669b57ebb2f63794a57a57c21b3dbbea7882e (diff) | |
download | otp-f862407dfe09b9ca4a505c1d2dc562b1a67dea69.tar.gz otp-f862407dfe09b9ca4a505c1d2dc562b1a67dea69.tar.bz2 otp-f862407dfe09b9ca4a505c1d2dc562b1a67dea69.zip |
Merge branch 'bjorn/compiler/misc-fixes'
* bjorn/compiler/misc-fixes:
beam_ssa: Remove unnecessary beam_ssa: prefixes
beam_ssa_bsm: Fix replacement of variables in a remote call
Diffstat (limited to 'lib/compiler/src')
-rw-r--r-- | lib/compiler/src/beam_ssa.erl | 18 | ||||
-rw-r--r-- | lib/compiler/src/beam_ssa_bsm.erl | 22 |
2 files changed, 28 insertions, 12 deletions
diff --git a/lib/compiler/src/beam_ssa.erl b/lib/compiler/src/beam_ssa.erl index a71802cf80..c5e23d2ae0 100644 --- a/lib/compiler/src/beam_ssa.erl +++ b/lib/compiler/src/beam_ssa.erl @@ -579,11 +579,11 @@ used(_) -> []. -spec definitions(Blocks :: block_map()) -> definition_map(). definitions(Blocks) -> - beam_ssa:fold_instrs_rpo(fun(#b_set{ dst = Var }=I, Acc) -> - maps:put(Var, I, Acc); - (_Terminator, Acc) -> - Acc - end, [0], #{}, Blocks). + fold_instrs_rpo(fun(#b_set{ dst = Var }=I, Acc) -> + maps:put(Var, I, Acc); + (_Terminator, Acc) -> + Acc + end, [0], #{}, Blocks). -spec uses(Blocks :: block_map()) -> usage_map(). uses(Blocks) -> @@ -593,7 +593,7 @@ uses(Blocks) -> From :: [label()], Blocks :: block_map(). uses(From, Blocks) -> - beam_ssa:fold_rpo(fun fold_uses_block/3, From, #{}, Blocks). + fold_rpo(fun fold_uses_block/3, From, #{}, Blocks). fold_uses_block(Lbl, #b_blk{is=Is,last=Last}, UseMap0) -> F = fun(I, UseMap) -> @@ -601,7 +601,7 @@ fold_uses_block(Lbl, #b_blk{is=Is,last=Last}, UseMap0) -> Uses0 = maps:get(Var, Acc, []), Uses = [{Lbl, I} | Uses0], maps:put(Var, Uses, Acc) - end, UseMap, beam_ssa:used(I)) + end, UseMap, used(I)) end, F(Last, foldl(F, UseMap0, Is)). @@ -798,8 +798,8 @@ split_blocks_1([L|Ls], P, Blocks0, Count0) -> BefBlk = Blk#b_blk{is=Bef,last=Br}, NewBlk = Blk#b_blk{is=Aft}, Blocks1 = Blocks0#{L:=BefBlk,NewLbl=>NewBlk}, - Successors = beam_ssa:successors(NewBlk), - Blocks = beam_ssa:update_phi_labels(Successors, L, NewLbl, Blocks1), + Successors = successors(NewBlk), + Blocks = update_phi_labels(Successors, L, NewLbl, Blocks1), split_blocks_1([NewLbl|Ls], P, Blocks, Count); no -> split_blocks_1(Ls, P, Blocks0, Count0) diff --git a/lib/compiler/src/beam_ssa_bsm.erl b/lib/compiler/src/beam_ssa_bsm.erl index 2efeb6b5b6..9631bf3334 100644 --- a/lib/compiler/src/beam_ssa_bsm.erl +++ b/lib/compiler/src/beam_ssa_bsm.erl @@ -354,6 +354,11 @@ amb_get_alias(#b_var{}=Arg, Lbl, State) -> error -> {Arg, State} end; +amb_get_alias(#b_remote{mod=Mod0,name=Name0}=Arg0, Lbl, State0) -> + {Mod, State1} = amb_get_alias(Mod0, Lbl, State0), + {Name, State} = amb_get_alias(Name0, Lbl, State1), + Arg = Arg0#b_remote{mod=Mod,name=Name}, + {Arg, State}; amb_get_alias(Arg, _Lbl, State) -> {Arg, State}. @@ -391,15 +396,22 @@ amb_insert_promotions(Blocks0, State) -> Block = maps:get(Lbl, Blocks), Alias = Promotion#b_set.dst, - {Before, After} = splitwith(fun(#b_set{args=Args}) -> - not member(Alias, Args) - end, Block#b_blk.is), + {Before, After} = splitwith( + fun(#b_set{args=Args}) -> + not is_var_in_args(Alias, Args) + end, Block#b_blk.is), Is = Before ++ [Promotion | After], maps:put(Lbl, Block#b_blk{is=Is}, Blocks) end, maps:fold(F, Blocks0, State#amb.promotions). +is_var_in_args(Var, [Var | _]) -> true; +is_var_in_args(Var, [#b_remote{name=Var} | _]) -> true; +is_var_in_args(Var, [#b_remote{mod=Var} | _]) -> true; +is_var_in_args(Var, [_ | Args]) -> is_var_in_args(Var, Args); +is_var_in_args(_Var, []) -> false. + %%% %%% Subpasses %%% @@ -732,6 +744,10 @@ aca_cs_args([Arg | Args], VRs) -> aca_cs_args([], _VRs) -> []. +aca_cs_arg(#b_remote{mod=Mod0,name=Name0}=Rem, VRs) -> + Mod = aca_cs_arg(Mod0, VRs), + Name = aca_cs_arg(Name0, VRs), + Rem#b_remote{mod=Mod,name=Name}; aca_cs_arg(Arg, VRs) -> case VRs of #{ Arg := New } -> New; |