Skip to content

Commit a4080b8

Browse files
committed
Initial version of local allocation (unsafe)
1 parent 7116602 commit a4080b8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+693
-279
lines changed

asmcomp/amd64/CSE.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ method! class_of_operation op =
2929
begin match spec with
3030
| Ilea _ | Isextend32 | Izextend32 -> Op_pure
3131
| Istore_int(_, _, is_asg) -> Op_store is_asg
32+
| Iregionbegin -> Op_load
33+
| Iregionend -> Op_store true
3234
| Ioffset_loc(_, _) -> Op_store true
3335
| Ifloatarithmem _ | Ifloatsqrtf _ -> Op_load
3436
| Ibswap _ | Isqrtf -> super#class_of_operation op

asmcomp/amd64/arch.ml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ type specific_operation =
4646
extension *)
4747
| Izextend32 (* 32 to 64 bit conversion with zero
4848
extension *)
49+
| Iregionbegin
50+
| Iregionend
4951

5052
and float_operation =
5153
Ifloatadd | Ifloatsub | Ifloatmul | Ifloatdiv
@@ -133,6 +135,10 @@ let print_specific_operation printreg op ppf arg =
133135
fprintf ppf "sextend32 %a" printreg arg.(0)
134136
| Izextend32 ->
135137
fprintf ppf "zextend32 %a" printreg arg.(0)
138+
| Iregionbegin ->
139+
fprintf ppf "iregionbegin"
140+
| Iregionend ->
141+
fprintf ppf "iregionend %a" printreg arg.(0)
136142

137143
let win64 =
138144
match Config.system with

asmcomp/amd64/emit.mlp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,7 @@ let emit_instr fallthrough i =
619619
| Double | Double_u ->
620620
I.movsd (arg i 0) (addressing addr REAL8 i 1)
621621
end
622-
| Lop(Ialloc { bytes = n; dbginfo }) ->
622+
| Lop(Ialloc { bytes = n; dbginfo; mode = Alloc_heap }) ->
623623
assert (n <= (Config.max_young_wosize + 1) * Arch.size_addr);
624624
if !fastcode_flag then begin
625625
I.sub (int n) r15;
@@ -649,6 +649,20 @@ let emit_instr fallthrough i =
649649
def_label label;
650650
I.lea (mem64 NONE 8 R15) (res i 0)
651651
end
652+
| Lop(Ialloc { bytes = n; dbginfo=_; mode = Alloc_local }) ->
653+
assert (n <= (Config.max_young_wosize + 1) * Arch.size_addr);
654+
let r = res i 0 in
655+
I.mov (domain_field Domainstate.Domain_local_sp) r;
656+
I.sub (int n) r;
657+
(* FIXME: before or after check? Calling conv w/ realloc *)
658+
I.mov r (domain_field Domainstate.Domain_local_sp);
659+
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;
664+
I.add (domain_field Domainstate.Domain_local_top) r;
665+
I.add (int 8) r;
652666
| Lop(Iintop(Icomp cmp)) ->
653667
I.cmp (arg i 1) (arg i 0);
654668
I.set (cond cmp) al;
@@ -724,6 +738,10 @@ let emit_instr fallthrough i =
724738
I.movsxd (arg32 i 0) (res i 0)
725739
| Lop(Ispecific(Izextend32)) ->
726740
I.mov (arg32 i 0) (res32 i 0)
741+
| Lop(Ispecific(Iregionbegin)) ->
742+
I.mov (domain_field Domainstate.Domain_local_sp) (res i 0)
743+
| Lop(Ispecific(Iregionend)) ->
744+
I.mov (arg i 0) (domain_field Domainstate.Domain_local_sp)
727745
| Lop (Iname_for_debugger _) -> ()
728746
| Lreloadretaddr ->
729747
()

asmcomp/amd64/selection.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,8 @@ method! select_operation op args dbg =
245245
Ispecific Izextend32, [arg]
246246
| _ -> super#select_operation op args dbg
247247
end
248+
| Cbeginregion -> Ispecific Iregionbegin, args
249+
| Cendregion -> Ispecific Iregionend, args
248250
| _ -> super#select_operation op args dbg
249251

250252
(* Recognize float arithmetic with mem *)

asmcomp/cmm.ml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ and operation =
152152
Capply of machtype
153153
| Cextcall of string * machtype * exttype list * bool
154154
| Cload of memory_chunk * Asttypes.mutable_flag
155-
| Calloc
155+
| Calloc of Lambda.alloc_mode
156156
| Cstore of memory_chunk * Lambda.initialization_or_assignment
157157
| Caddi | Csubi | Cmuli | Cmulhi | Cdivi | Cmodi
158158
| Cand | Cor | Cxor | Clsl | Clsr | Casr
@@ -165,6 +165,8 @@ and operation =
165165
| Ccmpf of float_comparison
166166
| Craise of Lambda.raise_kind
167167
| Ccheckbound
168+
| Cbeginregion
169+
| Cendregion
168170

169171
type expression =
170172
Cconst_int of int * Debuginfo.t

asmcomp/cmm.mli

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ and operation =
145145
The [exttype list] describes the unboxing types of the arguments.
146146
An empty list means "all arguments are machine words [XInt]". *)
147147
| Cload of memory_chunk * Asttypes.mutable_flag
148-
| Calloc
148+
| Calloc of Lambda.alloc_mode
149149
| Cstore of memory_chunk * Lambda.initialization_or_assignment
150150
| Caddi | Csubi | Cmuli | Cmulhi | Cdivi | Cmodi
151151
| Cand | Cor | Cxor | Clsl | Clsr | Casr
@@ -162,6 +162,8 @@ and operation =
162162
then the index.
163163
It results in a bounds error if the index is greater than
164164
or equal to the bound. *)
165+
| Cbeginregion
166+
| Cendregion
165167

166168
(** Every basic block should have a corresponding [Debuginfo.t] for its
167169
beginning. *)

asmcomp/cmm_helpers.ml

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -556,12 +556,12 @@ let test_bool dbg cmm =
556556

557557
(* Float *)
558558

559-
let box_float dbg c = Cop(Calloc, [alloc_float_header dbg; c], dbg)
559+
let box_float dbg c = Cop(Calloc Alloc_heap, [alloc_float_header dbg; c], dbg)
560560

561561
let unbox_float dbg =
562562
map_tail
563563
(function
564-
| Cop(Calloc, [Cconst_natint (hdr, _); c], _)
564+
| Cop(Calloc Alloc_heap, [Cconst_natint (hdr, _); c], _)
565565
when Nativeint.equal hdr float_header ->
566566
c
567567
| Cconst_symbol (s, _dbg) as cmm ->
@@ -577,7 +577,7 @@ let unbox_float dbg =
577577
(* Complex *)
578578

579579
let box_complex dbg c_re c_im =
580-
Cop(Calloc, [alloc_floatarray_header 2 dbg; c_re; c_im], dbg)
580+
Cop(Calloc Alloc_heap, [alloc_floatarray_header 2 dbg; c_re; c_im], dbg)
581581

582582
let complex_re c dbg = Cop(Cload (Double_u, Immutable), [c], dbg)
583583
let complex_im c dbg = Cop(Cload (Double_u, Immutable),
@@ -793,9 +793,10 @@ let call_cached_method obj tag cache pos args dbg =
793793

794794
(* Allocation *)
795795

796-
let make_alloc_generic set_fn dbg tag wordsize args =
796+
let make_alloc_generic ~mode set_fn dbg tag wordsize args =
797797
if wordsize <= Config.max_young_wosize then
798-
Cop(Calloc, Cconst_natint(block_header tag wordsize, dbg) :: args, dbg)
798+
Cop(Calloc mode,
799+
Cconst_natint(block_header tag wordsize, dbg) :: args, dbg)
799800
else begin
800801
let id = V.create_local "*alloc*" in
801802
let rec fill_fields idx = function
@@ -808,15 +809,15 @@ let make_alloc_generic set_fn dbg tag wordsize args =
808809
fill_fields 1 args)
809810
end
810811

811-
let make_alloc dbg tag args =
812+
let make_alloc ?(mode=Lambda.Alloc_heap) dbg tag args =
812813
let addr_array_init arr ofs newval dbg =
813814
Cop(Cextcall("caml_initialize", typ_void, [], false),
814815
[array_indexing log2_size_addr arr ofs dbg; newval], dbg)
815816
in
816-
make_alloc_generic addr_array_init dbg tag (List.length args) args
817+
make_alloc_generic ~mode addr_array_init dbg tag (List.length args) args
817818

818819
let make_float_alloc dbg tag args =
819-
make_alloc_generic float_array_set dbg tag
820+
make_alloc_generic ~mode:Alloc_heap float_array_set dbg tag
820821
(List.length args * size_float / size_addr) args
821822

822823
(* Bounds checking *)
@@ -1017,9 +1018,10 @@ let box_int_gen dbg (bi : Primitive.boxed_integer) arg =
10171018
else sign_extend_32 dbg arg
10181019
else arg
10191020
in
1020-
Cop(Calloc, [alloc_header_boxed_int bi dbg;
1021-
Cconst_symbol(operations_boxed_int bi, dbg);
1022-
arg'], dbg)
1021+
Cop(Calloc Alloc_heap,
1022+
[alloc_header_boxed_int bi dbg;
1023+
Cconst_symbol(operations_boxed_int bi, dbg);
1024+
arg'], dbg)
10231025

10241026
let split_int64_for_32bit_target arg dbg =
10251027
bind "split_int64" arg (fun arg ->
@@ -1053,20 +1055,20 @@ let unbox_int dbg bi =
10531055
in
10541056
map_tail
10551057
(function
1056-
| Cop(Calloc,
1058+
| Cop(Calloc Alloc_heap,
10571059
[hdr; ops;
10581060
Cop(Clsl, [contents; Cconst_int (32, _)], _dbg')], _dbg)
10591061
when bi = Primitive.Pint32 && size_int = 8 && big_endian
10601062
&& alloc_matches_boxed_int bi ~hdr ~ops ->
10611063
(* Force sign-extension of low 32 bits *)
10621064
sign_extend_32 dbg contents
1063-
| Cop(Calloc,
1065+
| Cop(Calloc Alloc_heap,
10641066
[hdr; ops; contents], _dbg)
10651067
when bi = Primitive.Pint32 && size_int = 8 && not big_endian
10661068
&& alloc_matches_boxed_int bi ~hdr ~ops ->
10671069
(* Force sign-extension of low 32 bits *)
10681070
sign_extend_32 dbg contents
1069-
| Cop(Calloc, [hdr; ops; contents], _dbg)
1071+
| Cop(Calloc Alloc_heap, [hdr; ops; contents], _dbg)
10701072
when alloc_matches_boxed_int bi ~hdr ~ops ->
10711073
contents
10721074
| Cconst_symbol (s, _dbg) as cmm ->
@@ -1997,7 +1999,7 @@ let rec intermediate_curry_functions arity num =
19971999
fun_args = [VP.create arg, typ_val; VP.create clos, typ_val];
19982000
fun_body =
19992001
if arity - num > 2 && arity <= max_arity_optimized then
2000-
Cop(Calloc,
2002+
Cop(Calloc Alloc_heap,
20012003
[alloc_closure_header 5 (dbg ());
20022004
Cconst_symbol(name1 ^ "_" ^ Int.to_string (num+1), dbg ());
20032005
alloc_closure_info ~arity:(arity - num - 1)
@@ -2007,7 +2009,7 @@ let rec intermediate_curry_functions arity num =
20072009
Cvar arg; Cvar clos],
20082010
dbg ())
20092011
else
2010-
Cop(Calloc,
2012+
Cop(Calloc Alloc_heap,
20112013
[alloc_closure_header 4 (dbg ());
20122014
Cconst_symbol(name1 ^ "_" ^ Int.to_string (num+1), dbg ());
20132015
alloc_closure_info ~arity:1 ~startenv:2 (dbg ());

asmcomp/cmm_helpers.mli

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,8 @@ val call_cached_method :
299299
(** Allocations *)
300300

301301
(** Allocate a block of regular values with the given tag *)
302-
val make_alloc : Debuginfo.t -> int -> expression list -> expression
302+
val make_alloc :
303+
?mode:Lambda.alloc_mode -> Debuginfo.t -> int -> expression list -> expression
303304

304305
(** Allocate a block of unboxed floats with the given tag *)
305306
val make_float_alloc : Debuginfo.t -> int -> expression list -> expression

asmcomp/cmmgen.ml

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -314,10 +314,10 @@ let is_unboxed_number_cmm ~strict cmm =
314314
r := join_unboxed_number_kind ~strict !r k
315315
in
316316
let rec aux = function
317-
| Cop(Calloc, [Cconst_natint (hdr, _); _], dbg)
317+
| Cop(Calloc _, [Cconst_natint (hdr, _); _], dbg)
318318
when Nativeint.equal hdr float_header ->
319319
notify (Boxed (Boxed_float dbg, false))
320-
| Cop(Calloc, [Cconst_natint (hdr, _); Cconst_symbol (ops, _); _], dbg) ->
320+
| Cop(Calloc _, [Cconst_natint (hdr, _); Cconst_symbol (ops, _); _], dbg) ->
321321
if Nativeint.equal hdr boxedintnat_header
322322
&& String.equal ops caml_nativeint_ops
323323
then
@@ -459,8 +459,8 @@ let rec transl env e =
459459
Cconst_symbol (sym, dbg)
460460
| (Pmakeblock _, []) ->
461461
assert false
462-
| (Pmakeblock(tag, _mut, _kind), args) ->
463-
make_alloc dbg tag (List.map (transl env) args)
462+
| (Pmakeblock(tag, _mut, _kind, mode), args) ->
463+
make_alloc ~mode dbg tag (List.map (transl env) args)
464464
| (Pccall prim, args) ->
465465
transl_ccall env prim args dbg
466466
| (Pduparray (kind, _), [Uprim (Pmakearray (kind', _), args, _dbg)]) ->
@@ -556,7 +556,7 @@ let rec transl env e =
556556
| Pandbint _ | Porbint _ | Pxorbint _ | Plslbint _ | Plsrbint _
557557
| Pasrbint _ | Pbintcomp (_, _) | Pstring_load _ | Pbytes_load _
558558
| Pbytes_set _ | Pbigstring_load _ | Pbigstring_set _
559-
| Pbbswap _), _)
559+
| Pbbswap _ | Pendregion), _)
560560
->
561561
fatal_error "Cmmgen.transl:prim"
562562
end
@@ -672,6 +672,8 @@ let rec transl env e =
672672
| Uunreachable ->
673673
let dbg = Debuginfo.none in
674674
Cop(Cload (Word_int, Mutable), [Cconst_int (0, dbg)], dbg)
675+
| Ubeginregion (r, e) ->
676+
Clet (r, Cop (Cbeginregion, [], Debuginfo.none), transl env e)
675677

676678
and transl_catch env nfail ids body handler dbg =
677679
let ids = List.map (fun (id, kind) -> (id, kind, ref No_result)) ids in
@@ -844,13 +846,15 @@ and transl_prim_1 env p arg dbg =
844846
| Pbswap16 ->
845847
tag_int (bswap16 (ignore_high_bit_int (untag_int
846848
(transl env arg) dbg)) dbg) dbg
849+
| Pendregion ->
850+
Cop(Cendregion, [transl env arg], dbg)
847851
| (Pfield_computed | Psequand | Psequor
848852
| Paddint | Psubint | Pmulint | Pandint
849853
| Porint | Pxorint | Plslint | Plsrint | Pasrint
850854
| Paddfloat | Psubfloat | Pmulfloat | Pdivfloat
851855
| Pstringrefu | Pstringrefs | Pbytesrefu | Pbytessetu
852856
| Pbytesrefs | Pbytessets | Pisout | Pread_symbol _
853-
| Pmakeblock (_, _, _) | Psetfield (_, _, _) | Psetfield_computed (_, _)
857+
| Pmakeblock (_, _, _, _) | Psetfield (_, _, _) | Psetfield_computed (_, _)
854858
| Psetfloatfield (_, _) | Pduprecord (_, _) | Pccall _ | Pdivint _
855859
| Pmodint _ | Pintcomp _ | Pfloatcomp _ | Pmakearray (_, _)
856860
| Pcompare_ints | Pcompare_floats | Pcompare_bints _
@@ -1031,12 +1035,13 @@ and transl_prim_2 env p arg1 arg2 dbg =
10311035
| Pnot | Pnegint | Pintoffloat | Pfloatofint | Pnegfloat
10321036
| Pabsfloat | Pstringlength | Pbyteslength | Pbytessetu | Pbytessets
10331037
| Pisint | Pbswap16 | Pint_as_pointer | Popaque | Pread_symbol _
1034-
| Pmakeblock (_, _, _) | Pfield _ | Psetfield_computed (_, _) | Pfloatfield _
1038+
| Pmakeblock (_, _, _, _) | Pfield _ | Psetfield_computed (_, _)
1039+
| Pfloatfield _
10351040
| Pduprecord (_, _) | Pccall _ | Praise _ | Poffsetint _ | Poffsetref _
10361041
| Pmakearray (_, _) | Pduparray (_, _) | Parraylength _ | Parraysetu _
10371042
| Parraysets _ | Pbintofint _ | Pintofbint _ | Pcvtbint (_, _)
10381043
| Pnegbint _ | Pbigarrayref (_, _, _, _) | Pbigarrayset (_, _, _, _)
1039-
| Pbigarraydim _ | Pbytes_set _ | Pbigstring_set _ | Pbbswap _
1044+
| Pbigarraydim _ | Pbytes_set _ | Pbigstring_set _ | Pbbswap _ | Pendregion
10401045
->
10411046
fatal_errorf "Cmmgen.transl_prim_2: %a"
10421047
Printclambda_primitives.primitive p
@@ -1084,7 +1089,8 @@ and transl_prim_3 env p arg1 arg2 arg3 dbg =
10841089
| Pintoffloat | Pfloatofint | Pnegfloat | Pabsfloat | Paddfloat | Psubfloat
10851090
| Pmulfloat | Pdivfloat | Pstringlength | Pstringrefu | Pstringrefs
10861091
| Pbyteslength | Pbytesrefu | Pbytesrefs | Pisint | Pisout
1087-
| Pbswap16 | Pint_as_pointer | Popaque | Pread_symbol _ | Pmakeblock (_, _, _)
1092+
| Pbswap16 | Pint_as_pointer | Popaque | Pread_symbol _
1093+
| Pmakeblock (_, _, _, _)
10881094
| Pfield _ | Psetfield (_, _, _) | Pfloatfield _ | Psetfloatfield (_, _)
10891095
| Pduprecord (_, _) | Pccall _ | Praise _ | Pdivint _ | Pmodint _ | Pintcomp _
10901096
| Pcompare_ints | Pcompare_floats | Pcompare_bints _
@@ -1094,7 +1100,7 @@ and transl_prim_3 env p arg1 arg2 arg3 dbg =
10941100
| Psubbint _ | Pmulbint _ | Pdivbint _ | Pmodbint _ | Pandbint _ | Porbint _
10951101
| Pxorbint _ | Plslbint _ | Plsrbint _ | Pasrbint _ | Pbintcomp (_, _)
10961102
| Pbigarrayref (_, _, _, _) | Pbigarrayset (_, _, _, _) | Pbigarraydim _
1097-
| Pstring_load _ | Pbytes_load _ | Pbigstring_load _ | Pbbswap _
1103+
| Pstring_load _ | Pbytes_load _ | Pbigstring_load _ | Pbbswap _ | Pendregion
10981104
->
10991105
fatal_errorf "Cmmgen.transl_prim_3: %a"
11001106
Printclambda_primitives.primitive p

0 commit comments

Comments
 (0)