Skip to content

Commit a2a4e60

Browse files
committed
Runtime and compiler support for more local allocations (#23)
* Local allocation support for arrays and records * Relax the Max_young_wosize constraint on local allocs * Runtime support for local array allocations. Includes a bugfix in realloc_local (wsize/bsize confusion).
1 parent d030554 commit a2a4e60

25 files changed

+411
-78
lines changed

asmcomp/amd64/emit.mlp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -663,11 +663,9 @@ let emit_instr fallthrough i =
663663
I.lea (mem64 NONE 8 R15) (res i 0)
664664
end
665665
| Lop(Ialloc { bytes = n; dbginfo=_; mode = Alloc_local }) ->
666-
assert (n <= (Config.max_young_wosize + 1) * Arch.size_addr);
667666
let r = res i 0 in
668667
I.mov (domain_field Domainstate.Domain_local_sp) r;
669668
I.sub (int n) r;
670-
(* FIXME: before or after check? Calling conv w/ realloc *)
671669
I.mov r (domain_field Domainstate.Domain_local_sp);
672670
I.cmp (domain_field Domainstate.Domain_local_limit) r;
673671
let lbl_call = new_label () in

asmcomp/cmm_helpers.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -794,7 +794,7 @@ let call_cached_method obj tag cache pos args dbg =
794794
(* Allocation *)
795795

796796
let make_alloc_generic ~mode set_fn dbg tag wordsize args =
797-
if wordsize <= Config.max_young_wosize then
797+
if mode = Lambda.Alloc_local || wordsize <= Config.max_young_wosize then
798798
Cop(Calloc mode,
799799
Cconst_natint(block_header tag wordsize, dbg) :: args, dbg)
800800
else begin
@@ -816,8 +816,8 @@ let make_alloc ?(mode=Lambda.Alloc_heap) dbg tag args =
816816
in
817817
make_alloc_generic ~mode addr_array_init dbg tag (List.length args) args
818818

819-
let make_float_alloc dbg tag args =
820-
make_alloc_generic ~mode:Alloc_heap float_array_set dbg tag
819+
let make_float_alloc ?(mode=Lambda.Alloc_heap) dbg tag args =
820+
make_alloc_generic ~mode float_array_set dbg tag
821821
(List.length args * size_float / size_addr) args
822822

823823
(* Bounds checking *)

asmcomp/cmm_helpers.mli

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,8 @@ val make_alloc :
303303
?mode:Lambda.alloc_mode -> Debuginfo.t -> int -> expression list -> expression
304304

305305
(** Allocate a block of unboxed floats with the given tag *)
306-
val make_float_alloc : Debuginfo.t -> int -> expression list -> expression
306+
val make_float_alloc :
307+
?mode:Lambda.alloc_mode -> Debuginfo.t -> int -> expression list -> expression
307308

308309
(** Bounds checking *)
309310

asmcomp/cmmgen.ml

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -144,11 +144,11 @@ let rec expr_size env = function
144144
expr_size env body
145145
| Uprim(Pmakeblock _, args, _) ->
146146
RHS_block (List.length args)
147-
| Uprim(Pmakearray((Paddrarray | Pintarray), _), args, _) ->
147+
| Uprim(Pmakearray((Paddrarray | Pintarray), _, _), args, _) ->
148148
RHS_block (List.length args)
149-
| Uprim(Pmakearray(Pfloatarray, _), args, _) ->
149+
| Uprim(Pmakearray(Pfloatarray, _, _), args, _) ->
150150
RHS_floatblock (List.length args)
151-
| Uprim(Pmakearray(Pgenarray, _), _, _) ->
151+
| Uprim(Pmakearray(Pgenarray, _, _), _, _) ->
152152
(* Pgenarray is excluded from recursive bindings by the
153153
check in Translcore.check_recursive_lambda *)
154154
RHS_nonrec
@@ -463,7 +463,7 @@ let rec transl env e =
463463
make_alloc ~mode dbg tag (List.map (transl env) args)
464464
| (Pccall prim, args) ->
465465
transl_ccall env prim args dbg
466-
| (Pduparray (kind, _), [Uprim (Pmakearray (kind', _), args, _dbg)]) ->
466+
| (Pduparray (kind, _), [Uprim (Pmakearray (kind', _, _), args, _dbg)]) ->
467467
(* We arrive here in two cases:
468468
1. When using Closure, all the time.
469469
2. When using Flambda, if a float array longer than
@@ -475,15 +475,16 @@ let rec transl env e =
475475
state of [Translcore], we will in fact only get here with
476476
[Pfloatarray]s. *)
477477
assert (kind = kind');
478-
transl_make_array dbg env kind args
478+
transl_make_array dbg env kind Alloc_heap args
479479
| (Pduparray _, [arg]) ->
480480
let prim_obj_dup =
481481
Primitive.simple ~name:"caml_obj_dup" ~arity:1 ~alloc:true
482482
in
483483
transl_ccall env prim_obj_dup [arg] dbg
484484
| (Pmakearray _, []) ->
485485
Misc.fatal_error "Pmakearray is not allowed for an empty array"
486-
| (Pmakearray (kind, _), args) -> transl_make_array dbg env kind args
486+
| (Pmakearray (kind, _, mode), args) ->
487+
transl_make_array dbg env kind mode args
487488
| (Pbigarrayref(unsafe, _num_dims, elt_kind, layout), arg1 :: argl) ->
488489
let elt =
489490
bigarray_get unsafe elt_kind layout
@@ -728,15 +729,20 @@ and transl_catch env nfail ids body handler dbg =
728729
in
729730
ccatch (new_nfail, ids, body, transl new_env handler, dbg)
730731

731-
and transl_make_array dbg env kind args =
732+
and transl_make_array dbg env kind mode args =
732733
match kind with
733734
| Pgenarray ->
734-
Cop(Cextcall("caml_make_array", typ_val, [], true),
735-
[make_alloc dbg 0 (List.map (transl env) args)], dbg)
735+
let prim =
736+
match (mode : Lambda.alloc_mode) with
737+
| Alloc_heap -> "caml_make_array"
738+
| Alloc_local -> "caml_make_array_local"
739+
in
740+
Cop(Cextcall(prim, typ_val, [], true),
741+
[make_alloc ~mode dbg 0 (List.map (transl env) args)], dbg)
736742
| Paddrarray | Pintarray ->
737-
make_alloc dbg 0 (List.map (transl env) args)
743+
make_alloc ~mode dbg 0 (List.map (transl env) args)
738744
| Pfloatarray ->
739-
make_float_alloc dbg Obj.double_array_tag
745+
make_float_alloc ~mode dbg Obj.double_array_tag
740746
(List.map (transl_unbox_float dbg env) args)
741747

742748
and transl_ccall env prim args dbg =
@@ -854,7 +860,7 @@ and transl_prim_1 env p arg dbg =
854860
| Pbytesrefs | Pbytessets | Pisout | Pread_symbol _
855861
| Pmakeblock (_, _, _, _) | Psetfield (_, _, _) | Psetfield_computed (_, _)
856862
| Psetfloatfield (_, _) | Pduprecord (_, _) | Pccall _ | Pdivint _
857-
| Pmodint _ | Pintcomp _ | Pfloatcomp _ | Pmakearray (_, _)
863+
| Pmodint _ | Pintcomp _ | Pfloatcomp _ | Pmakearray (_, _, _)
858864
| Pcompare_ints | Pcompare_floats | Pcompare_bints _
859865
| Pduparray (_, _) | Parrayrefu _ | Parraysetu _
860866
| Parrayrefs _ | Parraysets _ | Paddbint _ | Psubbint _ | Pmulbint _
@@ -1036,7 +1042,7 @@ and transl_prim_2 env p arg1 arg2 dbg =
10361042
| Pmakeblock (_, _, _, _) | Pfield _ | Psetfield_computed (_, _)
10371043
| Pfloatfield _
10381044
| Pduprecord (_, _) | Pccall _ | Praise _ | Poffsetint _ | Poffsetref _
1039-
| Pmakearray (_, _) | Pduparray (_, _) | Parraylength _ | Parraysetu _
1045+
| Pmakearray (_, _, _) | Pduparray (_, _) | Parraylength _ | Parraysetu _
10401046
| Parraysets _ | Pbintofint _ | Pintofbint _ | Pcvtbint (_, _)
10411047
| Pnegbint _ | Pbigarrayref (_, _, _, _) | Pbigarrayset (_, _, _, _)
10421048
| Pbigarraydim _ | Pbytes_set _ | Pbigstring_set _ | Pbbswap _
@@ -1092,7 +1098,7 @@ and transl_prim_3 env p arg1 arg2 arg3 dbg =
10921098
| Pfield _ | Psetfield (_, _, _) | Pfloatfield _ | Psetfloatfield (_, _)
10931099
| Pduprecord (_, _) | Pccall _ | Praise _ | Pdivint _ | Pmodint _ | Pintcomp _
10941100
| Pcompare_ints | Pcompare_floats | Pcompare_bints _
1095-
| Poffsetint _ | Poffsetref _ | Pfloatcomp _ | Pmakearray (_, _)
1101+
| Poffsetint _ | Poffsetref _ | Pfloatcomp _ | Pmakearray (_, _, _)
10961102
| Pduparray (_, _) | Parraylength _ | Parrayrefu _ | Parrayrefs _
10971103
| Pbintofint _ | Pintofbint _ | Pcvtbint (_, _) | Pnegbint _ | Paddbint _
10981104
| Psubbint _ | Pmulbint _ | Pdivbint _ | Pmodbint _ | Pandbint _ | Porbint _

asmcomp/comballoc.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ let rec combine i allocstate =
4747
assert (List.length dbginfo = 1);
4848
begin match get_mode mode allocstate with
4949
| Pending_alloc {reg; dbginfos; totalsz}
50-
when totalsz + sz <= (Config.max_young_wosize + 1) * Arch.size_addr ->
50+
when (totalsz + sz <= (Config.max_young_wosize + 1) * Arch.size_addr)
51+
|| mode = Lambda.Alloc_local ->
5152
let (next, state) =
5253
combine i.next
5354
(set_mode mode allocstate

bytecomp/bytegen.ml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -207,11 +207,11 @@ let rec size_of_lambda env = function
207207
in
208208
size_of_lambda env body
209209
| Lprim(Pmakeblock _, args, _) -> RHS_block (List.length args)
210-
| Lprim (Pmakearray ((Paddrarray|Pintarray), _), args, _) ->
210+
| Lprim (Pmakearray ((Paddrarray|Pintarray), _, _), args, _) ->
211211
RHS_block (List.length args)
212-
| Lprim (Pmakearray (Pfloatarray, _), args, _) ->
212+
| Lprim (Pmakearray (Pfloatarray, _, _), args, _) ->
213213
RHS_floatblock (List.length args)
214-
| Lprim (Pmakearray (Pgenarray, _), _, _) ->
214+
| Lprim (Pmakearray (Pgenarray, _, _), _, _) ->
215215
(* Pgenarray is excluded from recursive bindings by the
216216
check in Translcore.check_recursive_lambda *)
217217
RHS_nonrec
@@ -734,7 +734,7 @@ let rec comp_expr env exp sz cont =
734734
(Kpush::
735735
Kconst (Const_base (Const_int n))::
736736
Kaddint::cont)
737-
| Lprim(Pmakearray (kind, _), args, loc) ->
737+
| Lprim(Pmakearray (kind, _, _), args, loc) ->
738738
let cont = add_pseudo_event loc !compunit_name cont in
739739
begin match kind with
740740
Pintarray | Paddrarray ->
@@ -749,9 +749,9 @@ let rec comp_expr env exp sz cont =
749749
Kccall("caml_make_array", 1) :: cont)
750750
end
751751
| Lprim (Pduparray (kind, mutability),
752-
[Lprim (Pmakearray (kind',_),args,_)], loc) ->
752+
[Lprim (Pmakearray (kind',_,m),args,_)], loc) ->
753753
assert (kind = kind');
754-
comp_expr env (Lprim (Pmakearray (kind, mutability), args, loc)) sz cont
754+
comp_expr env (Lprim (Pmakearray (kind, mutability, m), args, loc)) sz cont
755755
| Lprim (Pduparray _, [arg], loc) ->
756756
let prim_obj_dup =
757757
Primitive.simple ~name:"caml_obj_dup" ~arity:1 ~alloc:true

lambda/lambda.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ type primitive =
8787
| Pstringlength | Pstringrefu | Pstringrefs
8888
| Pbyteslength | Pbytesrefu | Pbytessetu | Pbytesrefs | Pbytessets
8989
(* Array operations *)
90-
| Pmakearray of array_kind * mutable_flag
90+
| Pmakearray of array_kind * mutable_flag * alloc_mode
9191
| Pduparray of array_kind * mutable_flag
9292
| Parraylength of array_kind
9393
| Parrayrefu of array_kind

lambda/lambda.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ type primitive =
9393
| Pstringlength | Pstringrefu | Pstringrefs
9494
| Pbyteslength | Pbytesrefu | Pbytessetu | Pbytesrefs | Pbytessets
9595
(* Array operations *)
96-
| Pmakearray of array_kind * mutable_flag
96+
| Pmakearray of array_kind * mutable_flag * alloc_mode
9797
| Pduparray of array_kind * mutable_flag
9898
(** For [Pduparray], the argument must be an immutable array.
9999
The arguments of [Pduparray] give the kind and mutability of the

lambda/printlambda.ml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,8 +245,10 @@ let primitive ppf = function
245245
| Pbytessets -> fprintf ppf "bytes.set"
246246

247247
| Parraylength k -> fprintf ppf "array.length[%s]" (array_kind k)
248-
| Pmakearray (k, Mutable) -> fprintf ppf "makearray[%s]" (array_kind k)
249-
| Pmakearray (k, Immutable) -> fprintf ppf "makearray_imm[%s]" (array_kind k)
248+
| Pmakearray (k, mut, mode) ->
249+
let mode = match mode with Alloc_local -> "local" | Alloc_heap -> "" in
250+
let mut = match mut with Immutable -> "_imm" | Mutable -> "" in
251+
fprintf ppf "make%sarray%s[%s]" mode mut (array_kind k)
250252
| Pduparray (k, Mutable) -> fprintf ppf "duparray[%s]" (array_kind k)
251253
| Pduparray (k, Immutable) -> fprintf ppf "duparray_imm[%s]" (array_kind k)
252254
| Parrayrefu k -> fprintf ppf "array.unsafe_get[%s]" (array_kind k)

lambda/translcore.ml

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ let transl_extension_constructor ~scopes env path ext =
6262
let loc = of_location ~scopes ext.ext_loc in
6363
match ext.ext_kind with
6464
Text_decl _ ->
65+
(* Extension constructors are currently always Alloc_heap.
66+
They could be Alloc_local, but that would require changes
67+
to pattern typing, as patterns can close over them. *)
6568
Lprim (Pmakeblock (Obj.object_tag, Immutable, None, Alloc_heap),
6669
[Lconst (Const_base (Const_string (name, ext.ext_loc, None)));
6770
Lprim (prim_fresh_oo_id, [Lconst (const_int 0)], loc)],
@@ -409,6 +412,7 @@ and transl_exp0 ~in_new_scope ~scopes e =
409412
| Texp_array expr_list ->
410413
let kind = array_kind e in
411414
let ll = transl_list ~scopes expr_list in
415+
let mode = transl_alloc_mode e.exp_mode in
412416
begin try
413417
(* For native code the decision as to which compilation strategy to
414418
use is made later. This enables the Flambda passes to lift certain
@@ -418,6 +422,8 @@ and transl_exp0 ~in_new_scope ~scopes e =
418422
then begin
419423
raise Not_constant
420424
end;
425+
(* Pduparray only works in Alloc_heap mode *)
426+
if mode <> Alloc_heap then raise Not_constant;
421427
begin match List.map extract_constant ll with
422428
| exception Not_constant when kind = Pfloatarray ->
423429
(* We cannot currently lift [Pintarray] arrays safely in Flambda
@@ -433,7 +439,7 @@ and transl_exp0 ~in_new_scope ~scopes e =
433439
When not [Pfloatarray], the exception propagates to the handler
434440
below. *)
435441
let imm_array =
436-
Lprim (Pmakearray (kind, Immutable), ll,
442+
Lprim (Pmakearray (kind, Immutable, mode), ll,
437443
of_location ~scopes e.exp_loc)
438444
in
439445
Lprim (Pduparray (kind, Mutable), [imm_array],
@@ -452,7 +458,7 @@ and transl_exp0 ~in_new_scope ~scopes e =
452458
of_location ~scopes e.exp_loc)
453459
end
454460
with Not_constant ->
455-
Lprim(Pmakearray (kind, Mutable), ll,
461+
Lprim(Pmakearray (kind, Mutable, mode), ll,
456462
of_location ~scopes e.exp_loc)
457463
end
458464
| Texp_ifthenelse(cond, ifso, Some ifnot) ->
@@ -958,7 +964,7 @@ and transl_record ~scopes loc env mode fields repres opt_init_expr =
958964
(* Determine if there are "enough" fields (only relevant if this is a
959965
functional-style record update *)
960966
let no_init = match opt_init_expr with None -> true | _ -> false in
961-
if no_init || size < Config.max_young_wosize
967+
if no_init || size < Config.max_young_wosize || mode = Lambda.Alloc_local
962968
then begin
963969
(* Allocate new record with given fields (and remaining fields
964970
taken from init_expr if any *)
@@ -1009,7 +1015,7 @@ and transl_record ~scopes loc env mode fields repres opt_init_expr =
10091015
Lprim(Pmakeblock(tag, mut, Some shape, mode), ll, loc)
10101016
| Record_unboxed _ -> (match ll with [v] -> v | _ -> assert false)
10111017
| Record_float ->
1012-
Lprim(Pmakearray (Pfloatarray, mut), ll, loc)
1018+
Lprim(Pmakearray (Pfloatarray, mut, mode), ll, loc)
10131019
| Record_extension path ->
10141020
let slot = transl_extension_path loc env path in
10151021
Lprim(Pmakeblock(0, mut, Some (Pgenval :: shape), mode),
@@ -1045,6 +1051,7 @@ and transl_record ~scopes loc env mode fields repres opt_init_expr =
10451051
begin match opt_init_expr with
10461052
None -> assert false
10471053
| Some init_expr ->
1054+
assert (mode = Lambda.Alloc_heap); (* Pduprecord must be Alloc_heap *)
10481055
Llet(Strict, Pgenval, copy_id,
10491056
Lprim(Pduprecord (repres, size), [transl_exp ~scopes init_expr],
10501057
of_location ~scopes loc),

lambda/translprim.ml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ let primitives_table =
128128
"%setfield0", Primitive ((Psetfield(0, Pointer, Assignment)), 2);
129129
"%makeblock", Primitive ((Pmakeblock(0, Immutable, None, Alloc_heap)), 1);
130130
"%makemutable", Primitive ((Pmakeblock(0, Mutable, None, Alloc_heap)), 1);
131+
"%makelocalmutable",
132+
Primitive ((Pmakeblock(0, Mutable, None, Alloc_local)), 1);
131133
"%raise", Raise Raise_regular;
132134
"%reraise", Raise Raise_reraise;
133135
"%raise_notrace", Raise Raise_notrace;
@@ -747,7 +749,7 @@ let lambda_primitive_needs_event_after = function
747749
collect the call stack. *)
748750
| Pduprecord _ | Pccall _ | Pfloatofint | Pnegfloat | Pabsfloat
749751
| Paddfloat | Psubfloat | Pmulfloat | Pdivfloat | Pstringrefs | Pbytesrefs
750-
| Pbytessets | Pmakearray (Pgenarray, _) | Pduparray _
752+
| Pbytessets | Pmakearray (Pgenarray, _, _) | Pduparray _
751753
| Parrayrefu (Pgenarray | Pfloatarray) | Parraysetu (Pgenarray | Pfloatarray)
752754
| Parrayrefs _ | Parraysets _ | Pbintofint _ | Pcvtbint _ | Pnegbint _
753755
| Paddbint _ | Psubbint _ | Pmulbint _ | Pdivbint _ | Pmodbint _ | Pandbint _
@@ -768,7 +770,7 @@ let lambda_primitive_needs_event_after = function
768770
| Pasrint | Pintcomp _ | Poffsetint _ | Poffsetref _ | Pintoffloat
769771
| Pcompare_ints | Pcompare_floats
770772
| Pfloatcomp _ | Pstringlength | Pstringrefu | Pbyteslength | Pbytesrefu
771-
| Pbytessetu | Pmakearray ((Pintarray | Paddrarray | Pfloatarray), _)
773+
| Pbytessetu | Pmakearray ((Pintarray | Paddrarray | Pfloatarray), _, _)
772774
| Parraylength _ | Parrayrefu _ | Parraysetu _ | Pisint | Pisout
773775
| Pintofbint _ | Pctconst _ | Pbswap16 | Pint_as_pointer | Popaque ->
774776
false

middle_end/clambda_primitives.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ type primitive =
6565
| Pstringlength | Pstringrefu | Pstringrefs
6666
| Pbyteslength | Pbytesrefu | Pbytessetu | Pbytesrefs | Pbytessets
6767
(* Array operations *)
68-
| Pmakearray of array_kind * mutable_flag
68+
| Pmakearray of array_kind * mutable_flag * Lambda.alloc_mode
6969
| Pduparray of array_kind * mutable_flag
7070
(** For [Pduparray], the argument must be an immutable array.
7171
The arguments of [Pduparray] give the kind and mutability of the

middle_end/clambda_primitives.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ type primitive =
6565
| Pstringlength | Pstringrefu | Pstringrefs
6666
| Pbyteslength | Pbytesrefu | Pbytessetu | Pbytesrefs | Pbytessets
6767
(* Array operations *)
68-
| Pmakearray of array_kind * mutable_flag
68+
| Pmakearray of array_kind * mutable_flag * Lambda.alloc_mode
6969
(** For [Pmakearray], the list of arguments must not be empty. The empty
7070
array should be represented by a distinguished constant in the middle
7171
end. *)

middle_end/convert_primitives.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ let convert (prim : Lambda.primitive) : Clambda_primitives.primitive =
7676
| Pbytessetu -> Pbytessetu
7777
| Pbytesrefs -> Pbytesrefs
7878
| Pbytessets -> Pbytessets
79-
| Pmakearray (kind, mutability) -> Pmakearray (kind, mutability)
79+
| Pmakearray (kind, mutability, mode) -> Pmakearray (kind, mutability, mode)
8080
| Pduparray (kind, mutability) -> Pduparray (kind, mutability)
8181
| Parraylength kind -> Parraylength kind
8282
| Parrayrefu kind -> Parrayrefu kind

middle_end/flambda/inconstant_idents.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -343,9 +343,9 @@ module Inconstants (P:Param) (Backend:Backend_intf.S) = struct
343343
when toplevel ->
344344
List.iter (mark_loop ~toplevel curr) args
345345
*)
346-
| Prim (Pmakearray (Pfloatarray, Immutable), args, _) ->
346+
| Prim (Pmakearray (Pfloatarray, Immutable, _mode), args, _) ->
347347
mark_vars args curr
348-
| Prim (Pmakearray (Pfloatarray, Mutable), args, _) ->
348+
| Prim (Pmakearray (Pfloatarray, Mutable, _mode), args, _) ->
349349
(* CR-someday pchambart: Toplevel float arrays could always be
350350
statically allocated using an equivalent of the
351351
Initialize_symbol construction.

middle_end/flambda/lift_constants.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ let assign_symbols_and_collect_constant_definitions
9494
| Prim (Pfield _, _, _) ->
9595
Misc.fatal_errorf "[Pfield] with the wrong number of arguments"
9696
Flambda.print_named named
97-
| Prim (Pmakearray (Pfloatarray as kind, mutability), args, _) ->
97+
| Prim (Pmakearray (Pfloatarray as kind, mutability, _mode), args, _) ->
9898
assign_symbol ();
9999
record_definition (AA.Allocated_const (Array (kind, mutability, args)))
100100
| Prim (Pduparray (kind, mutability), [arg], _) ->

middle_end/flambda/simplify_primitives.ml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,15 +120,15 @@ let primitive (p : Clambda_primitives.primitive) (args, approxs)
120120
A.value_block tag (Array.of_list approxs), C.Benefit.zero
121121
| Praise _ ->
122122
expr, A.value_bottom, C.Benefit.zero
123-
| Pmakearray(_, _) when is_empty approxs ->
124-
Prim (Pmakeblock(0, Asttypes.Immutable, Some [], Alloc_heap), [], dbg),
123+
| Pmakearray(_, _, mode) when is_empty approxs ->
124+
Prim (Pmakeblock(0, Asttypes.Immutable, Some [], mode), [], dbg),
125125
A.value_block (Tag.create_exn 0) [||], C.Benefit.zero
126-
| Pmakearray (Pfloatarray, Mutable) ->
126+
| Pmakearray (Pfloatarray, Mutable, _) ->
127127
let approx =
128128
A.value_mutable_float_array ~size:(List.length args)
129129
in
130130
expr, approx, C.Benefit.zero
131-
| Pmakearray (Pfloatarray, Immutable) ->
131+
| Pmakearray (Pfloatarray, Immutable, _) ->
132132
let approx =
133133
A.value_immutable_float_array (Array.of_list approxs)
134134
in

middle_end/printclambda_primitives.ml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,10 @@ let primitive ppf (prim:Clambda_primitives.primitive) =
148148
| Pbytessets -> fprintf ppf "bytes.set"
149149

150150
| Parraylength k -> fprintf ppf "array.length[%s]" (array_kind k)
151-
| Pmakearray (k, Mutable) -> fprintf ppf "makearray[%s]" (array_kind k)
152-
| Pmakearray (k, Immutable) -> fprintf ppf "makearray_imm[%s]" (array_kind k)
151+
| Pmakearray (k, mut, mode) ->
152+
let mode = match mode with Alloc_local -> "local" | Alloc_heap -> "" in
153+
let mut = match mut with Mutable -> "" | Immutable -> "_imm" in
154+
fprintf ppf "make%sarray%s[%s]" mut mode (array_kind k)
153155
| Pduparray (k, Mutable) -> fprintf ppf "duparray[%s]" (array_kind k)
154156
| Pduparray (k, Immutable) -> fprintf ppf "duparray_imm[%s]" (array_kind k)
155157
| Parrayrefu k -> fprintf ppf "array.unsafe_get[%s]" (array_kind k)

0 commit comments

Comments
 (0)