Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upIntroduce a new SSA-based intermediate format for the compiler #1935
Conversation
bjorng
added some commits
Mar 12, 2018
bjorng
added
team:VM
enhancement
labels
Aug 17, 2018
bjorng
self-assigned this
Aug 17, 2018
| @@ -110,6 +110,8 @@ undo_rename({test,has_map_fields,Fail,[Src|List]}) -> | ||
| {test,has_map_fields,Fail,Src,{list,List}}; | ||
| undo_rename({get_map_elements,Fail,Src,{list,List}}) -> | ||
| {get_map_elements,Fail,Src,{list,List}}; | ||
| undo_rename({test,is_eq_exact,Fail,[Src,nil]}) -> | ||
| {test,is_nil,Fail,[Src]}; |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
michalmuskala
Aug 17, 2018
Contributor
Is it possible the nil value will be the first argument? If so, I think this should cover both cases.
The previous code in bif_to_test would convert all [] == X, [] =:= X, X == [], and X =:= [] to the is_nil instruction.
michalmuskala
Aug 17, 2018
Contributor
Is it possible the nil value will be the first argument? If so, I think this should cover both cases.
The previous code in bif_to_test would convert all [] == X, [] =:= X, X == [], and X =:= [] to the is_nil instruction.
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
bjorng
Aug 19, 2018
Contributor
Is it possible the
nilvalue will be the first argument?
No, that should not be possible.
There is this clause in beam_utils:bif_to_test/3 that places any literal argument in the second position:
bif_to_test('=:=', [C,A], Fail) when ?is_const(C) ->
{test,is_eq_exact,Fail,[A,C]};
Here is the definition of is_const:
-define(is_const(Val), (Val =:= nil orelse
element(1, Val) =:= integer orelse
element(1, Val) =:= float orelse
element(1, Val) =:= atom orelse
element(1, Val) =:= literal)).
bjorng
Aug 19, 2018
Contributor
Is it possible the
nilvalue will be the first argument?
No, that should not be possible.
There is this clause in beam_utils:bif_to_test/3 that places any literal argument in the second position:
bif_to_test('=:=', [C,A], Fail) when ?is_const(C) ->
{test,is_eq_exact,Fail,[A,C]};
Here is the definition of is_const:
-define(is_const(Val), (Val =:= nil orelse
element(1, Val) =:= integer orelse
element(1, Val) =:= float orelse
element(1, Val) =:= atom orelse
element(1, Val) =:= literal)).
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
bjorng
added some commits
Feb 1, 2018
bjorng
merged commit b3af7a2
into
erlang:master
Aug 24, 2018
bjorng
deleted the
bjorng:bjorn/compiler/ssa
branch
Aug 24, 2018
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
josevalim
Aug 29, 2018
Contributor
Hi @bjorng! This looks very interesting, happy to see it merged! Are there any existing passes that you suspect that it could be cleaner (i.e. less lines of code) or more efficient (i.e. applies in more cases) if moved to SSA? If so, I would love to explore it, as a way to get more familiar with how SSA works. Thanks!
|
Hi @bjorng! This looks very interesting, happy to see it merged! Are there any existing passes that you suspect that it could be cleaner (i.e. less lines of code) or more efficient (i.e. applies in more cases) if moved to SSA? If so, I would love to explore it, as a way to get more familiar with how SSA works. Thanks! |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
bjorng
Aug 29, 2018
Contributor
Here are some passes that I think could benefit from SSA:
sys_core_dsetel. Could be an easy way to get started with SSA. You could also implement #1890.
The sub pass v3_kernel:guard_opt/2.
beam_trim. This probably has to be implemented as a sub pass of ssa_codegen or ssa_pre_codegen.
The minor optimizations in beam_flatten. They probably have to be done in beam_ssa_codegen.
Optimization of #b_switch{} branches. If two branches jumps to code blocks that do the same thing, let both branches jump to the same block. beam_jump does this kind of optimization, but doing it earlier in the SSA format could speed up compilation of function with many clauses.
Getting rid of the call to beam_utils:is_killed/3 in beam_jump (in some way to be determined). We want to remove beam_utils:is_killed().
A pass I am not sure about is beam_bs. We could possibly gain some compilation speed by rewriting it in SSA. Could also be a good project for getting started with SSA.
I am currently working on a replacement for beam_dead. John is working on a replacement for beam_bsm.
|
Here are some passes that I think could benefit from SSA:
The sub pass
The minor optimizations in Optimization of Getting rid of the call to A pass I am not sure about is I am currently working on a replacement for |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
josevalim
Aug 29, 2018
Contributor
Thanks! I will let you know when I get started with any those (possibly the dsetel one) to make sure there is no work duplication.
|
Thanks! I will let you know when I get started with any those (possibly the dsetel one) to make sure there is no work duplication. |
bjorng commentedAug 17, 2018
•
edited
Edited 1 time
-
bjorng
edited Aug 17, 2018 (most recent)
-
bjorng
created Aug 17, 2018
This pull request introduces a Static Single Assignment (SSA) format as a new intermediate format in the compiler. The code generator as well as several optimization passes has been completely rewritten.
It is easier to write many kind optimizations for new SSA-based intermediate format than for the BEAM assembly language. We plan to introduce significantly improved optimizations of binary matching later this year.
For more details about the new compiler passes, see the individual commit messagges in this branch (especially "Introduce a new SSA-based intermediate format").
We hope to merge this pull request in one or two weeks. We'll try to fix any major bugs (compiler crashes or incorrectly generated code) before merging.