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 9facb02b91979ef90b47ac0a54d1eb71fdaa1ee1
Showing with 10,703 additions and 6,595 deletions.
  1. +2 −2 .travis.yml
  2. +22 −11 erts/emulator/beam/ops.tab
  3. +20 −7 lib/compiler/src/Makefile
  4. +17 −2 lib/compiler/src/beam_a.erl
  5. +10 −578 lib/compiler/src/beam_block.erl
  6. +22 −119 lib/compiler/src/beam_bs.erl
  7. +4 −158 lib/compiler/src/beam_clean.erl
  8. +18 −108 lib/compiler/src/beam_dead.erl
  9. +38 −15 lib/compiler/src/beam_except.erl
  10. +3 −1 lib/compiler/src/beam_flatten.erl
  11. +6 −0 lib/compiler/src/beam_jump.erl
  12. +1,330 −0 lib/compiler/src/beam_kernel_to_ssa.erl
  13. +7 −0 lib/compiler/src/beam_listing.erl
  14. +55 −14 lib/compiler/src/beam_peep.erl
  15. +0 −416 lib/compiler/src/beam_receive.erl
  16. +0 −131 lib/compiler/src/beam_record.erl
  17. +0 −150 lib/compiler/src/beam_reorder.erl
  18. +0 −4 lib/compiler/src/beam_split.erl
  19. +616 −0 lib/compiler/src/beam_ssa.erl
  20. +66 −0 lib/compiler/src/beam_ssa.hrl
  21. +1,827 −0 lib/compiler/src/beam_ssa_codegen.erl
  22. +349 −0 lib/compiler/src/beam_ssa_lint.erl
  23. +1,307 −0 lib/compiler/src/beam_ssa_opt.erl
  24. +238 −0 lib/compiler/src/beam_ssa_pp.erl
  25. +2,437 −0 lib/compiler/src/beam_ssa_pre_codegen.erl
  26. +281 −0 lib/compiler/src/beam_ssa_recv.erl
  27. +1,106 −0 lib/compiler/src/beam_ssa_type.erl
  28. +1 −1 lib/compiler/src/beam_trim.erl
  29. +0 −1,117 lib/compiler/src/beam_type.erl
  30. +5 −565 lib/compiler/src/beam_utils.erl
  31. +228 −73 lib/compiler/src/beam_validator.erl
  32. +2 −0 lib/compiler/src/beam_z.erl
  33. +104 −32 lib/compiler/src/compile.erl
  34. +9 −5 lib/compiler/src/compiler.app.src
  35. +0 −2,925 lib/compiler/src/v3_codegen.erl
  36. +2 −1 lib/compiler/src/v3_core.erl
  37. +3 −8 lib/compiler/src/v3_kernel.erl
  38. +1 −1 lib/compiler/src/v3_kernel.hrl
  39. +6 −2 lib/compiler/test/Makefile
  40. +290 −0 lib/compiler/test/beam_ssa_SUITE.erl
  41. +52 −2 lib/compiler/test/beam_type_SUITE.erl
  42. +44 −0 lib/compiler/test/bs_match_SUITE.erl
  43. +3 −3 lib/compiler/test/compilation_SUITE.erl
  44. +13 −15 lib/compiler/test/compile_SUITE.erl
  45. +1 −1 lib/compiler/test/core_fold_SUITE.erl
  46. +15 −0 lib/compiler/test/guard_SUITE.erl
  47. +7 −5 lib/compiler/test/inline_SUITE.erl
  48. +51 −46 lib/compiler/test/misc_SUITE.erl
  49. +38 −0 lib/compiler/test/receive_SUITE_data/ref_opt/no_5.erl
  50. +0 −71 lib/compiler/test/receive_SUITE_data/ref_opt/yes_14.S
  51. +27 −0 lib/compiler/test/receive_SUITE_data/ref_opt/yes_14.erl
  52. +3 −5 lib/compiler/test/test_lib.erl
  53. +17 −1 lib/hipe/icode/hipe_beam_to_icode.erl
View
@@ -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:
View
@@ -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
#
View
@@ -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).
Oops, something went wrong.

0 comments on commit 9facb02

Please sign in to comment.