Skip to content
Permalink
Browse files
Merge branch 'bjorn/compiler/ssa'
* bjorn/compiler/ssa:
  Travis CI: Run the SSA linter in the Linux64SmokeTest build
  Remove retired compiler passes
  Introduce a new SSA-based intermediate format
  hipe_beam_to_icode: Correct translation of get_map_elements
  beam_dead: Remove shortcut of binary matching instruction
  beam_bs: Remove optimizations that are easier done on SSA format
  Don't run unsafe compiler passes
  Simplify optimizations by introducing is_nil late
  beam_utils: Make is_tagged_tuple a pure test
  beam_except: Enhance recognition of function_clause exceptions
  beam_validator: Infer the types of copies in a smarter way
  beam_validator: Improve merge of cons and literal list
  beam_validator: Strengthen validation of func_info
  beam_validator: Allow get_tuple_element before dsetelement
  beam_validator: Don't transfer state to labels that can't be reached
  beam_validator: Improve type analysis for tuples
  beam_validator: Be more careful when updating try/catch state
  beam_trim: Handle an empty list of instructions
  v3_core: Number argument variables in ascending order
  Teach binary instructions to use Y registers as destination

OTP-14894
  • Loading branch information
bjorng committed Aug 24, 2018
2 parents 35979da + b3af7a2 commit 9facb02
Show file tree
Hide file tree
Showing 53 changed files with 10,703 additions and 6,595 deletions.
@@ -43,8 +43,8 @@ matrix:
- ./scripts/build-docker-otp 32 sh -c "scripts/build-otp release && ./otp_build tests && scripts/run-smoke-tests && bin/dialyzer --build_plt --apps erts kernel stdlib"
- env: Linux64SmokeTest
script:
- ./scripts/build-otp
- ./otp_build tests
- ERL_COMPILER_OPTIONS=ssalint ./scripts/build-otp
- ERL_COMPILER_OPTIONS=ssalint ./otp_build tests
- ./scripts/run-smoke-tests
- env: Linux64Docbuild
script:
@@ -1097,23 +1097,29 @@ i_bs_match_string x f W W
bs_get_integer2 Fail=f Ms=x Live=u Sz=sq Unit=u Flags=u Dst=d => \
gen_get_integer2(Fail, Ms, Live, Sz, Unit, Flags, Dst)

i_bs_get_integer_small_imm Ms Bits Fail Flags Y=y => \
i_bs_get_integer_small_imm Ms Bits Fail Flags x | move x Y

i_bs_get_integer_imm Ms Bits Live Fail Flags Y=y => \
i_bs_get_integer_imm Ms Bits Live Fail Flags x | move x Y

i_bs_get_integer_small_imm x W f? t x
i_bs_get_integer_imm x W t f? t x
i_bs_get_integer f? t t x s x
i_bs_get_integer_8 x f? x
i_bs_get_integer_16 x f? x
i_bs_get_integer f? t t x s xy
i_bs_get_integer_8 x f? xy
i_bs_get_integer_16 x f? xy

%if ARCH_64
i_bs_get_integer_32 x f? x
i_bs_get_integer_32 x f? xy
%endif

# Fetching binaries from binaries.
bs_get_binary2 Fail=f Ms=x Live=u Sz=sq Unit=u Flags=u Dst=d => \
gen_get_binary2(Fail, Ms, Live, Sz, Unit, Flags, Dst)

i_bs_get_binary_imm2 f? x t W t x
i_bs_get_binary2 f x t? s t x
i_bs_get_binary_all2 f? x t t x
i_bs_get_binary_imm2 f? x t W t xy
i_bs_get_binary2 f x t? s t xy
i_bs_get_binary_all2 f? x t t xy
i_bs_get_binary_all_reuse x f? t

# Fetching float from binaries.
@@ -1122,7 +1128,7 @@ bs_get_float2 Fail=f Ms=x Live=u Sz=s Unit=u Flags=u Dst=d => \

bs_get_float2 Fail=f Ms=x Live=u Sz=q Unit=u Flags=u Dst=d => jump Fail

i_bs_get_float2 f? x t s t x
i_bs_get_float2 f? x t s t xy

# Miscellanous

@@ -1156,14 +1162,14 @@ bs_context_to_binary x
# Utf8/utf16/utf32 support. (R12B-5)
#
bs_get_utf8 Fail=f Ms=x u u Dst=d => i_bs_get_utf8 Ms Fail Dst
i_bs_get_utf8 x f? x
i_bs_get_utf8 x f? xy

bs_skip_utf8 Fail=f Ms=x u u => i_bs_get_utf8 Ms Fail x

bs_get_utf16 Fail=f Ms=x u Flags=u Dst=d => i_bs_get_utf16 Ms Fail Flags Dst
bs_skip_utf16 Fail=f Ms=x u Flags=u => i_bs_get_utf16 Ms Fail Flags x

i_bs_get_utf16 x f? t x
i_bs_get_utf16 x f? t xy

bs_get_utf32 Fail=f Ms=x Live=u Flags=u Dst=d => \
bs_get_integer2 Fail Ms Live i=32 u=1 Flags Dst | \
@@ -1182,6 +1188,9 @@ i_bs_validate_unicode_retract j s S

bs_init2 Fail Sz Words Regs Flags Dst | binary_too_big(Sz) => system_limit Fail

bs_init2 Fail Sz Words Regs Flags Dst=y => \
bs_init2 Fail Sz Words Regs Flags x | move x Dst

bs_init2 Fail Sz=u Words=u==0 Regs Flags Dst => i_bs_init Sz Regs Dst

bs_init2 Fail Sz=u Words Regs Flags Dst => \
@@ -1202,6 +1211,8 @@ i_bs_init_heap W I t? x


bs_init_bits Fail Sz=o Words Regs Flags Dst => system_limit Fail
bs_init_bits Fail Sz Words Regs Flags Dst=y => \
bs_init_bits Fail Sz Words Regs Flags x | move x Dst

bs_init_bits Fail Sz=u Words=u==0 Regs Flags Dst => i_bs_init_bits Sz Regs Dst
bs_init_bits Fail Sz=u Words Regs Flags Dst => i_bs_init_bits_heap Sz Words Regs Dst
@@ -1230,7 +1241,7 @@ bs_private_append Fail Size Unit Bin Flags Dst => \

bs_init_writable

i_bs_append j? I t? t s x
i_bs_append j? I t? t s xy
i_bs_private_append j? t s S x

#
@@ -61,12 +61,17 @@ MODULES = \
beam_listing \
beam_opcodes \
beam_peep \
beam_receive \
beam_reorder \
beam_record \
beam_split \
beam_ssa \
beam_ssa_codegen \
beam_ssa_lint \
beam_ssa_opt \
beam_ssa_pp \
beam_ssa_pre_codegen \
beam_ssa_recv \
beam_ssa_type \
beam_kernel_to_ssa \
beam_trim \
beam_type \
beam_utils \
beam_validator \
beam_z \
@@ -90,7 +95,6 @@ MODULES = \
sys_core_fold_lists \
sys_core_inline \
sys_pre_attributes \
v3_codegen \
v3_core \
v3_kernel \
v3_kernel_pp
@@ -99,6 +103,7 @@ BEAM_H = $(wildcard ../priv/beam_h/*.h)

HRL_FILES= \
beam_disasm.hrl \
beam_ssa.hrl \
core_parse.hrl \
v3_kernel.hrl

@@ -185,7 +190,16 @@ release_docs_spec:
# ----------------------------------------------------

$(EBIN)/beam_disasm.beam: $(EGEN)/beam_opcodes.hrl beam_disasm.hrl
$(EBIN)/beam_listing.beam: core_parse.hrl v3_kernel.hrl
$(EBIN)/beam_listing.beam: core_parse.hrl v3_kernel.hrl beam_ssa.hrl
$(EBIN)/beam_kernel_to_ssa.beam: v3_kernel.hrl beam_ssa.hrl
$(EBIN)/beam_ssa.beam: beam_ssa.hrl
$(EBIN)/beam_ssa_codegen.beam: beam_ssa.hrl
$(EBIN)/beam_ssa_lint.beam: beam_ssa.hrl
$(EBIN)/beam_ssa_opt.beam: beam_ssa.hrl
$(EBIN)/beam_ssa_pp.beam: beam_ssa.hrl
$(EBIN)/beam_ssa_pre_codegen.beam: beam_ssa.hrl
$(EBIN)/beam_ssa_recv.beam: beam_ssa.hrl
$(EBIN)/beam_ssa_type.beam: beam_ssa.hrl
$(EBIN)/cerl.beam: core_parse.hrl
$(EBIN)/compile.beam: core_parse.hrl ../../stdlib/include/erl_compile.hrl
$(EBIN)/core_lib.beam: core_parse.hrl
@@ -197,7 +211,6 @@ $(EBIN)/sys_core_dsetel.beam: core_parse.hrl
$(EBIN)/sys_core_fold.beam: core_parse.hrl
$(EBIN)/sys_core_fold_lists.beam: core_parse.hrl
$(EBIN)/sys_core_inline.beam: core_parse.hrl
$(EBIN)/v3_codegen.beam: v3_kernel.hrl
$(EBIN)/v3_core.beam: core_parse.hrl
$(EBIN)/v3_kernel.beam: core_parse.hrl v3_kernel.hrl
$(EBIN)/v3_kernel_pp.beam: v3_kernel.hrl
@@ -39,8 +39,13 @@ function({function,Name,Arity,CLabel,Is0}) ->

%% Remove unusued labels for cleanliness and to help
%% optimization passes and HiPE.
Is = beam_jump:remove_unused_labels(Is1),
{function,Name,Arity,CLabel,Is}
Is2 = beam_jump:remove_unused_labels(Is1),

%% Some optimization passes can't handle consecutive labels.
%% Coalesce multiple consecutive labels.
Is = coalesce_consecutive_labels(Is2, [], []),

{function,Name,Arity,CLabel,Is}
catch
Class:Error:Stack ->
io:fwrite("Function: ~w/~w\n", [Name,Arity]),
@@ -113,10 +118,20 @@ rename_instr({put_map_exact,Fail,S,D,R,L}) ->
{put_map,Fail,exact,S,D,R,L};
rename_instr({test,has_map_fields,Fail,Src,{list,List}}) ->
{test,has_map_fields,Fail,[Src|List]};
rename_instr({test,is_nil,Fail,[Src]}) ->
{test,is_eq_exact,Fail,[Src,nil]};
rename_instr({select_val=I,Reg,Fail,{list,List}}) ->
{select,I,Reg,Fail,List};
rename_instr({select_tuple_arity=I,Reg,Fail,{list,List}}) ->
{select,I,Reg,Fail,List};
rename_instr(send) ->
{call_ext,2,send};
rename_instr(I) -> I.

coalesce_consecutive_labels([{label,L}=Lbl,{label,Alias}|Is], Replace, Acc) ->
coalesce_consecutive_labels([Lbl|Is], [{Alias,L}|Replace], Acc);
coalesce_consecutive_labels([I|Is], Replace, Acc) ->
coalesce_consecutive_labels(Is, Replace, [I|Acc]);
coalesce_consecutive_labels([], Replace, Acc) ->
D = maps:from_list(Replace),
beam_utils:replace_labels(Acc, [], D, fun(L) -> L end).

0 comments on commit 9facb02

Please sign in to comment.