Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
bjorng committed Nov 7, 2024
1 parent 9b41d4f commit 42a53eb
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 73 deletions.
10 changes: 5 additions & 5 deletions erts/emulator/beam/bif.tab
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ ubif erlang:abs/1
bif erlang:adler32/1
bif erlang:adler32/2
bif erlang:adler32_combine/3
pbif erlang:atom_to_list/1
bif erlang:atom_to_list/1
bif erlang:binary_to_list/1
bif erlang:binary_to_list/3
bif erlang:binary_to_term/1
Expand Down Expand Up @@ -87,7 +87,7 @@ ubif erlang:hd/1
bif erlang:integer_to_list/1
ubif erlang:length/1
bif erlang:link/1
bif erlang:list_to_atom/1
pbif erlang:list_to_atom/1
bif erlang:list_to_binary/1
bif erlang:list_to_float/1
bif erlang:list_to_pid/1
Expand Down Expand Up @@ -481,7 +481,7 @@ bif string:list_to_float/1
bif erlang:make_fun/3
bif erlang:iolist_size/1
bif erlang:iolist_to_binary/1
bif erlang:list_to_existing_atom/1
pbif erlang:list_to_existing_atom/1

#
# New Bifs in R12B-0
Expand Down Expand Up @@ -513,8 +513,8 @@ bif unicode:bin_is_7bit/1
# New Bifs in R13A.
#
bif erlang:atom_to_binary/2
bif erlang:binary_to_atom/2
bif erlang:binary_to_existing_atom/2
pbif erlang:binary_to_atom/2
pbif erlang:binary_to_existing_atom/2
bif net_kernel:dflag_unicode_io/1
#
# New Bifs in R13B-1
Expand Down
2 changes: 1 addition & 1 deletion erts/emulator/beam/jit/arm/beam_asm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1305,7 +1305,7 @@ class BeamModuleAssembler : public BeamAssembler,

void emit_validate_unicode(Label next, Label fail, a64::Gp value);

void ubif_comment(const ArgWord &Bif);
void ubif_comment(const ArgWord &Bif, const ArgExport &Exp);

void emit_cmp_immed_to_bool(arm::CondCode cc,
const ArgSource &LHS,
Expand Down
78 changes: 50 additions & 28 deletions erts/emulator/beam/jit/arm/instr_bif.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,28 @@ extern "C"
#include "erl_msacc.h"
}

void BeamModuleAssembler::ubif_comment(const ArgWord &Bif) {
void BeamModuleAssembler::ubif_comment(const ArgWord &Bif,
const ArgExport &Exp) {
if (logger.file()) {
ErtsCodeMFA *mfa = ubif2mfa((void *)Bif.get());
if (mfa) {
comment("UBIF: %T/%d", mfa->function, mfa->arity);
BeamFile_ImportEntry *import;
const Export *exp;
bool is_pure;

import = &beam->imports.entries[Exp.val];
exp = erts_active_export_entry(import->module,
import->function,
import->arity);

is_pure = exp->bif_number != -1 &&
bif_table[exp->bif_number].kind == BIF_KIND_PURE;

if (is_pure) {
comment("fake UBIF: %T:%T/%d", import->module, import->function, import->arity);
} else {
ErtsCodeMFA *mfa = ubif2mfa((void *)Bif.get());
if (mfa) {
comment("UBIF: %T/%d", mfa->function, mfa->arity);
}
}
}
}
Expand Down Expand Up @@ -108,25 +125,27 @@ void BeamGlobalAssembler::emit_i_bif_body_shared() {
void BeamModuleAssembler::emit_i_bif1(const ArgSource &Src1,
const ArgLabel &Fail,
const ArgWord &Bif,
const ArgExport &Exp,
const ArgRegister &Dst) {
auto src1 = load_source(Src1);

a.str(src1.reg, getXRef(0));

ubif_comment(Bif);
ubif_comment(Bif, Exp);
emit_i_bif(Fail, Bif, Dst);
}

void BeamModuleAssembler::emit_i_bif2(const ArgSource &Src1,
const ArgSource &Src2,
const ArgLabel &Fail,
const ArgWord &Bif,
const ArgExport &Exp,
const ArgRegister &Dst) {
auto [src1, src2] = load_sources(Src1, TMP1, Src2, TMP2);

a.stp(src1.reg, src2.reg, getXRef(0));

ubif_comment(Bif);
ubif_comment(Bif, Exp);
emit_i_bif(Fail, Bif, Dst);
}

Expand All @@ -135,14 +154,15 @@ void BeamModuleAssembler::emit_i_bif3(const ArgSource &Src1,
const ArgSource &Src3,
const ArgLabel &Fail,
const ArgWord &Bif,
const ArgExport &Exp,
const ArgRegister &Dst) {
auto [src1, src2] = load_sources(Src1, TMP1, Src2, TMP2);
auto src3 = load_source(Src3, TMP3);

a.stp(src1.reg, src2.reg, getXRef(0));
a.str(src3.reg, getXRef(2));

ubif_comment(Bif);
ubif_comment(Bif, Exp);
emit_i_bif(Fail, Bif, Dst);
}

Expand All @@ -168,12 +188,13 @@ void BeamModuleAssembler::emit_i_bif(const ArgLabel &Fail,

void BeamModuleAssembler::emit_nofail_bif1(const ArgSource &Src1,
const ArgWord &Bif,
const ArgExport &Exp,
const ArgRegister &Dst) {
auto src1 = load_source(Src1);

a.str(src1.reg, getXRef(0));

ubif_comment(Bif);
ubif_comment(Bif, Exp);
mov_arg(ARG4, Bif);
fragment_call(ga->get_i_bif_guard_shared());
mov_arg(Dst, ARG1);
Expand All @@ -182,12 +203,13 @@ void BeamModuleAssembler::emit_nofail_bif1(const ArgSource &Src1,
void BeamModuleAssembler::emit_nofail_bif2(const ArgSource &Src1,
const ArgSource &Src2,
const ArgWord &Bif,
const ArgExport &Exp,
const ArgRegister &Dst) {
auto [src1, src2] = load_sources(Src1, TMP1, Src2, TMP2);

a.stp(src1.reg, src2.reg, getXRef(0));

ubif_comment(Bif);
ubif_comment(Bif, Exp);
mov_arg(ARG4, Bif);
fragment_call(ga->get_i_bif_guard_shared());
mov_arg(Dst, ARG1);
Expand Down Expand Up @@ -609,25 +631,25 @@ void BeamModuleAssembler::emit_send() {
fragment_call(ga->get_call_light_bif_shared());
}

void BeamModuleAssembler::emit_i_bif_pure(const ArgWord &Bif,
const ArgExport &Exp,
const ArgWord &Live,
const ArgLabel &Fail,
const ArgRegister &Dst) {
}

void BeamModuleAssembler::emit_i_bif1_pure(const ArgWord &Bif,
const ArgExport &Exp,
const ArgWord &Live,
const ArgLabel &Fail,
const ArgSource &Src1,
const ArgRegister &Dst) {
auto src1 = load_source(Src1);

a.str(src1.reg, getXRef(0));

emit_i_bif_pure(Fail, Exp, Bif, Live, Dst);
}
// void BeamModuleAssembler::emit_i_bif_pure(const ArgWord &Bif,
// const ArgExport &Exp,
// const ArgWord &Live,
// const ArgLabel &Fail,
// const ArgRegister &Dst) {
// }

// void BeamModuleAssembler::emit_i_bif1_pure(const ArgWord &Bif,
// const ArgExport &Exp,
// const ArgWord &Live,
// const ArgLabel &Fail,
// const ArgSource &Src1,
// const ArgRegister &Dst) {
// auto src1 = load_source(Src1);

// a.str(src1.reg, getXRef(0));

// emit_i_bif_pure(Fail, Exp, Bif, Live, Dst);
// }

void BeamModuleAssembler::emit_nif_start() {
/* load time only instruction */
Expand Down
3 changes: 2 additions & 1 deletion erts/emulator/beam/jit/arm/instr_guard_bifs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -802,12 +802,13 @@ void BeamModuleAssembler::emit_bif_hd(const ArgSource &Src,
*/

void BeamModuleAssembler::emit_bif_is_map_key(const ArgWord &Bif,
const ArgExport &Exp,
const ArgLabel &Fail,
const ArgSource &Key,
const ArgSource &Src,
const ArgRegister &Dst) {
if (!exact_type<BeamTypeId::Map>(Src)) {
emit_i_bif2(Key, Src, Fail, Bif, Dst);
emit_i_bif2(Key, Src, Fail, Bif, Exp, Dst);
return;
}

Expand Down
42 changes: 21 additions & 21 deletions erts/emulator/beam/jit/arm/ops.tab
Original file line number Diff line number Diff line change
Expand Up @@ -786,8 +786,8 @@ bif2 Fail _Bif=u$bif:erlang:map_get/2 Src1 Src2=xy Dst=d =>
bif_map_get j s s d

bif2 Fail Bif=u$bif:erlang:is_map_key/2 Key Map=xy Dst=d =>
bif_is_map_key Bif Fail Key Map Dst
bif_is_map_key b j s s d
bif_is_map_key Bif Bif Fail Key Map Dst
bif_is_map_key b e j s s d

bif2 _Fail _Bif=u$bif:erlang:max/2 Src1 Src2 Dst =>
bif_max Src1 Src2 Dst
Expand All @@ -796,16 +796,16 @@ bif2 _Fail _Bif=u$bif:erlang:min/2 Src1 Src2 Dst =>
bif_max s s d
bif_min s s d

bif1 _Fail Bif S1 Dst | never_fails(Bif) => nofail_bif1 S1 Bif Dst
bif2 _Fail Bif S1 S2 Dst | never_fails(Bif) => nofail_bif2 S1 S2 Bif Dst
bif1 _Fail Bif S1 Dst | never_fails(Bif) => nofail_bif1 S1 Bif Bif Dst
bif2 _Fail Bif S1 S2 Dst | never_fails(Bif) => nofail_bif2 S1 S2 Bif Bif Dst

bif1 Fail Bif S1 Dst => i_bif1 S1 Fail Bif Dst
bif2 Fail Bif S1 S2 Dst => i_bif2 S1 S2 Fail Bif Dst
bif1 Fail Bif S1 Dst => i_bif1 S1 Fail Bif Bif Dst
bif2 Fail Bif S1 S2 Dst => i_bif2 S1 S2 Fail Bif Bif Dst

nofail_bif2 S1=d S2 Bif Dst | is_eq_exact_bif(Bif) => bif_is_eq_exact S1 S2 Dst
nofail_bif2 S1=d S2 Bif Dst | is_ne_exact_bif(Bif) => bif_is_ne_exact S1 S2 Dst
nofail_bif2 S1 S2 Bif Dst | is_ge_bif(Bif) => bif_is_ge S1 S2 Dst
nofail_bif2 S1 S2 Bif Dst | is_lt_bif(Bif) => bif_is_lt S1 S2 Dst
nofail_bif2 S1=d S2 Bif _Exp Dst | is_eq_exact_bif(Bif) => bif_is_eq_exact S1 S2 Dst
nofail_bif2 S1=d S2 Bif _Exp Dst | is_ne_exact_bif(Bif) => bif_is_ne_exact S1 S2 Dst
nofail_bif2 S1 S2 Bif _Exp Dst | is_ge_bif(Bif) => bif_is_ge S1 S2 Dst
nofail_bif2 S1 S2 Bif _Exp Dst | is_lt_bif(Bif) => bif_is_lt S1 S2 Dst

i_get_hash c W d
i_get s d
Expand All @@ -814,12 +814,12 @@ self d

node d

nofail_bif1 s b d
nofail_bif2 s s b d
nofail_bif1 s b e d
nofail_bif2 s s b e d

i_bif1 s j b d
i_bif2 s s j b d
i_bif3 s s s j b d
i_bif1 s j b e d
i_bif2 s s j b e d
i_bif3 s s s j b e d

bif_is_eq_exact S s d
bif_is_ne_exact S s d
Expand Down Expand Up @@ -1319,17 +1319,17 @@ bif_map_size j s d
#
# Pure BIFs.
#
gc_bif1 Fail=f Live Bif S1 Dst | is_pure_bif(Bif) =>
i_bif1_pure Bif Bif Live Fail S1 Dst
#gc_bif1 Fail=f Live Bif S1 Dst | is_pure_bif(Bif) =>
# i_bif1_pure Bif Bif Live Fail S1 Dst

i_bif1_pure b e t f s d
#i_bif1_pure b e t f s d

#
# Guard BIFs.
#
gc_bif1 Fail _Live Bif Src Dst => i_bif1 Src Fail Bif Dst
gc_bif2 Fail _Live Bif S1 S2 Dst => i_bif2 S1 S2 Fail Bif Dst
gc_bif3 Fail _Live Bif S1 S2 S3 Dst => i_bif3 S1 S2 S3 Fail Bif Dst
gc_bif1 Fail _Live Bif Src Dst => i_bif1 Src Fail Bif Bif Dst
gc_bif2 Fail _Live Bif S1 S2 Dst => i_bif2 S1 S2 Fail Bif Bif Dst
gc_bif3 Fail _Live Bif S1 S2 S3 Dst => i_bif3 S1 S2 S3 Fail Bif Bif Dst

#
# The following instruction is specially handled in beam_load.c
Expand Down
30 changes: 15 additions & 15 deletions erts/emulator/beam/predicates.tab
Original file line number Diff line number Diff line change
Expand Up @@ -140,25 +140,25 @@ pred.is_heavy_bif(Bif) {
return 0;
}

pred.is_pure_bif(Bif) {
BeamFile_ImportEntry *import;
const Export *export;
// pred.is_pure_bif(Bif) {
// BeamFile_ImportEntry *import;
// const Export *export;

if (Bif.type != TAG_u || Bif.val >= S->beam.imports.count) {
return 0;
}
// if (Bif.type != TAG_u || Bif.val >= S->beam.imports.count) {
// return 0;
// }

import = &S->beam.imports.entries[Bif.val];
export = erts_active_export_entry(import->module,
import->function,
import->arity);
// import = &S->beam.imports.entries[Bif.val];
// export = erts_active_export_entry(import->module,
// import->function,
// import->arity);

if (export->bif_number != -1) {
return bif_table[export->bif_number].kind == BIF_KIND_PURE;
}
// if (export->bif_number != -1) {
// return bif_table[export->bif_number].kind == BIF_KIND_PURE;
// }

return 0;
}
// return 0;
// }

// Predicate to test whether all of the given new small map keys are literals
pred.is_small_map_literal_keys(Size, Rest) {
Expand Down
4 changes: 2 additions & 2 deletions lib/compiler/src/beam_ssa_opt.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1913,8 +1913,8 @@ reduce_try_is([#b_set{op=Op}=I|Is], Acc) ->
reduce_try_is([], Acc) ->
{safe,reverse(Acc)}.

is_safe_as_guard_bif(erlang, binary_to_atom, 1) -> true;
is_safe_as_guard_bif(erlang, binary_to_existing_atom, 1) -> true;
is_safe_as_guard_bif(erlang, binary_to_atom, 2) -> true;
is_safe_as_guard_bif(erlang, binary_to_existing_atom, 2) -> true;
is_safe_as_guard_bif(erlang, list_to_atom, 1) -> true;
is_safe_as_guard_bif(erlang, list_to_existing_atom, 1) -> true;
is_safe_as_guard_bif(_, _, _) -> false.
Expand Down

0 comments on commit 42a53eb

Please sign in to comment.