File 3517-compiler-kernel_to_ssa-Collect-opaques-with-SSA-chec.patch of Package erlang
From 0341cdfca0dcff05b629c9e3c0ff77f4b6a593b3 Mon Sep 17 00:00:00 2001
From: Frej Drejhammar <frej.drejhammar@gmail.com>
Date: Wed, 30 Nov 2022 13:32:11 +0100
Subject: [PATCH 07/13] compiler: kernel_to_ssa: Collect opaques with SSA
checks
Collect opaques representing SSA checks, accumulate them in the main
codegen structure and output the checks as annotations on the
`b_function{}` they refer to.
---
lib/compiler/src/beam_kernel_to_ssa.erl | 14 +++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)
diff --git a/lib/compiler/src/beam_kernel_to_ssa.erl b/lib/compiler/src/beam_kernel_to_ssa.erl
index 52a68efbb6..a97db89ce6 100644
--- a/lib/compiler/src/beam_kernel_to_ssa.erl
+++ b/lib/compiler/src/beam_kernel_to_ssa.erl
@@ -42,7 +42,8 @@
recv=0 :: label(), %Receive label
ultimate_failure=0 :: label(), %Label for ultimate match failure.
labels=#{} :: #{atom() => label()},
- no_make_fun3=false :: boolean()
+ no_make_fun3=false :: boolean(),
+ checks=[] :: [term()]
}).
%% Internal records.
@@ -74,7 +75,12 @@ function(#k_fdef{anno=Anno0,func=Name,arity=Arity,
{As,St1} = new_ssa_vars(As0, St0),
{Asm,St} = cg_fun(Kb, St1),
Anno1 = line_anno(Anno0),
- Anno = Anno1#{func_info=>{Mod,Name,Arity}},
+ Anno2 = Anno1#{func_info=>{Mod,Name,Arity}},
+ Anno = case St#cg.checks of
+ [] -> Anno2;
+ Checks ->
+ Anno2#{ssa_checks=>Checks}
+ end,
#b_function{anno=Anno,args=As,bs=Asm,cnt=St#cg.lcount}
catch
Class:Error:Stack ->
@@ -157,7 +163,9 @@ cg(#k_goto{label=Label,args=As0}, #cg{labels=Labels}=St) ->
As = ssa_args(As0, St),
Branch = map_get(Label, Labels),
Break = #cg_break{args=As,phi=Branch},
- {[Break],St}.
+ {[Break],St};
+cg(#k_opaque{val={ssa_check_when,_,_,_,_}=Check},St) -> %% Extract here
+ {[],St#cg{checks=[Check|St#cg.checks]}}.
%% match_cg(Matc, [Ret], State) -> {[Ainstr],State}.
%% Generate code for a match.
--
2.35.3