Skip to content

Commit cb4b0a6

Browse files
committed
Allow %arrayblit at all layouts
1 parent a417e98 commit cb4b0a6

File tree

3 files changed

+20
-17
lines changed

3 files changed

+20
-17
lines changed

lambda/lambda.ml

+5-8
Original file line numberDiff line numberDiff line change
@@ -2399,8 +2399,8 @@ let array_set_kind mode = function
23992399
| Pgcscannableproductarray kinds -> Pgcscannableproductarray_set (mode, kinds)
24002400
| Pgcignorableproductarray kinds -> Pgcignorableproductarray_set kinds
24012401

2402-
let array_ref_kind_of_array_set_kind_for_unboxed_types_and_int
2403-
(kind : array_set_kind) ~print_array_set_kind : array_ref_kind =
2402+
let array_ref_kind_of_array_set_kind (kind : array_set_kind) mode
2403+
: array_ref_kind =
24042404
match kind with
24052405
| Pintarray_set -> Pintarray_ref
24062406
| Punboxedfloatarray_set uf -> Punboxedfloatarray_ref uf
@@ -2410,12 +2410,9 @@ let array_ref_kind_of_array_set_kind_for_unboxed_types_and_int
24102410
Pgcscannableproductarray_ref scannables
24112411
| Pgcignorableproductarray_set ignorables ->
24122412
Pgcignorableproductarray_ref ignorables
2413-
| Pgenarray_set _
2414-
| Paddrarray_set _
2415-
| Pfloatarray_set ->
2416-
Misc.fatal_errorf "Array set kind %a cannot be converted via \
2417-
array_ref_kind_of_array_set_kind_for_unboxed_types_and_int"
2418-
print_array_set_kind kind
2413+
| Pgenarray_set _ -> Pgenarray_ref mode
2414+
| Paddrarray_set _ -> Paddrarray_ref
2415+
| Pfloatarray_set -> Pfloatarray_ref mode
24192416

24202417
let may_allocate_in_region lam =
24212418
(* loop_region raises, if the lambda might allocate in parent region *)

lambda/lambda.mli

+4-5
Original file line numberDiff line numberDiff line change
@@ -1169,11 +1169,10 @@ val array_ref_kind : locality_mode -> array_kind -> array_ref_kind
11691169
(** The mode will be discarded if unnecessary for the given [array_kind] *)
11701170
val array_set_kind : modify_mode -> array_kind -> array_set_kind
11711171

1172-
(** Note that this fails on [Pfloatarray_set] *)
1173-
val array_ref_kind_of_array_set_kind_for_unboxed_types_and_int
1174-
: array_set_kind
1175-
-> print_array_set_kind:(Format.formatter -> array_set_kind -> unit)
1176-
-> array_ref_kind
1172+
(** Any mode information in the given [array_set_kind] is ignored. Any mode
1173+
in the return value always comes from the [locality_mode] parameter. *)
1174+
val array_ref_kind_of_array_set_kind
1175+
: array_set_kind -> locality_mode -> array_ref_kind
11771176

11781177
(* Returns true if the given lambda can allocate on the local stack *)
11791178
val may_allocate_in_region : lambda -> bool

middle_end/flambda2/from_lambda/lambda_to_lambda_transforms.ml

+11-4
Original file line numberDiff line numberDiff line change
@@ -462,8 +462,11 @@ let makearray_dynamic env (lambda_array_kind : L.array_kind)
462462
let arrayblit env ~(src_mutability : L.mutable_flag)
463463
~(dst_array_set_kind : L.array_set_kind) args loc =
464464
let src_array_ref_kind =
465-
L.array_ref_kind_of_array_set_kind_for_unboxed_types_and_int
466-
dst_array_set_kind ~print_array_set_kind:Printlambda.array_set_kind
465+
(* We don't expect any allocation (e.g. occurring from the reading of a
466+
[float array]) to persist after simplification. We use [alloc_local] just
467+
in case that simplification doesn't happen for some reason (this seems
468+
unlikely). *)
469+
L.array_ref_kind_of_array_set_kind dst_array_set_kind L.alloc_local
467470
in
468471
match args with
469472
| [src_expr; src_start_pos_expr; dst_expr; dst_start_pos_expr; length_expr] ->
@@ -521,8 +524,12 @@ let arrayblit env ~(src_mutability : L.mutable_flag)
521524
let env, copy_backwards = make_loop env Downto in
522525
let env, copy_forwards = make_loop env Upto in
523526
let body =
524-
L.Lifthenelse
525-
(must_copy_backwards, copy_backwards, copy_forwards, L.layout_unit)
527+
(* The region is expected to be redundant (see comment above about
528+
modes). *)
529+
L.Lregion
530+
( L.Lifthenelse
531+
(must_copy_backwards, copy_backwards, copy_forwards, L.layout_unit),
532+
L.layout_unit )
526533
in
527534
let expr =
528535
(* Preserve right-to-left evaluation order. *)

0 commit comments

Comments
 (0)