Skip to content

Commit

Permalink
Merge pull request erlang#7240 from bjorng/bjorn/compiler/core-to-ssa
Browse files Browse the repository at this point in the history
compiler: Eliminate the Kernel Erlang intermediate representation
bjorng authored May 26, 2023
2 parents f273011 + 83d41bb commit 718a323
Showing 28 changed files with 3,382 additions and 4,459 deletions.
34 changes: 12 additions & 22 deletions lib/compiler/internal_doc/beam_ssa.md
Original file line number Diff line number Diff line change
@@ -123,28 +123,18 @@ apply:
Variable Naming
---------------

A variable name in BEAM SSA is either an atom, a non-negative integer
or a tuple: `atom() | non_neg_integer() | {atom() | non_neg_integer(),
non_neg_integer()}`. In order to generate fresh unused variable names,
all compiler transforms maintain a counter, the `cnt`-field in the
`opt_st`-record, which is incremented each time a new variable or
label is created. In the following description the value of the
`cnt`-field is called `Cnt`.

Due to peculiarities in the BEAM SSA code generator, a compiler
transformation unfortunately cannot just use the `cnt`-value directly
as a fresh name. There are three basic strategies for creating fresh
variable names which can by used by a compiler pass:
A variable name in BEAM SSA is either an atom or a non-negative
integer:

1) A name can be derived from an existing name of the form `V ::
atom() | non_neg_integer()` by selecting an atom, which is unique to
the compiler pass, to form a new name `{A, V}`. The same `A` cannot
be used by strategy 3) below.
atom() | non_neg_integer()

2) A name can be derived from an existing name of the form `V ::
non_neg_integer()` by combining it with the `cnt`-field into `{V,
Cnt}`.
In order to generate fresh unused variable names, all compiler
transforms maintain a counter, the `cnt`-field in the `b_function` and
`opt_st` records, which is incremented each time a new variable or
label is created. In the following description the value of the
`cnt`-field is called `Cnt`. The `Cnt` value is guaranteed to never
clash with a previously defined variable name. Therefore, value of
`Cnt` can directly be used as a variable name in the SSA passes.

3) A fresh name can be created by selecting an atom `A`, which is
unique to the compiler pass, to form the new name `{A, Cnt}`. The
same `A` cannot be used by strategy 1) above.
Note that the rules were more complicated before Erlang/OTP 27, because
the `Cnt` value could clash with other variables.
17 changes: 6 additions & 11 deletions lib/compiler/src/Makefile
Original file line number Diff line number Diff line change
@@ -51,6 +51,7 @@ MODULES = \
beam_bounds \
beam_block \
beam_call_types \
beam_core_to_ssa \
beam_clean \
beam_dict \
beam_digraph \
@@ -76,7 +77,6 @@ MODULES = \
beam_ssa_share \
beam_ssa_throw \
beam_ssa_type \
beam_kernel_to_ssa \
beam_trim \
beam_types \
beam_utils \
@@ -102,9 +102,7 @@ MODULES = \
sys_core_prepare \
sys_messages \
sys_pre_attributes \
v3_core \
v3_kernel \
v3_kernel_pp
v3_core

BEAM_H = $(wildcard ../priv/beam_h/*.h)

@@ -114,8 +112,7 @@ HRL_FILES= \
beam_ssa_opt.hrl \
beam_ssa.hrl \
beam_types.hrl \
core_parse.hrl \
v3_kernel.hrl
core_parse.hrl

YRL_FILE = core_parse.yrl

@@ -206,14 +203,14 @@ release_docs_spec:

$(EBIN)/beam_a.beam: beam_asm.hrl beam_types.hrl
$(EBIN)/beam_asm.beam: beam_asm.hrl $(EGEN)/beam_opcodes.hrl beam_types.hrl
$(EBIN)/beam_call_types.beam: beam_types.hrl
$(EBIN)/beam_block.beam: beam_asm.hrl
$(EBIN)/beam_call_types.beam: beam_types.hrl
$(EBIN)/beam_core_to_ssa.beam: core_parse.hrl beam_ssa.hrl
$(EBIN)/beam_dict.beam: beam_types.hrl
$(EBIN)/beam_disasm.beam: $(EGEN)/beam_opcodes.hrl beam_disasm.hrl \
beam_asm.hrl beam_types.hrl
$(EBIN)/beam_jump.beam: beam_asm.hrl
$(EBIN)/beam_kernel_to_ssa.beam: v3_kernel.hrl beam_ssa.hrl
$(EBIN)/beam_listing.beam: core_parse.hrl v3_kernel.hrl beam_ssa.hrl \
$(EBIN)/beam_listing.beam: core_parse.hrl beam_ssa.hrl \
beam_asm.hrl beam_types.hrl
$(EBIN)/beam_ssa.beam: beam_ssa.hrl
$(EBIN)/beam_ssa_alias_opt.beam: beam_ssa_opt.hrl beam_types.hrl
@@ -245,5 +242,3 @@ $(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_core.beam: core_parse.hrl
$(EBIN)/v3_kernel.beam: core_parse.hrl v3_kernel.hrl
$(EBIN)/v3_kernel_pp.beam: v3_kernel.hrl
Loading
Oops, something went wrong.

0 comments on commit 718a323

Please sign in to comment.