Skip to content

Commit 8c40fe2

Browse files
committed
Refactor make_block
1 parent 8c1f5f6 commit 8c40fe2

File tree

4 files changed

+36
-26
lines changed

4 files changed

+36
-26
lines changed

backend/cmm_helpers.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1632,12 +1632,12 @@ let addr_array_init arr ofs newval dbg =
16321632
[array_indexing log2_size_addr arr ofs dbg; newval],
16331633
dbg )
16341634

1635-
let make_alloc ~mode dbg tag args =
1635+
let make_alloc ~mode dbg ~tag args =
16361636
make_alloc_generic ~mode
16371637
(fun _ arr ofs newval dbg -> addr_array_init arr ofs newval dbg)
16381638
dbg tag (List.length args) args
16391639

1640-
let make_float_alloc ~mode dbg tag args =
1640+
let make_float_alloc ~mode dbg ~tag args =
16411641
make_alloc_generic ~mode
16421642
(fun _ -> float_array_set)
16431643
dbg tag

backend/cmm_helpers.mli

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,11 +309,19 @@ end
309309

310310
(** Allocate a block of regular values with the given tag *)
311311
val make_alloc :
312-
mode:Lambda.alloc_mode -> Debuginfo.t -> int -> expression list -> expression
312+
mode:Lambda.alloc_mode ->
313+
Debuginfo.t ->
314+
tag:int ->
315+
expression list ->
316+
expression
313317

314318
(** Allocate a block of unboxed floats with the given tag *)
315319
val make_float_alloc :
316-
mode:Lambda.alloc_mode -> Debuginfo.t -> int -> expression list -> expression
320+
mode:Lambda.alloc_mode ->
321+
Debuginfo.t ->
322+
tag:int ->
323+
expression list ->
324+
expression
317325

318326
module Flat_suffix_element : sig
319327
type t =

middle_end/flambda2/to_cmm/to_cmm_primitive.ml

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -88,25 +88,27 @@ let check_alloc_fields = function
8888
let make_block ~dbg kind alloc_mode args =
8989
check_alloc_fields args;
9090
let mode = Alloc_mode.For_allocations.to_lambda alloc_mode in
91-
match (kind : P.Block_kind.t) with
92-
| Values (tag, _) -> C.make_alloc ~mode dbg (Tag.Scannable.to_int tag) args
93-
| Naked_floats ->
94-
C.make_float_alloc ~mode dbg (Tag.to_int Tag.double_array_tag) args
95-
| Mixed (tag, shape) ->
96-
let value_prefix_size = K.Mixed_block_shape.value_prefix_size shape in
97-
let flat_suffix =
98-
Array.map
99-
(fun (flat_elt : K.Flat_suffix_element.t) : C.Flat_suffix_element.t ->
100-
match flat_elt with
101-
| Tagged_immediate -> Tagged_immediate
102-
| Naked_float -> Naked_float
103-
| Naked_float32 -> Naked_float32
104-
| Naked_int32 -> Naked_int32
105-
| Naked_int64 | Naked_nativeint -> Naked_int64_or_nativeint)
106-
(K.Mixed_block_shape.flat_suffix shape)
107-
in
108-
C.make_mixed_alloc ~mode dbg ~tag:(Tag.Scannable.to_int tag)
109-
~value_prefix_size ~flat_suffix args
91+
let allocator, tag =
92+
match (kind : P.Block_kind.t) with
93+
| Values (tag, _) -> C.make_alloc, Tag.Scannable.to_tag tag
94+
| Naked_floats -> C.make_float_alloc, Tag.double_array_tag
95+
| Mixed (tag, shape) ->
96+
let value_prefix_size = K.Mixed_block_shape.value_prefix_size shape in
97+
let flat_suffix =
98+
Array.map
99+
(fun (flat_elt : K.Flat_suffix_element.t) : C.Flat_suffix_element.t ->
100+
match flat_elt with
101+
| Tagged_immediate -> Tagged_immediate
102+
| Naked_float -> Naked_float
103+
| Naked_float32 -> Naked_float32
104+
| Naked_int32 -> Naked_int32
105+
| Naked_int64 | Naked_nativeint -> Naked_int64_or_nativeint)
106+
(K.Mixed_block_shape.flat_suffix shape)
107+
in
108+
( C.make_mixed_alloc ~value_prefix_size ~flat_suffix,
109+
Tag.Scannable.to_tag tag )
110+
in
111+
allocator ~mode dbg ~tag:(Tag.to_int tag) args
110112

111113
let block_load ~dbg (kind : P.Block_access_kind.t) (mutability : Mutability.t)
112114
~block ~index =
@@ -159,9 +161,9 @@ let make_array ~dbg kind alloc_mode args =
159161
check_alloc_fields args;
160162
let mode = Alloc_mode.For_allocations.to_lambda alloc_mode in
161163
match (kind : P.Array_kind.t) with
162-
| Immediates | Values -> C.make_alloc ~mode dbg 0 args
164+
| Immediates | Values -> C.make_alloc ~mode dbg ~tag:0 args
163165
| Naked_floats ->
164-
C.make_float_alloc ~mode dbg (Tag.to_int Tag.double_array_tag) args
166+
C.make_float_alloc ~mode dbg ~tag:(Tag.to_int Tag.double_array_tag) args
165167
| Naked_float32s -> C.allocate_unboxed_float32_array ~elements:args mode dbg
166168
| Naked_int32s -> C.allocate_unboxed_int32_array ~elements:args mode dbg
167169
| Naked_int64s -> C.allocate_unboxed_int64_array ~elements:args mode dbg

middle_end/flambda2/to_cmm/to_cmm_set_of_closures.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,7 @@ let let_dynamic_set_of_closures0 env res ~body ~bound_vars set
615615
let tag = Tag.(to_int closure_tag) in
616616
C.make_alloc
617617
~mode:(Alloc_mode.For_allocations.to_lambda closure_alloc_mode)
618-
dbg tag l
618+
dbg ~tag l
619619
in
620620
let soc_var = Variable.create "*set_of_closures*" in
621621
let defining_expr = Env.simple csoc free_vars in

0 commit comments

Comments
 (0)