@@ -58,6 +58,7 @@ let black_closure_header sz = black_block_header Obj.closure_tag sz
58
58
let local_closure_header sz = local_block_header Obj. closure_tag sz
59
59
let infix_header ofs = block_header Obj. infix_tag ofs
60
60
let float_header = block_header Obj. double_tag (size_float / size_addr)
61
+ let float_local_header = local_block_header Obj. double_tag (size_float / size_addr)
61
62
let floatarray_header len =
62
63
(* Zero-sized float arrays have tag zero for consistency with
63
64
[caml_alloc_float_array]. *)
@@ -69,6 +70,9 @@ let string_header len =
69
70
let boxedint32_header = block_header Obj. custom_tag 2
70
71
let boxedint64_header = block_header Obj. custom_tag (1 + 8 / size_addr)
71
72
let boxedintnat_header = block_header Obj. custom_tag 2
73
+ let boxedint32_local_header = local_block_header Obj. custom_tag 2
74
+ let boxedint64_local_header = local_block_header Obj. custom_tag (1 + 8 / size_addr)
75
+ let boxedintnat_local_header = local_block_header Obj. custom_tag 2
72
76
let caml_nativeint_ops = " caml_nativeint_ops"
73
77
let caml_int32_ops = " caml_int32_ops"
74
78
let caml_int64_ops = " caml_int64_ops"
@@ -88,7 +92,10 @@ let closure_info ~arity ~startenv =
88
92
(add (shift_left (of_int startenv) 1 )
89
93
1n ))
90
94
91
- let alloc_float_header dbg = Cconst_natint (float_header, dbg)
95
+ let alloc_float_header mode dbg =
96
+ match mode with
97
+ | Lambda. Alloc_heap -> Cconst_natint (float_header, dbg)
98
+ | Lambda. Alloc_local -> Cconst_natint (float_local_header, dbg)
92
99
let alloc_floatarray_header len dbg = Cconst_natint (floatarray_header len, dbg)
93
100
let alloc_closure_header ~mode sz dbg =
94
101
match (mode : Lambda.alloc_mode ) with
@@ -97,9 +104,18 @@ let alloc_closure_header ~mode sz dbg =
97
104
let alloc_infix_header ofs dbg = Cconst_natint (infix_header ofs, dbg)
98
105
let alloc_closure_info ~arity ~startenv dbg =
99
106
Cconst_natint (closure_info ~arity ~startenv , dbg)
100
- let alloc_boxedint32_header dbg = Cconst_natint (boxedint32_header, dbg)
101
- let alloc_boxedint64_header dbg = Cconst_natint (boxedint64_header, dbg)
102
- let alloc_boxedintnat_header dbg = Cconst_natint (boxedintnat_header, dbg)
107
+ let alloc_boxedint32_header mode dbg =
108
+ match mode with
109
+ | Lambda. Alloc_heap -> Cconst_natint (boxedint32_header, dbg)
110
+ | Lambda. Alloc_local -> Cconst_natint (boxedint32_local_header, dbg)
111
+ let alloc_boxedint64_header mode dbg =
112
+ match mode with
113
+ | Lambda. Alloc_heap -> Cconst_natint (boxedint64_header, dbg)
114
+ | Lambda. Alloc_local -> Cconst_natint (boxedint64_local_header, dbg)
115
+ let alloc_boxedintnat_header mode dbg =
116
+ match mode with
117
+ | Lambda. Alloc_heap -> Cconst_natint (boxedintnat_header, dbg)
118
+ | Lambda. Alloc_local -> Cconst_natint (boxedintnat_local_header, dbg)
103
119
104
120
(* Integers *)
105
121
@@ -567,7 +583,7 @@ let test_bool dbg cmm =
567
583
568
584
(* Float *)
569
585
570
- let box_float dbg c = Cop (Calloc Alloc_heap , [alloc_float_header dbg; c], dbg)
586
+ let box_float dbg m c = Cop (Calloc m , [alloc_float_header m dbg; c], dbg)
571
587
572
588
let unbox_float dbg =
573
589
map_tail
@@ -742,7 +758,7 @@ let unboxed_float_array_ref arr ofs dbg =
742
758
Cop (Cload (Double_u , Mutable ),
743
759
[array_indexing log2_size_float arr ofs dbg], dbg)
744
760
let float_array_ref arr ofs dbg =
745
- box_float dbg (unboxed_float_array_ref arr ofs dbg)
761
+ box_float dbg Alloc_heap (unboxed_float_array_ref arr ofs dbg)
746
762
747
763
(* FIXME local arrays *)
748
764
let addr_array_set arr ofs newval dbg =
@@ -1021,22 +1037,22 @@ let operations_boxed_int (bi : Primitive.boxed_integer) =
1021
1037
| Pint32 -> caml_int32_ops
1022
1038
| Pint64 -> caml_int64_ops
1023
1039
1024
- let alloc_header_boxed_int (bi : Primitive.boxed_integer ) =
1040
+ let alloc_header_boxed_int (bi : Primitive.boxed_integer ) mode dbg =
1025
1041
match bi with
1026
- Pnativeint -> alloc_boxedintnat_header
1027
- | Pint32 -> alloc_boxedint32_header
1028
- | Pint64 -> alloc_boxedint64_header
1042
+ Pnativeint -> alloc_boxedintnat_header mode dbg
1043
+ | Pint32 -> alloc_boxedint32_header mode dbg
1044
+ | Pint64 -> alloc_boxedint64_header mode dbg
1029
1045
1030
- let box_int_gen dbg (bi : Primitive.boxed_integer ) arg =
1046
+ let box_int_gen dbg (bi : Primitive.boxed_integer ) mode arg =
1031
1047
let arg' =
1032
1048
if bi = Primitive. Pint32 && size_int = 8 then
1033
1049
if big_endian
1034
1050
then Cop (Clsl , [arg; Cconst_int (32 , dbg)], dbg)
1035
1051
else sign_extend_32 dbg arg
1036
1052
else arg
1037
1053
in
1038
- Cop (Calloc Alloc_heap ,
1039
- [alloc_header_boxed_int bi dbg;
1054
+ Cop (Calloc mode ,
1055
+ [alloc_header_boxed_int bi mode dbg;
1040
1056
Cconst_symbol (operations_boxed_int bi, dbg);
1041
1057
arg'], dbg)
1042
1058
@@ -1360,11 +1376,11 @@ let unaligned_load size ptr idx dbg =
1360
1376
| Thirty_two -> unaligned_load_32 ptr idx dbg
1361
1377
| Sixty_four -> unaligned_load_64 ptr idx dbg
1362
1378
1363
- let box_sized size dbg exp =
1379
+ let box_sized size mode dbg exp =
1364
1380
match (size : Clambda_primitives.memory_access_size ) with
1365
1381
| Sixteen -> tag_int exp dbg
1366
- | Thirty_two -> box_int_gen dbg Pint32 exp
1367
- | Sixty_four -> box_int_gen dbg Pint64 exp
1382
+ | Thirty_two -> box_int_gen dbg Pint32 mode exp
1383
+ | Sixty_four -> box_int_gen dbg Pint64 mode exp
1368
1384
1369
1385
(* Simplification of some primitives into C calls *)
1370
1386
@@ -1380,37 +1396,39 @@ let int64_native_prim name arity ~alloc =
1380
1396
~native_repr_args: (make_args arity)
1381
1397
~native_repr_res: u64
1382
1398
1399
+ (* FIXME: On 32-bit, these will do heap allocations
1400
+ even when local allocs are possible *)
1383
1401
let simplif_primitive_32bits :
1384
1402
Clambda_primitives. primitive -> Clambda_primitives. primitive = function
1385
- Pbintofint Pint64 -> Pccall (default_prim " caml_int64_of_int" )
1403
+ Pbintofint ( Pint64, _ ) -> Pccall (default_prim " caml_int64_of_int" )
1386
1404
| Pintofbint Pint64 -> Pccall (default_prim " caml_int64_to_int" )
1387
- | Pcvtbint (Pint32, Pint64) -> Pccall (default_prim " caml_int64_of_int32" )
1388
- | Pcvtbint (Pint64, Pint32) -> Pccall (default_prim " caml_int64_to_int32" )
1389
- | Pcvtbint (Pnativeint, Pint64) ->
1405
+ | Pcvtbint (Pint32, Pint64, _ ) -> Pccall (default_prim " caml_int64_of_int32" )
1406
+ | Pcvtbint (Pint64, Pint32, _ ) -> Pccall (default_prim " caml_int64_to_int32" )
1407
+ | Pcvtbint (Pnativeint, Pint64, _ ) ->
1390
1408
Pccall (default_prim " caml_int64_of_nativeint" )
1391
- | Pcvtbint (Pint64, Pnativeint) ->
1409
+ | Pcvtbint (Pint64, Pnativeint, _ ) ->
1392
1410
Pccall (default_prim " caml_int64_to_nativeint" )
1393
- | Pnegbint Pint64 -> Pccall (int64_native_prim " caml_int64_neg" 1
1411
+ | Pnegbint ( Pint64, _ ) -> Pccall (int64_native_prim " caml_int64_neg" 1
1394
1412
~alloc: false )
1395
- | Paddbint Pint64 -> Pccall (int64_native_prim " caml_int64_add" 2
1413
+ | Paddbint ( Pint64, _ ) -> Pccall (int64_native_prim " caml_int64_add" 2
1396
1414
~alloc: false )
1397
- | Psubbint Pint64 -> Pccall (int64_native_prim " caml_int64_sub" 2
1415
+ | Psubbint ( Pint64, _ ) -> Pccall (int64_native_prim " caml_int64_sub" 2
1398
1416
~alloc: false )
1399
- | Pmulbint Pint64 -> Pccall (int64_native_prim " caml_int64_mul" 2
1417
+ | Pmulbint ( Pint64, _ ) -> Pccall (int64_native_prim " caml_int64_mul" 2
1400
1418
~alloc: false )
1401
1419
| Pdivbint {size =Pint64 } -> Pccall (int64_native_prim " caml_int64_div" 2
1402
1420
~alloc: true )
1403
1421
| Pmodbint {size =Pint64 } -> Pccall (int64_native_prim " caml_int64_mod" 2
1404
1422
~alloc: true )
1405
- | Pandbint Pint64 -> Pccall (int64_native_prim " caml_int64_and" 2
1423
+ | Pandbint ( Pint64, _ ) -> Pccall (int64_native_prim " caml_int64_and" 2
1406
1424
~alloc: false )
1407
- | Porbint Pint64 -> Pccall (int64_native_prim " caml_int64_or" 2
1425
+ | Porbint ( Pint64, _ ) -> Pccall (int64_native_prim " caml_int64_or" 2
1408
1426
~alloc: false )
1409
- | Pxorbint Pint64 -> Pccall (int64_native_prim " caml_int64_xor" 2
1427
+ | Pxorbint ( Pint64, _ ) -> Pccall (int64_native_prim " caml_int64_xor" 2
1410
1428
~alloc: false )
1411
- | Plslbint Pint64 -> Pccall (default_prim " caml_int64_shift_left" )
1412
- | Plsrbint Pint64 -> Pccall (default_prim " caml_int64_shift_right_unsigned" )
1413
- | Pasrbint Pint64 -> Pccall (default_prim " caml_int64_shift_right" )
1429
+ | Plslbint ( Pint64, _ ) -> Pccall (default_prim " caml_int64_shift_left" )
1430
+ | Plsrbint ( Pint64, _ ) -> Pccall (default_prim " caml_int64_shift_right_unsigned" )
1431
+ | Pasrbint ( Pint64, _ ) -> Pccall (default_prim " caml_int64_shift_right" )
1414
1432
| Pbintcomp (Pint64, Lambda. Ceq) -> Pccall (default_prim " caml_equal" )
1415
1433
| Pbintcomp (Pint64, Lambda. Cne) -> Pccall (default_prim " caml_notequal" )
1416
1434
| Pbintcomp (Pint64, Lambda. Clt) -> Pccall (default_prim " caml_lessthan" )
@@ -1422,12 +1440,12 @@ let simplif_primitive_32bits :
1422
1440
Pccall (default_prim (" caml_ba_get_" ^ Int. to_string n))
1423
1441
| Pbigarrayset (_unsafe , n , Pbigarray_int64, _layout ) ->
1424
1442
Pccall (default_prim (" caml_ba_set_" ^ Int. to_string n))
1425
- | Pstring_load (Sixty_four, _ ) -> Pccall (default_prim " caml_string_get64" )
1426
- | Pbytes_load (Sixty_four, _ ) -> Pccall (default_prim " caml_bytes_get64" )
1443
+ | Pstring_load (Sixty_four, _ , _ ) -> Pccall (default_prim " caml_string_get64" )
1444
+ | Pbytes_load (Sixty_four, _ , _ ) -> Pccall (default_prim " caml_bytes_get64" )
1427
1445
| Pbytes_set (Sixty_four, _ ) -> Pccall (default_prim " caml_bytes_set64" )
1428
- | Pbigstring_load (Sixty_four,_ ) -> Pccall (default_prim " caml_ba_uint8_get64" )
1446
+ | Pbigstring_load (Sixty_four,_ , _ ) -> Pccall (default_prim " caml_ba_uint8_get64" )
1429
1447
| Pbigstring_set (Sixty_four,_ ) -> Pccall (default_prim " caml_ba_uint8_set64" )
1430
- | Pbbswap Pint64 -> Pccall (default_prim " caml_int64_bswap" )
1448
+ | Pbbswap ( Pint64, _ ) -> Pccall (default_prim " caml_int64_bswap" )
1431
1449
| p -> p
1432
1450
1433
1451
let simplif_primitive p : Clambda_primitives.primitive =
@@ -2324,16 +2342,16 @@ let stringref_safe arg1 arg2 dbg =
2324
2342
Cop (Cload (Byte_unsigned , Mutable ),
2325
2343
[add_int str idx dbg], dbg))))) dbg
2326
2344
2327
- let string_load size unsafe arg1 arg2 dbg =
2328
- box_sized size dbg
2345
+ let string_load size unsafe mode arg1 arg2 dbg =
2346
+ box_sized size mode dbg
2329
2347
(bind " str" arg1 (fun str ->
2330
2348
bind " index" (untag_int arg2 dbg) (fun idx ->
2331
2349
check_bound unsafe size dbg
2332
2350
(string_length str dbg)
2333
2351
idx (unaligned_load size str idx dbg))))
2334
2352
2335
- let bigstring_load size unsafe arg1 arg2 dbg =
2336
- box_sized size dbg
2353
+ let bigstring_load size unsafe mode arg1 arg2 dbg =
2354
+ box_sized size mode dbg
2337
2355
(bind " ba" arg1 (fun ba ->
2338
2356
bind " index" (untag_int arg2 dbg) (fun idx ->
2339
2357
bind " ba_data"
@@ -2406,7 +2424,7 @@ let arrayref_safe kind arg1 arg2 dbg =
2406
2424
(get_header_without_profinfo arr dbg) dbg; idx],
2407
2425
int_array_ref arr idx dbg)))
2408
2426
| Pfloatarray ->
2409
- box_float dbg (
2427
+ box_float dbg Alloc_heap (
2410
2428
bind " index" arg2 (fun idx ->
2411
2429
bind " arr" arg1 (fun arr ->
2412
2430
Csequence (
0 commit comments