Skip to content

Commit 86dbe1c

Browse files
committed
amd64: Move stack realloc calls out-of-line
1 parent 324d218 commit 86dbe1c

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

asmcomp/amd64/emit.mlp

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,19 @@ let emit_call_gc gc =
279279
def_label gc.gc_frame;
280280
I.jmp (label gc.gc_return_lbl)
281281

282+
(* Record calls to local stack reallocation *)
283+
284+
type local_realloc_call =
285+
{ lr_lbl: label;
286+
lr_return_lbl: label; }
287+
288+
let local_realloc_sites = ref ([] : local_realloc_call list)
289+
290+
let emit_local_realloc lr =
291+
def_label lr.lr_lbl;
292+
emit_call "caml_call_local_realloc";
293+
I.jmp (label lr.lr_return_lbl)
294+
282295
(* Record calls to caml_ml_array_bound_error.
283296
In -g mode we maintain one call to
284297
caml_ml_array_bound_error per bound check site. Without -g, we can share
@@ -657,12 +670,15 @@ let emit_instr fallthrough i =
657670
(* FIXME: before or after check? Calling conv w/ realloc *)
658671
I.mov r (domain_field Domainstate.Domain_local_sp);
659672
I.cmp (domain_field Domainstate.Domain_local_limit) r;
660-
let lbl_ok = new_label () in
661-
I.j GE (label lbl_ok);
662-
emit_call "caml_call_local_realloc";
663-
def_label lbl_ok;
673+
let lbl_call = new_label () in
674+
I.j L (label lbl_call);
675+
let lbl_after_alloc = new_label () in
676+
def_label lbl_after_alloc;
664677
I.add (domain_field Domainstate.Domain_local_top) r;
665678
I.add (int 8) r;
679+
local_realloc_sites :=
680+
{ lr_lbl = lbl_call;
681+
lr_return_lbl = lbl_after_alloc } :: !local_realloc_sites
666682
| Lop(Iintop(Icomp cmp)) ->
667683
I.cmp (arg i 1) (arg i 0);
668684
I.set (cond cmp) al;
@@ -885,6 +901,7 @@ let fundecl fundecl =
885901
tailrec_entry_point := fundecl.fun_tailrec_entry_point_label;
886902
stack_offset := 0;
887903
call_gc_sites := [];
904+
local_realloc_sites := [];
888905
bound_error_sites := [];
889906
bound_error_call := 0;
890907
for i = 0 to Proc.num_register_classes - 1 do
@@ -908,6 +925,7 @@ let fundecl fundecl =
908925
cfi_startproc ();
909926
emit_all true fundecl.fun_body;
910927
List.iter emit_call_gc !call_gc_sites;
928+
List.iter emit_local_realloc !local_realloc_sites;
911929
emit_call_bound_errors ();
912930
if !frame_required then begin
913931
let n = frame_size() - 8 - (if fp then 8 else 0) in

0 commit comments

Comments
 (0)