diff options
author | Björn Gustavsson <[email protected]> | 2018-11-28 11:53:43 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2018-11-28 11:53:43 +0100 |
commit | 489b5eddf4b9b432e4e854bad603bb7d1d5678dc (patch) | |
tree | 325f9d30635d34257bd8e7d199e381705da549fe /lib/compiler/src/beam_ssa_opt.erl | |
parent | da90cf437e07f0f21b15e0d0ea8ff38cbc0bb1ea (diff) | |
parent | 96ac99d3e9b12295b7e8a70888fd1134a78e63a8 (diff) | |
download | otp-489b5eddf4b9b432e4e854bad603bb7d1d5678dc.tar.gz otp-489b5eddf4b9b432e4e854bad603bb7d1d5678dc.tar.bz2 otp-489b5eddf4b9b432e4e854bad603bb7d1d5678dc.zip |
Merge pull request #2033 from bjorng/bjorn/compiler/sharing
Add a code sharing optimization pass
Diffstat (limited to 'lib/compiler/src/beam_ssa_opt.erl')
-rw-r--r-- | lib/compiler/src/beam_ssa_opt.erl | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/lib/compiler/src/beam_ssa_opt.erl b/lib/compiler/src/beam_ssa_opt.erl index ac2d943fef..2dda67eac6 100644 --- a/lib/compiler/src/beam_ssa_opt.erl +++ b/lib/compiler/src/beam_ssa_opt.erl @@ -22,7 +22,8 @@ -export([module/2]). -include("beam_ssa.hrl"). --import(lists, [all/2,append/1,foldl/3,keyfind/3,member/2,reverse/1,reverse/2, +-import(lists, [all/2,append/1,foldl/3,keyfind/3,member/2, + reverse/1,reverse/2, splitwith/2,takewhile/2,unzip/1]). -spec module(beam_ssa:b_module(), [compile:option()]) -> @@ -787,15 +788,20 @@ float_flush_regs(#fs{regs=Rs}) -> %%% with a cheaper instructions %%% -ssa_opt_live(#st{ssa=Linear}=St) -> - St#st{ssa=live_opt(reverse(Linear), #{}, [])}. +ssa_opt_live(#st{ssa=Linear0}=St) -> + RevLinear = reverse(Linear0), + Blocks0 = maps:from_list(RevLinear), + Blocks = live_opt(RevLinear, #{}, Blocks0), + Linear = beam_ssa:linearize(Blocks), + St#st{ssa=Linear}. -live_opt([{L,Blk0}|Bs], LiveMap0, Acc) -> - Successors = beam_ssa:successors(Blk0), +live_opt([{L,Blk0}|Bs], LiveMap0, Blocks) -> + Blk1 = beam_ssa_share:block(Blk0, Blocks), + Successors = beam_ssa:successors(Blk1), Live0 = live_opt_succ(Successors, L, LiveMap0), - {Blk,Live} = live_opt_blk(Blk0, Live0), + {Blk,Live} = live_opt_blk(Blk1, Live0), LiveMap = live_opt_phis(Blk#b_blk.is, L, Live, LiveMap0), - live_opt(Bs, LiveMap, [{L,Blk}|Acc]); + live_opt(Bs, LiveMap, Blocks#{L:=Blk}); live_opt([], _, Acc) -> Acc. live_opt_succ([S|Ss], L, LiveMap) -> |