summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrej Drejhammar <frej.drejhammar@gmail.com>2022-10-07 12:00:14 +0200
committerFrej Drejhammar <frej.drejhammar@gmail.com>2023-02-10 10:57:05 +0100
commit56eeb2852b52da284faf60d133a4efa0e04de921 (patch)
treec010107a8b8e672700304604385b62db07d3d451
parent9ce6a2e7974af49793715b54e41e05d11d8b707f (diff)
downloaderlang-56eeb2852b52da284faf60d133a4efa0e04de921.tar.gz
compiler: alias 1/4: Introduce alias analysis pass
This commit inserts an empty analysis pass which will eventually be extended to do a full alias analysis.
-rw-r--r--lib/compiler/src/Makefile2
-rw-r--r--lib/compiler/src/beam_ssa_alias.erl45
-rw-r--r--lib/compiler/src/beam_ssa_opt.erl19
-rw-r--r--lib/compiler/src/compile.erl1
-rw-r--r--lib/compiler/src/compiler.app.src1
5 files changed, 64 insertions, 4 deletions
diff --git a/lib/compiler/src/Makefile b/lib/compiler/src/Makefile
index 50a3dbd339..645a1de589 100644
--- a/lib/compiler/src/Makefile
+++ b/lib/compiler/src/Makefile
@@ -60,6 +60,7 @@ MODULES = \
beam_listing \
beam_opcodes \
beam_ssa \
+ beam_ssa_alias \
beam_ssa_bc_size \
beam_ssa_bool \
beam_ssa_bsm \
@@ -212,6 +213,7 @@ $(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 \
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
$(EBIN)/beam_ssa_bsm.beam: beam_ssa.hrl
$(EBIN)/beam_ssa_bool.beam: beam_ssa.hrl
$(EBIN)/beam_ssa_check.beam: beam_ssa.hrl beam_types.hrl
diff --git a/lib/compiler/src/beam_ssa_alias.erl b/lib/compiler/src/beam_ssa_alias.erl
new file mode 100644
index 0000000000..1fc73c1828
--- /dev/null
+++ b/lib/compiler/src/beam_ssa_alias.erl
@@ -0,0 +1,45 @@
+%%
+%% %CopyrightBegin%
+%%
+%% Copyright Ericsson AB 2023. All Rights Reserved.
+%%
+%% Licensed under the Apache License, Version 2.0 (the "License");
+%% you may not use this file except in compliance with the License.
+%% You may obtain a copy of the License at
+%%
+%% http://www.apache.org/licenses/LICENSE-2.0
+%%
+%% Unless required by applicable law or agreed to in writing, software
+%% distributed under the License is distributed on an "AS IS" BASIS,
+%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+%% See the License for the specific language governing permissions and
+%% limitations under the License.
+%%
+%% %CopyrightEnd%
+%%
+%%
+
+-module(beam_ssa_alias).
+
+-export([opt/2]).
+
+-include("beam_ssa_opt.hrl").
+
+%% -define(DEBUG, true).
+
+-ifdef(DEBUG).
+-define(DP(FMT, ARGS), io:format(FMT, ARGS)).
+-define(DP(FMT), io:format(FMT)).
+-else.
+-define(DP(FMT, ARGS), skip).
+-define(DP(FMT), skip).
+-endif.
+
+%%%
+%%% Optimization pass which calculates the alias status of values and
+%%% uses the results to transform the code.
+%%%
+-spec opt(st_map(), func_info_db()) -> {st_map(), func_info_db()}.
+
+opt(StMap0, FuncDb0) ->
+ {StMap0, FuncDb0}.
diff --git a/lib/compiler/src/beam_ssa_opt.erl b/lib/compiler/src/beam_ssa_opt.erl
index 1d6a45dbe7..97032e0f0a 100644
--- a/lib/compiler/src/beam_ssa_opt.erl
+++ b/lib/compiler/src/beam_ssa_opt.erl
@@ -64,7 +64,9 @@ module(Module, Opts) ->
Phases = [{once, Order, prologue_passes(Opts)},
{module, module_passes(Opts)},
{fixpoint, Order, repeated_passes(Opts)},
- {once, Order, epilogue_passes(Opts)}],
+ {once, Order, early_epilogue_passes(Opts)},
+ {module, epilogue_module_passes(Opts)},
+ {once, Order, late_epilogue_passes(Opts)}],
StMap = run_phases(Phases, StMap0, FuncDb),
{ok, finish(Module, StMap)}.
@@ -276,12 +278,21 @@ repeated_passes(Opts) ->
%clean up phi nodes.
passes_1(Ps, Opts).
-epilogue_passes(Opts) ->
+epilogue_module_passes(Opts) ->
+ Ps0 = [{ssa_opt_alias,
+ fun({StMap, FuncDb}) ->
+ beam_ssa_alias:opt(StMap, FuncDb)
+ end}],
+ passes_1(Ps0, Opts).
+
+early_epilogue_passes(Opts) ->
Ps = [?PASS(ssa_opt_type_finish),
?PASS(ssa_opt_float),
- ?PASS(ssa_opt_sw),
+ ?PASS(ssa_opt_sw)],
+ passes_1(Ps, Opts).
- %% Run live one more time to clean up after the previous
+late_epilogue_passes(Opts) ->
+ Ps = [%% Run live one more time to clean up after the previous
%% epilogue passes.
?PASS(ssa_opt_live),
?PASS(ssa_opt_bsm),
diff --git a/lib/compiler/src/compile.erl b/lib/compiler/src/compile.erl
index 06ab3c5345..feb65dacb9 100644
--- a/lib/compiler/src/compile.erl
+++ b/lib/compiler/src/compile.erl
@@ -2101,6 +2101,7 @@ pre_load() ->
beam_kernel_to_ssa,
beam_opcodes,
beam_ssa,
+ beam_ssa_alias,
beam_ssa_bc_size,
beam_ssa_bool,
beam_ssa_bsm,
diff --git a/lib/compiler/src/compiler.app.src b/lib/compiler/src/compiler.app.src
index b95c8d52d3..15de283706 100644
--- a/lib/compiler/src/compiler.app.src
+++ b/lib/compiler/src/compiler.app.src
@@ -36,6 +36,7 @@
beam_listing,
beam_opcodes,
beam_ssa,
+ beam_ssa_alias,
beam_ssa_bc_size,
beam_ssa_bool,
beam_ssa_bsm,