Skip to content

Commit 36a2e96

Browse files
lthlsTheNumbat
authored andcommitted
Support for mixed blocks in Flambda2 types (#2533)
1 parent c6fabbe commit 36a2e96

Some content is hidden

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

55 files changed

+1649
-1318
lines changed

middle_end/flambda2/classic_mode_types/value_approximation.ml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ type 'code t =
2828
code : 'code;
2929
symbol : Symbol.t option
3030
}
31-
| Block_approximation of Tag.t * 'code t array * Alloc_mode.For_types.t
31+
| Block_approximation of
32+
Tag.Scannable.t * 'code t array * Alloc_mode.For_types.t
3233

3334
let rec print fmt = function
3435
| Value_unknown -> Format.fprintf fmt "?"
@@ -41,7 +42,8 @@ let rec print fmt = function
4142
if len < 1
4243
then Format.fprintf fmt "{}"
4344
else (
44-
Format.fprintf fmt "@[<hov 2>{%a:%a" Tag.print tag print fields.(0);
45+
Format.fprintf fmt "@[<hov 2>{%a:%a" Tag.Scannable.print tag print
46+
fields.(0);
4547
for i = 1 to len - 1 do
4648
Format.fprintf fmt "@ %a" print fields.(i)
4749
done;

middle_end/flambda2/classic_mode_types/value_approximation.mli

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ type 'code t =
2828
code : 'code;
2929
symbol : Symbol.t option
3030
}
31-
| Block_approximation of Tag.t * 'code t array * Alloc_mode.For_types.t
31+
| Block_approximation of
32+
Tag.Scannable.t * 'code t array * Alloc_mode.For_types.t
3233

3334
val print : Format.formatter -> 'a t -> unit
3435

middle_end/flambda2/from_lambda/closure_conversion.ml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,7 +1055,6 @@ let close_let acc env let_bound_ids_with_kinds user_visible defining_expr
10551055
( Variadic
10561056
(Make_block (Values (tag, _), Immutable, alloc_mode), fields),
10571057
_ ) -> (
1058-
let tag' = Tag.Scannable.to_tag tag in
10591058
let approxs =
10601059
List.map (find_value_approximation body_env) fields |> Array.of_list
10611060
in
@@ -1073,7 +1072,7 @@ let close_let acc env let_bound_ids_with_kinds user_visible defining_expr
10731072
let acc =
10741073
Acc.add_symbol_approximation acc sym
10751074
(Value_approximation.Block_approximation
1076-
(tag', approxs, Alloc_mode.For_allocations.as_type alloc_mode))
1075+
(tag, approxs, Alloc_mode.For_allocations.as_type alloc_mode))
10771076
in
10781077
body acc body_env
10791078
| Computed_static static_fields ->
@@ -1097,7 +1096,7 @@ let close_let acc env let_bound_ids_with_kinds user_visible defining_expr
10971096
in
10981097
let approx =
10991098
Value_approximation.Block_approximation
1100-
(tag', approxs, Alloc_mode.For_allocations.as_type alloc_mode)
1099+
(tag, approxs, Alloc_mode.For_allocations.as_type alloc_mode)
11011100
in
11021101
let acc = Acc.add_symbol_approximation acc symbol approx in
11031102
let acc, body = body acc body_env in
@@ -1107,7 +1106,7 @@ let close_let acc env let_bound_ids_with_kinds user_visible defining_expr
11071106
defining_expr ~body
11081107
| Dynamic_block ->
11091108
let body_env =
1110-
Env.add_block_approximation body_env var tag' approxs
1109+
Env.add_block_approximation body_env var tag approxs
11111110
(Alloc_mode.For_allocations.as_type alloc_mode)
11121111
in
11131112
bind acc body_env)

middle_end/flambda2/from_lambda/closure_conversion_aux.ml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,6 @@ module Acc = struct
494494
| Tagged_immediate i -> Value_int i
495495
| Dynamically_computed _ -> Value_unknown
496496
in
497-
let tag = Tag.Scannable.to_tag tag in
498497
let fields = List.map approx_of_field fields |> Array.of_list in
499498
Block_approximation (tag, fields, Alloc_mode.For_types.unknown ())
500499
else Value_unknown

middle_end/flambda2/from_lambda/closure_conversion_aux.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ module Env : sig
169169
val add_block_approximation :
170170
t ->
171171
Variable.t ->
172-
Tag.t ->
172+
Tag.Scannable.t ->
173173
value_approximation array ->
174174
Alloc_mode.For_types.t ->
175175
t

middle_end/flambda2/from_lambda/lambda_to_flambda_primitives.ml

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,8 +1002,8 @@ let convert_lprim ~big_endian (prim : L.primitive) (args : Simple.t list list)
10021002
let mode = Alloc_mode.For_allocations.from_lambda mode ~current_region in
10031003
let mutability = Mutability.from_lambda mutability in
10041004
let tag = Tag.Scannable.create_exn tag in
1005-
let shape = P.Mixed_block_kind.from_lambda shape in
1006-
[Variadic (Make_mixed_block (tag, shape, mutability, mode), args)]
1005+
let shape = K.Mixed_block_shape.from_lambda shape in
1006+
[Variadic (Make_block (Mixed (tag, shape), mutability, mode), args)]
10071007
| Pmakearray (lambda_array_kind, mutability, mode), _ -> (
10081008
let args = List.flatten args in
10091009
let mode = Alloc_mode.For_allocations.from_lambda mode ~current_region in
@@ -1468,7 +1468,7 @@ let convert_lprim ~big_endian (prim : L.primitive) (args : Simple.t list list)
14681468
Naked_floats { size = Unknown }
14691469
in
14701470
[Binary (Block_load (block_access, mutability), arg, Simple field)]
1471-
| Pmixedfield (field, read, sem), [[arg]] -> (
1471+
| Pmixedfield (field, read, shape, sem), [[arg]] -> (
14721472
let imm = Targetint_31_63.of_int field in
14731473
check_non_negative_imm imm "Pmixedfield";
14741474
let field = Simple.const (Reg_width_const.tagged_immediate imm) in
@@ -1481,11 +1481,11 @@ let convert_lprim ~big_endian (prim : L.primitive) (args : Simple.t list list)
14811481
| Mread_flat_suffix read ->
14821482
Flat_suffix
14831483
(match read with
1484-
| Flat_read flat_element ->
1485-
P.Mixed_block_flat_element.from_lambda flat_element
1486-
| Flat_read_float_boxed _ -> Float_boxed)
1484+
| Flat_read flat_element -> K.from_lambda_flat_element flat_element
1485+
| Flat_read_float_boxed _ -> K.naked_float)
14871486
in
1488-
Mixed { tag = Unknown; field_kind; size = Unknown }
1487+
let shape = K.Mixed_block_shape.from_lambda shape in
1488+
Mixed { tag = Unknown; field_kind; shape; size = Unknown }
14891489
in
14901490
let block_access : H.expr_primitive =
14911491
Binary (Block_load (block_access, mutability), arg, Simple field)
@@ -1531,7 +1531,7 @@ let convert_lprim ~big_endian (prim : L.primitive) (args : Simple.t list list)
15311531
[ Ternary
15321532
(Block_set (block_access, init_or_assign), block, Simple field, value)
15331533
]
1534-
| ( Psetmixedfield (field, write, initialization_or_assignment),
1534+
| ( Psetmixedfield (field, write, shape, initialization_or_assignment),
15351535
[[block]; [value]] ) ->
15361536
let imm = Targetint_31_63.of_int field in
15371537
check_non_negative_imm imm "Psetmixedfield";
@@ -1544,9 +1544,10 @@ let convert_lprim ~big_endian (prim : L.primitive) (args : Simple.t list list)
15441544
Value_prefix
15451545
(convert_block_access_field_kind immediate_or_pointer)
15461546
| Mwrite_flat_suffix flat ->
1547-
Flat_suffix (P.Mixed_block_flat_element.from_lambda flat));
1548-
size = Unknown;
1549-
tag = Unknown
1547+
Flat_suffix (K.from_lambda_flat_element flat));
1548+
shape = K.Mixed_block_shape.from_lambda shape;
1549+
tag = Unknown;
1550+
size = Unknown
15501551
}
15511552
in
15521553
let init_or_assign = convert_init_or_assign initialization_or_assignment in

middle_end/flambda2/identifiers/reg_width_const.ml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,20 @@ let is_tagged_immediate t =
4040
| Naked_immediate _ | Naked_float _ | Naked_float32 _ | Naked_int32 _
4141
| Naked_int64 _ | Naked_nativeint _ | Naked_vec128 _ ->
4242
None
43+
44+
let of_int_of_kind (kind : Flambda_kind.t) i =
45+
match kind with
46+
| Value -> tagged_immediate (Targetint_31_63.of_int i)
47+
| Naked_number Naked_float ->
48+
naked_float (Numeric_types.Float_by_bit_pattern.create (float_of_int i))
49+
| Naked_number Naked_float32 ->
50+
naked_float32 (Numeric_types.Float32_by_bit_pattern.create (float_of_int i))
51+
| Naked_number Naked_immediate -> naked_immediate (Targetint_31_63.of_int i)
52+
| Naked_number Naked_int32 -> naked_int32 (Int32.of_int i)
53+
| Naked_number Naked_int64 -> naked_int64 (Int64.of_int i)
54+
| Naked_number Naked_nativeint -> naked_nativeint (Targetint_32_64.of_int i)
55+
| Naked_number Naked_vec128 ->
56+
let i = Int64.of_int i in
57+
naked_vec128 (Vector_types.Vec128.Bit_pattern.of_bits { high = i; low = i })
58+
| Region | Rec_info ->
59+
Misc.fatal_errorf "Invalid kind %a" Flambda_kind.print kind

middle_end/flambda2/identifiers/reg_width_const.mli

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,7 @@ val of_descr : Descr.t -> t
2525
val is_naked_immediate : t -> Targetint_31_63.t option
2626

2727
val is_tagged_immediate : t -> Targetint_31_63.t option
28+
29+
(** Create a numeric constant of the given kind ([Region] and [Rec_info] are
30+
forbidden). *)
31+
val of_int_of_kind : Flambda_kind.t -> int -> t

0 commit comments

Comments
 (0)