@@ -131,6 +131,37 @@ let convert_array_kind (kind : L.array_kind) : converted_array_kind =
131
131
| Pintarray -> Array_kind Immediates
132
132
| Pfloatarray -> Array_kind Naked_floats
133
133
134
+ type converted_array_ref_kind =
135
+ | Array_ref_kind of P.Array_ref_kind .t
136
+ | Float_array_opt_dynamic_ref of Alloc_mode.For_allocations .t
137
+
138
+ let convert_array_ref_kind
139
+ ~current_region (kind : L.array_ref_kind ) : converted_array_ref_kind =
140
+ match kind with
141
+ | Pgenarray_ref mode ->
142
+ check_float_array_optimisation_enabled () ;
143
+ Float_array_opt_dynamic_ref
144
+ (Alloc_mode.For_allocations. from_lambda ~current_region mode)
145
+ | Paddrarray_ref -> Array_ref_kind Values
146
+ | Pintarray_ref -> Array_ref_kind Immediates
147
+ | Pfloatarray_ref mode ->
148
+ Array_ref_kind
149
+ (Naked_floats (Alloc_mode.For_allocations. from_lambda ~current_region mode))
150
+
151
+ type converted_array_set_kind =
152
+ | Array_set_kind of P.Array_set_kind .t
153
+ | Float_array_opt_dynamic_set of Alloc_mode.For_assignments .t
154
+
155
+ let convert_array_set_kind (kind : L.array_set_kind ) : converted_array_set_kind =
156
+ match kind with
157
+ | Pgenarray_set mode ->
158
+ check_float_array_optimisation_enabled () ;
159
+ Float_array_opt_dynamic_set (Alloc_mode.For_assignments. from_lambda mode)
160
+ | Paddrarray_set mode ->
161
+ Array_set_kind (Values (Alloc_mode.For_assignments. from_lambda mode))
162
+ | Pintarray_set -> Array_set_kind Immediates
163
+ | Pfloatarray_set -> Array_set_kind Naked_floats
164
+
134
165
type converted_duplicate_array_kind =
135
166
| Duplicate_array_kind of P.Duplicate_array_kind .t
136
167
| Float_array_opt_dynamic
@@ -491,20 +522,26 @@ let check_array_access ~dbg ~array ~index primitive : H.expr_primitive =
491
522
~conditions: (array_access_validity_condition array index)
492
523
~dbg
493
524
494
- let array_load_unsafe ~array ~index (array_kind : P.Array_kind .t )
495
- ~current_region : H. expr_primitive =
496
- match array_kind with
525
+ let array_load_unsafe ~array ~index (array_ref_kind : P.Array_ref_kind .t )
526
+ ~current_region : H. expr_primitive =
527
+ match array_ref_kind with
497
528
| Immediates | Values ->
498
- Binary (Array_load (array_kind , Mutable ), array , index)
499
- | Naked_floats ->
500
- box_float L. alloc_heap
529
+ Binary (Array_load (array_ref_kind , Mutable ), array , index)
530
+ | Naked_floats mode ->
531
+ box_float mode
501
532
(Binary (Array_load (Naked_floats , Mutable ), array , index))
502
533
~current_region
503
534
504
- let array_set_unsafe ~array ~index ~new_value (array_kind : P.Array_kind .t ) :
535
+ let array_set_unsafe ~array ~index ~new_value (array_set_kind : P.Array_set_kind .t ) :
505
536
H. expr_primitive =
506
- match array_kind with
507
- | Immediates | Values ->
537
+ match array_set_kind with
538
+ | Immediates
539
+ Ternary
540
+ ( Array_set (array_kind, Assignment Alloc_mode.For_assignments. heap),
541
+ array ,
542
+ index,
543
+ new_value )
544
+ | Values ->
508
545
Ternary
509
546
( Array_set (array_kind, Assignment Alloc_mode.For_assignments. heap),
510
547
array ,
@@ -518,17 +555,29 @@ let array_set_unsafe ~array ~index ~new_value (array_kind : P.Array_kind.t) :
518
555
index,
519
556
unbox_float new_value )
520
557
521
- let [@ inline always] match_on_array_kind ~array array_kind f : H. expr_primitive =
522
- match convert_array_kind array_kind with
523
- | Array_kind ((Immediates | Values ) as array_kind ) -> f array_kind
524
- | Array_kind Naked_floats -> f P.Array_kind. Naked_floats
525
- | Float_array_opt_dynamic ->
558
+ let [@ inline always] match_on_array_ref_kind ~current_region ~array array_ref_kind f
559
+ : H. expr_primitive =
560
+ match convert_array_ref_kind ~current_region array_ref_kind with
561
+ | Array_ref_kind array_ref_kind -> f array_ref_kind
562
+ | Float_array_opt_dynamic_ref mode ->
563
+ (* CR keryan: we should push the ITE as low as possible to avoid duplicating
564
+ too much *)
565
+ If_then_else
566
+ ( Unary (Is_flat_float_array , array ),
567
+ f (P.Array_ref_kind. Naked_floats mode),
568
+ f P.Array_ref_kind. Values )
569
+
570
+ let [@ inline always] match_on_array_set_kind ~array array_ref_kind f
571
+ : H. expr_primitive =
572
+ match convert_array_set_kind array_ref_kind with
573
+ | Array_set_kind array_set_kind -> f array_set_kind
574
+ | Float_array_opt_dynamic_set mode ->
526
575
(* CR keryan: we should push the ITE as low as possible to avoid duplicating
527
576
too much *)
528
577
If_then_else
529
578
( Unary (Is_flat_float_array , array ),
530
- f P.Array_kind . Naked_floats ,
531
- f P.Array_kind .Values )
579
+ f P.Array_set_kind . Naked_floats ,
580
+ f ( P.Array_set_kind .Values mode) )
532
581
533
582
(* Safe arith (div/mod by zero) *)
534
583
let checked_arith_op ~dbg (bi : Lambda.boxed_integer option ) op mode arg1 arg2
@@ -969,22 +1018,22 @@ let convert_lprim ~big_endian (prim : L.primitive) (args : Simple.t list)
969
1018
| Pmodbint { size = Pnativeint ; is_safe = Safe ; mode } , [arg1; arg2] ->
970
1019
checked_arith_op ~dbg (Some Pnativeint ) Mod (Some mode) arg1 arg2
971
1020
~current_region
972
- | Parrayrefu array_kind , [array ; index] ->
1021
+ | Parrayrefu array_ref_kind , [array ; index] ->
973
1022
(* For this and the following cases we will end up relying on the backend to
974
1023
CSE the two accesses to the array's header word in the [Pgenarray]
975
1024
case. *)
976
- match_on_array_kind ~ array array_kind
1025
+ match_on_array_ref_kind ~current_region ~ array array_ref_kind
977
1026
(array_load_unsafe ~array ~index ~current_region )
978
- | Parrayrefs array_kind , [array ; index] ->
1027
+ | Parrayrefs array_ref_kind , [array ; index] ->
979
1028
check_array_access ~dbg ~array ~index
980
- (match_on_array_kind ~ array array_kind
1029
+ (match_on_array_ref_kind ~current_region ~ array array_ref_kind
981
1030
(array_load_unsafe ~array ~index ~current_region ))
982
- | Parraysetu array_kind , [array ; index; new_value] ->
983
- match_on_array_kind ~array array_kind
1031
+ | Parraysetu array_set_kind , [array ; index; new_value] ->
1032
+ match_on_array_set_kind ~array array_set_kind
984
1033
(array_set_unsafe ~array ~index ~new_value )
985
- | Parraysets array_kind , [array ; index; new_value] ->
1034
+ | Parraysets array_set_kind , [array ; index; new_value] ->
986
1035
check_array_access ~dbg ~array ~index
987
- (match_on_array_kind ~array array_kind
1036
+ (match_on_array_set_kind ~array array_set_kind
988
1037
(array_set_unsafe ~array ~index ~new_value ))
989
1038
| Pbytessetu (* unsafe *) , [bytes; index; new_value] ->
990
1039
bytes_like_set_unsafe ~access_size: Eight Bytes bytes index new_value
@@ -1194,17 +1243,21 @@ let convert_lprim ~big_endian (prim : L.primitive) (args : Simple.t list)
1194
1243
| Plsrbint _ | Pasrbint _ | Pfield_computed _ | Pdivbint _ | Pmodbint _
1195
1244
| Psetfloatfield _ | Pbintcomp _ | Pbigstring_load_16 _
1196
1245
| Pbigstring_load_32 _ | Pbigstring_load_64 _
1197
- | Parrayrefu (Pgenarray | Paddrarray | Pintarray | Pfloatarray )
1198
- | Parrayrefs (Pgenarray | Paddrarray | Pintarray | Pfloatarray )
1246
+ | Parrayrefu
1247
+ (Pgenarray_ref _ | Paddrarray_ref | Pintarray_ref | Pfloatarray_ref _)
1248
+ | Parrayrefs
1249
+ (Pgenarray_ref _ | Paddrarray_ref | Pintarray_ref | Pfloatarray_ref _)
1199
1250
| Pcompare_ints | Pcompare_floats | Pcompare_bints _ ),
1200
1251
([] | [_] | _ :: _ :: _ :: _ ) ) ->
1201
1252
Misc. fatal_errorf
1202
1253
" Closure_conversion.convert_primitive: Wrong arity for binary primitive \
1203
1254
%a (%a)"
1204
1255
Printlambda. primitive prim H. print_list_of_simple_or_prim args
1205
1256
| ( ( Psetfield_computed _ | Pbytessetu | Pbytessets
1206
- | Parraysetu (Pgenarray | Paddrarray | Pintarray | Pfloatarray )
1207
- | Parraysets (Pgenarray | Paddrarray | Pintarray | Pfloatarray )
1257
+ | Parraysetu
1258
+ (Pgenarray_set _ | Paddrarray_set _ | Pintarray_set | Pfloatarray_set )
1259
+ | Parraysets
1260
+ (Pgenarray_set _ | Paddrarray_set _ | Pintarray_set | Pfloatarray_set )
1208
1261
| Pbytes_set_16 _ | Pbytes_set_32 _ | Pbytes_set_64 _
1209
1262
| Pbigstring_set_16 _ | Pbigstring_set_32 _ | Pbigstring_set_64 _ ),
1210
1263
([] | [_] | [_; _] | _ :: _ :: _ :: _ :: _ ) ) ->
0 commit comments