Skip to content

Commit 23cf5a5

Browse files
committed
Merge flambda-backend changes
2 parents b3af0c4 + bcae5ff commit 23cf5a5

File tree

129 files changed

+1932
-1005
lines changed

Some content is hidden

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

129 files changed

+1932
-1005
lines changed

asmcomp/amd64/emit.mlp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1429,6 +1429,7 @@ let end_assembly() =
14291429
emit_global_label "data_end";
14301430
D.qword (const 0);
14311431

1432+
D.text ();
14321433
D.align 8; (* PR#7591 *)
14331434
emit_global_label "frametable";
14341435

@@ -1465,6 +1466,7 @@ let end_assembly() =
14651466
D.size frametable (ConstSub (ConstThis, ConstLabel frametable))
14661467
end;
14671468

1469+
D.data ();
14681470
emit_probe_notes ();
14691471

14701472
if system = S_linux then

asmcomp/cmm_helpers.ml

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -666,11 +666,14 @@ let field_address ptr n dbg =
666666
then ptr
667667
else Cop(Cadda, [ptr; Cconst_int(n * size_addr, dbg)], dbg)
668668

669+
let get_field_gen_given_memory_chunk memory_chunk mut ptr n dbg =
670+
Cop (Cload (memory_chunk, mut), [field_address ptr n dbg], dbg)
671+
669672
let get_field_gen mut ptr n dbg =
670-
Cop(Cload (Word_val, mut), [field_address ptr n dbg], dbg)
673+
get_field_gen_given_memory_chunk Word_val mut ptr n dbg
671674

672675
let get_field_codepointer mut ptr n dbg =
673-
Cop (Cload (Word_int, mut), [field_address ptr n dbg], dbg)
676+
get_field_gen_given_memory_chunk Word_int mut ptr n dbg
674677

675678
let set_field ptr n newval init dbg =
676679
Cop(Cstore (Word_val, init), [field_address ptr n dbg; newval], dbg)
@@ -2239,7 +2242,15 @@ let rec make_curry_apply result narity args_type args clos n =
22392242
:: args)
22402243
newclos (n - 1) )
22412244

2242-
let machtype_of_layout = function Lambda.Pvalue _ -> typ_val
2245+
let machtype_of_layout (layout : Lambda.layout) =
2246+
match layout with
2247+
| Ptop -> Misc.fatal_error "No machtype for layout [Ptop]"
2248+
| Pbottom -> Misc.fatal_error "No unique machtype for layout [Pbottom]"
2249+
| Punboxed_float -> typ_float
2250+
| Punboxed_int _ ->
2251+
(* Only 64-bit architectures, so this is always [typ_int] *)
2252+
typ_int
2253+
| Pvalue _ -> typ_val
22432254

22442255
let final_curry_function nlocal arity result =
22452256
let last_arg = V.create_local "arg" in
@@ -3140,5 +3151,11 @@ let emit_preallocated_blocks preallocated_blocks cont =
31403151
let c1 = emit_gc_roots_table ~symbols cont in
31413152
List.fold_left preallocate_block c1 preallocated_blocks
31423153

3143-
let kind_of_layout (Lambda.Pvalue kind) = Vval kind
3144-
3154+
let kind_of_layout (layout : Lambda.layout) =
3155+
match layout with
3156+
| Ptop | Pbottom ->
3157+
(* This is incorrect but only used for unboxing *)
3158+
Vval Pgenval
3159+
| Punboxed_float -> Vfloat
3160+
| Punboxed_int _ -> Vint
3161+
| Pvalue kind -> Vval kind

asmcomp/cmm_helpers.mli

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,10 +194,20 @@ val remove_unit : expression -> expression
194194
val field_address : expression -> int -> Debuginfo.t -> expression
195195

196196
(** [get_field_gen mut ptr n dbg] returns an expression for the access to the
197-
[n]th field of the block pointed to by [ptr] *)
197+
[n]th field of the block pointed to by [ptr]. The [memory_chunk] used is
198+
always [Word_val]. *)
198199
val get_field_gen :
199200
Asttypes.mutable_flag -> expression -> int -> Debuginfo.t -> expression
200201

202+
(** Like [get_field_gen] but allows use of a different [memory_chunk]. *)
203+
val get_field_gen_given_memory_chunk :
204+
Cmm.memory_chunk ->
205+
Asttypes.mutable_flag ->
206+
expression ->
207+
int ->
208+
Debuginfo.t ->
209+
expression
210+
201211
(** [set_field ptr n newval init dbg] returns an expression for setting the
202212
[n]th field of the block pointed to by [ptr] to [newval] *)
203213
val set_field :

asmcomp/cmmgen.ml

Lines changed: 85 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,20 @@ let mut_from_env env ptr =
117117
else Asttypes.Mutable
118118
| _ -> Asttypes.Mutable
119119

120-
let get_field env ptr n dbg =
120+
let get_field env layout ptr n dbg =
121121
let mut = mut_from_env env ptr in
122-
get_field_gen mut ptr n dbg
122+
let memory_chunk =
123+
match layout with
124+
| Pvalue Pintval | Punboxed_int _ -> Word_int
125+
| Pvalue _ -> Word_val
126+
| Punboxed_float -> Double
127+
| Ptop ->
128+
Misc.fatal_errorf "get_field with Ptop: %a" Debuginfo.print_compact dbg
129+
| Pbottom ->
130+
Misc.fatal_errorf "get_field with Pbottom: %a" Debuginfo.print_compact
131+
dbg
132+
in
133+
get_field_gen_given_memory_chunk memory_chunk mut ptr n dbg
123134

124135
type rhs_kind =
125136
| RHS_block of Lambda.alloc_mode * int
@@ -448,9 +459,19 @@ let rec transl env e =
448459
| Ugeneric_apply(clos, args, args_layout, result_layout, kind, dbg) ->
449460
let clos = transl env clos in
450461
let args = List.map (transl env) args in
451-
let args_type = List.map machtype_of_layout args_layout in
452-
let return = machtype_of_layout result_layout in
453-
generic_apply (mut_from_env env clos) clos args args_type return kind dbg
462+
if List.mem Pbottom args_layout then
463+
(* [machtype_of_layout] will fail on Pbottom, convert it to a sequence
464+
and remove the call, preserving the execution order. *)
465+
List.fold_left2 (fun rest arg arg_layout ->
466+
if arg_layout = Pbottom then
467+
arg
468+
else
469+
Csequence(remove_unit arg, rest)
470+
) (Ctuple []) args args_layout
471+
else
472+
let args_type = List.map machtype_of_layout args_layout in
473+
let return = machtype_of_layout result_layout in
474+
generic_apply (mut_from_env env clos) clos args args_type return kind dbg
454475
| Usend(kind, met, obj, args, args_layout, result_layout, pos, dbg) ->
455476
let met = transl env met in
456477
let obj = transl env obj in
@@ -596,6 +617,7 @@ let rec transl env e =
596617
| Pandbint _ | Porbint _ | Pxorbint _ | Plslbint _ | Plsrbint _
597618
| Pasrbint _ | Pbintcomp (_, _) | Pstring_load _ | Pbytes_load _
598619
| Pbytes_set _ | Pbigstring_load _ | Pbigstring_set _
620+
| Punbox_float | Pbox_float _ | Punbox_int _ | Pbox_int _
599621
| Pbbswap _), _)
600622
->
601623
fatal_error "Cmmgen.transl:prim"
@@ -731,27 +753,38 @@ and transl_catch (kind : Cmm.value_kind) env nfail ids body handler dbg =
731753
each argument. *)
732754
let report args =
733755
List.iter2
734-
(fun (_id, Pvalue kind, u) c ->
735-
let strict =
736-
match kind with
737-
| Pfloatval | Pboxedintval _ -> false
738-
| Pintval | Pgenval | Pvariant _ | Parrayval _ -> true
739-
in
740-
u := join_unboxed_number_kind ~strict !u
741-
(is_unboxed_number_cmm ~strict c)
756+
(fun (id, (layout : Lambda.layout), u) c ->
757+
match layout with
758+
| Ptop ->
759+
Misc.fatal_errorf "Variable %a with layout [Ptop] can't be compiled"
760+
VP.print id
761+
| Pbottom ->
762+
Misc.fatal_errorf
763+
"Variable %a with layout [Pbottom] can't be compiled"
764+
VP.print id
765+
| Punboxed_float | Punboxed_int _ ->
766+
u := No_unboxing
767+
| Pvalue kind ->
768+
let strict =
769+
match kind with
770+
| Pfloatval | Pboxedintval _ -> false
771+
| Pintval | Pgenval | Pvariant _ | Parrayval _ -> true
772+
in
773+
u := join_unboxed_number_kind ~strict !u
774+
(is_unboxed_number_cmm ~strict c)
742775
)
743776
ids args
744777
in
745778
let env_body = add_notify_catch nfail report env in
746779
let body = transl env_body body in
747780
let new_env, rewrite, ids =
748781
List.fold_right
749-
(fun (id, _kind, u) (env, rewrite, ids) ->
782+
(fun (id, layout, u) (env, rewrite, ids) ->
750783
match !u with
751784
| No_unboxing | Boxed (_, true) | No_result ->
752785
env,
753786
(fun x -> x) :: rewrite,
754-
(id, Cmm.typ_val) :: ids
787+
(id, machtype_of_layout layout) :: ids
755788
| Boxed (bn, false) ->
756789
let unboxed_id = V.create_local (VP.name id) in
757790
add_unboxed_id (VP.var id) unboxed_id bn env,
@@ -847,8 +880,8 @@ and transl_prim_1 env p arg dbg =
847880
Popaque ->
848881
opaque (transl env arg) dbg
849882
(* Heap operations *)
850-
| Pfield n ->
851-
get_field env (transl env arg) n dbg
883+
| Pfield (n, layout) ->
884+
get_field env layout (transl env arg) n dbg
852885
| Pfloatfield (n,mode) ->
853886
let ptr = transl env arg in
854887
box_float dbg mode (floatfield n ptr dbg)
@@ -864,7 +897,15 @@ and transl_prim_1 env p arg dbg =
864897
offsetint n (transl env arg) dbg
865898
| Poffsetref n ->
866899
offsetref n (transl env arg) dbg
900+
| Punbox_int bi ->
901+
transl_unbox_int dbg env bi arg
902+
| Pbox_int (bi, m) ->
903+
box_int dbg bi m (transl env arg)
867904
(* Floating-point operations *)
905+
| Punbox_float ->
906+
transl_unbox_float dbg env arg
907+
| Pbox_float m ->
908+
box_float dbg m (transl env arg)
868909
| Pfloatofint m ->
869910
box_float dbg m (Cop(Cfloatofint, [untag_int(transl env arg) dbg], dbg))
870911
| Pintoffloat ->
@@ -1099,6 +1140,7 @@ and transl_prim_2 env p arg1 arg2 dbg =
10991140
| Pnegbint _ | Pbigarrayref (_, _, _, _) | Pbigarrayset (_, _, _, _)
11001141
| Pbigarraydim _ | Pbytes_set _ | Pbigstring_set _ | Pbbswap _
11011142
| Pprobe_is_enabled _
1143+
| Punbox_float | Pbox_float _ | Punbox_int _ | Pbox_int _
11021144
->
11031145
fatal_errorf "Cmmgen.transl_prim_2: %a"
11041146
Printclambda_primitives.primitive p
@@ -1159,6 +1201,7 @@ and transl_prim_3 env p arg1 arg2 arg3 dbg =
11591201
| Pbigarrayref (_, _, _, _) | Pbigarrayset (_, _, _, _) | Pbigarraydim _
11601202
| Pstring_load _ | Pbytes_load _ | Pbigstring_load _ | Pbbswap _
11611203
| Pprobe_is_enabled _
1204+
| Punbox_float | Pbox_float _ | Punbox_int _ | Pbox_int _
11621205
->
11631206
fatal_errorf "Cmmgen.transl_prim_3: %a"
11641207
Printclambda_primitives.primitive p
@@ -1181,7 +1224,7 @@ and transl_unbox_sized size dbg env exp =
11811224
| Thirty_two -> transl_unbox_int dbg env Pint32 exp
11821225
| Sixty_four -> transl_unbox_int dbg env Pint64 exp
11831226

1184-
and transl_let env str (Pvalue kind : Lambda.layout) id exp transl_body =
1227+
and transl_let_value env str (kind : Lambda.value_kind) id exp transl_body =
11851228
let dbg = Debuginfo.none in
11861229
let cexp = transl env exp in
11871230
let unboxing =
@@ -1233,6 +1276,30 @@ and transl_let env str (Pvalue kind : Lambda.layout) id exp transl_body =
12331276
| Mutable, bn -> Clet_mut (v, typ_of_boxed_number bn, cexp, body)
12341277
end
12351278

1279+
and transl_let env str (layout : Lambda.layout) id exp transl_body =
1280+
match layout with
1281+
| Ptop ->
1282+
Misc.fatal_errorf "Variable %a with layout [Ptop] can't be compiled"
1283+
VP.print id
1284+
| Pbottom ->
1285+
let cexp = transl env exp in
1286+
(* N.B. [body] must still be traversed even if [exp] will never return:
1287+
there may be constant closures inside that need lifting out. *)
1288+
let _cbody : expression = transl_body env in
1289+
cexp
1290+
| Punboxed_float | Punboxed_int _ -> begin
1291+
let cexp = transl env exp in
1292+
let cbody = transl_body env in
1293+
match str with
1294+
| (Immutable | Immutable_unique) ->
1295+
Clet(id, cexp, cbody)
1296+
| Mutable ->
1297+
let typ = machtype_of_layout layout in
1298+
Clet_mut(id, typ, cexp, cbody)
1299+
end
1300+
| Pvalue kind ->
1301+
transl_let_value env str kind id exp transl_body
1302+
12361303
and make_catch (kind : Cmm.value_kind) ncatch body handler dbg = match body with
12371304
| Cexit (nexit,[]) when nexit=ncatch -> handler
12381305
| _ -> ccatch (ncatch, [], body, handler, dbg, kind)

asmcomp/emitaux.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ let emit_frames a =
203203
not (Debuginfo.is_none d.Debuginfo.alloc_dbg)) dbgs
204204
then 3 else 2
205205
in
206-
a.efa_code_label fd.fd_lbl;
206+
a.efa_label_rel fd.fd_lbl 0l;
207207
efa_16_checked (fd.fd_frame_size + flags);
208208
efa_16_checked (List.length fd.fd_live_offset);
209209
List.iter efa_16_checked fd.fd_live_offset;

boot/ocamlc

7.22 KB
Binary file not shown.

boot/ocamllex

-40 Bytes
Binary file not shown.

bytecomp/bytegen.ml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ let rec is_tailcall = function
109109
from the tail call optimization? *)
110110

111111
let preserve_tailcall_for_prim = function
112-
Popaque | Psequor | Psequand
113-
| Pobj_magic ->
112+
Popaque _ | Psequor | Psequand
113+
| Pobj_magic _ ->
114114
true
115115
| Pbytes_to_string | Pbytes_of_string
116116
| Parray_to_iarray | Parray_of_iarray
@@ -123,6 +123,7 @@ let preserve_tailcall_for_prim = function
123123
| Pdivint _ | Pmodint _ | Pandint | Porint | Pxorint | Plslint | Plsrint
124124
| Pasrint | Pintcomp _ | Poffsetint _ | Poffsetref _ | Pintoffloat
125125
| Pfloatofint _ | Pnegfloat _ | Pabsfloat _ | Paddfloat _ | Psubfloat _ | Pmulfloat _
126+
| Punbox_float | Pbox_float _ | Punbox_int _ | Pbox_int _
126127
| Pdivfloat _ | Pfloatcomp _ | Pstringlength | Pstringrefu | Pstringrefs
127128
| Pcompare_ints | Pcompare_floats | Pcompare_bints _
128129
| Pbyteslength | Pbytesrefu | Pbytessetu | Pbytesrefs | Pbytessets
@@ -526,14 +527,15 @@ let comp_primitive p args =
526527
(* The cases below are handled in [comp_expr] before the [comp_primitive] call
527528
(in the order in which they appear below),
528529
so they should never be reached in this function. *)
529-
| Pignore | Popaque | Pobj_magic
530+
| Pignore | Popaque _ | Pobj_magic _
530531
| Pnot | Psequand | Psequor
531532
| Praise _
532533
| Pmakearray _ | Pduparray _
533534
| Pfloatcomp _
534535
| Pmakeblock _
535536
| Pmakefloatblock _
536537
| Pprobe_is_enabled _
538+
| Punbox_float | Pbox_float _ | Punbox_int _ | Pbox_int _
537539
->
538540
fatal_error "Bytegen.comp_primitive"
539541

@@ -707,7 +709,11 @@ let rec comp_expr env exp sz cont =
707709
in
708710
comp_init env sz decl_size
709711
end
710-
| Lprim((Popaque | Pobj_magic), [arg], _) ->
712+
| Lprim((Popaque _ | Pobj_magic _), [arg], _) ->
713+
comp_expr env arg sz cont
714+
| Lprim((Pbox_float _ | Punbox_float), [arg], _) ->
715+
comp_expr env arg sz cont
716+
| Lprim((Pbox_int _ | Punbox_int _), [arg], _) ->
711717
comp_expr env arg sz cont
712718
| Lprim(Pignore, [arg], _) ->
713719
comp_expr env arg sz (add_const_unit cont)

0 commit comments

Comments
 (0)