File 1922-compiler-Remove-special-handling-for-NIFs-in-beam_ss.patch of Package erlang
From 08d2f64ada8e7fd55aec5022dcfe85b7930b7423 Mon Sep 17 00:00:00 2001
From: Frej Drejhammar <frej.drejhammar@gmail.com>
Date: Thu, 18 May 2023 11:35:00 +0200
Subject: [PATCH 2/2] compiler: Remove special handling for NIFs in
beam_ssa_opt-subpasses
The two beam_ssa_opt-subpasses beam_ssa_alias and
beam_ssa_private_append were prepared for gracefully handling
NIFs. With the new handling of NIFs introduced in
6f0fd83523847bc9e95558428c6f45b1db1080bc, this is no longer required
and the related code can be removed.
---
lib/compiler/src/beam_ssa_alias.erl | 25 +++-----------------
lib/compiler/src/beam_ssa_private_append.erl | 18 ++------------
2 files changed, 5 insertions(+), 38 deletions(-)
diff --git a/lib/compiler/src/beam_ssa_alias.erl b/lib/compiler/src/beam_ssa_alias.erl
index ec137f0ca8..c185f50a58 100644
--- a/lib/compiler/src/beam_ssa_alias.erl
+++ b/lib/compiler/src/beam_ssa_alias.erl
@@ -134,9 +134,8 @@ opt(StMap0, FuncDb0) ->
{StMap0, FuncDb0};
false ->
%% Ignore functions which are not in the function db (never
- %% called) or are stubs for nifs.
- Funs = [ F || F <- maps:keys(StMap0),
- is_map_key(F, FuncDb0), not is_nif(F, StMap0)],
+ %% called).
+ Funs = [ F || F <- maps:keys(StMap0), is_map_key(F, FuncDb0)],
Liveness = liveness(Funs, StMap0),
KillsMap = killsets(Liveness, StMap0),
@@ -176,19 +175,6 @@ liveness_make_cache([{Lbl,Blk}|Blocks], Cache0) ->
liveness_make_cache([], Cache) ->
Cache.
-%%%
-%%% Predicate to check if a function is the stub for a nif.
-%%%
--spec is_nif(func_id(), st_map()) -> boolean().
-
-is_nif(F, StMap) ->
- #opt_st{ssa=[{0,#b_blk{is=Is}}|_]} = map_get(F, StMap),
- case Is of
- [#b_set{op=nif_start}|_] ->
- true;
- _ -> false
- end.
-
%%%
%%% Calculate the killset for all functions in the liveness
%%% information.
@@ -768,9 +754,8 @@ aa_call(Dst, [#b_local{}=Callee|Args], Anno, SS0,
#aas{alias_map=AliasMap,st_map=StMap}=AAS0) ->
#b_local{name=#b_literal{val=_N},arity=_A} = Callee,
?DP("A Call~n callee: ~p/~p~n args: ~p~n", [_N, _A, Args]),
- IsNif = is_nif(Callee, StMap),
case AliasMap of
- #{Callee:=#{0:=CalleeSS}=Lbl2SS} when not IsNif ->
+ #{Callee:=#{0:=CalleeSS}=Lbl2SS} ->
?DP(" The callee is known~n"),
#opt_st{args=CalleeArgs} = map_get(Callee, StMap),
?DP(" callee args: ~p~n", [CalleeArgs]),
@@ -797,10 +782,6 @@ aa_call(Dst, [#b_local{}=Callee|Args], Anno, SS0,
ReturnStatusByType),
?DP(" result status: ~p~n", [ResultStatus]),
{aa_set_status(Dst, ResultStatus, SS), AAS};
- _ when IsNif ->
- %% This is a nif, assume that all arguments will be
- %% aliased and that the result is aliased.
- aa_set_aliased([Dst|Args], SS0);
#{} ->
%% We don't know anything about the function, don't change
%% the status of any variables
diff --git a/lib/compiler/src/beam_ssa_private_append.erl b/lib/compiler/src/beam_ssa_private_append.erl
index 9db25dc3fc..16a9fae874 100644
--- a/lib/compiler/src/beam_ssa_private_append.erl
+++ b/lib/compiler/src/beam_ssa_private_append.erl
@@ -57,9 +57,8 @@
-spec opt(st_map(), func_info_db()) -> {st_map(), func_info_db()}.
opt(StMap, FuncDb) ->
%% Ignore functions which are not in the function db (never
- %% called) or are stubs for nifs.
- Funs = [ F || F <- maps:keys(StMap),
- is_map_key(F, FuncDb), not is_nif(F, StMap)],
+ %% called).
+ Funs = [ F || F <- maps:keys(StMap), is_map_key(F, FuncDb)],
private_append(Funs, StMap, FuncDb).
private_append(Funs, StMap0, FuncDb) ->
@@ -636,16 +635,3 @@ insert_block_additions([Blk0={L,B=#b_blk{is=Is0}}|RevLinear],
insert_block_additions(RevLinear, Lbl2Addition, [Blk|Acc]);
insert_block_additions([], _, Acc) ->
Acc.
-
-%%%
-%%% Predicate to check if a function is the stub for a nif.
-%%%
--spec is_nif(func_id(), st_map()) -> boolean().
-
-is_nif(F, StMap) ->
- #opt_st{ssa=[{0,#b_blk{is=Is}}|_]} = map_get(F, StMap),
- case Is of
- [#b_set{op=nif_start}|_] ->
- true;
- _ -> false
- end.
--
2.35.3