Skip to content

Commit 77bd04c

Browse files
authored
Support for mixed blocks in Flambda2 types (#2533)
1 parent 9442538 commit 77bd04c

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
@@ -1053,7 +1053,6 @@ let close_let acc env let_bound_ids_with_kinds user_visible defining_expr
10531053
( Variadic
10541054
(Make_block (Values (tag, _), Immutable, alloc_mode), fields),
10551055
_ ) -> (
1056-
let tag' = Tag.Scannable.to_tag tag in
10571056
let approxs =
10581057
List.map (find_value_approximation body_env) fields |> Array.of_list
10591058
in
@@ -1071,7 +1070,7 @@ let close_let acc env let_bound_ids_with_kinds user_visible defining_expr
10711070
let acc =
10721071
Acc.add_symbol_approximation acc sym
10731072
(Value_approximation.Block_approximation
1074-
(tag', approxs, Alloc_mode.For_allocations.as_type alloc_mode))
1073+
(tag, approxs, Alloc_mode.For_allocations.as_type alloc_mode))
10751074
in
10761075
body acc body_env
10771076
| Computed_static static_fields ->
@@ -1095,7 +1094,7 @@ let close_let acc env let_bound_ids_with_kinds user_visible defining_expr
10951094
in
10961095
let approx =
10971096
Value_approximation.Block_approximation
1098-
(tag', approxs, Alloc_mode.For_allocations.as_type alloc_mode)
1097+
(tag, approxs, Alloc_mode.For_allocations.as_type alloc_mode)
10991098
in
11001099
let acc = Acc.add_symbol_approximation acc symbol approx in
11011100
let acc, body = body acc body_env in
@@ -1105,7 +1104,7 @@ let close_let acc env let_bound_ids_with_kinds user_visible defining_expr
11051104
defining_expr ~body
11061105
| Dynamic_block ->
11071106
let body_env =
1108-
Env.add_block_approximation body_env var tag' approxs
1107+
Env.add_block_approximation body_env var tag approxs
11091108
(Alloc_mode.For_allocations.as_type alloc_mode)
11101109
in
11111110
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
@@ -999,8 +999,8 @@ let convert_lprim ~big_endian (prim : L.primitive) (args : Simple.t list list)
999999
let mode = Alloc_mode.For_allocations.from_lambda mode ~current_region in
10001000
let mutability = Mutability.from_lambda mutability in
10011001
let tag = Tag.Scannable.create_exn tag in
1002-
let shape = P.Mixed_block_kind.from_lambda shape in
1003-
[Variadic (Make_mixed_block (tag, shape, mutability, mode), args)]
1002+
let shape = K.Mixed_block_shape.from_lambda shape in
1003+
[Variadic (Make_block (Mixed (tag, shape), mutability, mode), args)]
10041004
| Pmakearray (lambda_array_kind, mutability, mode), _ -> (
10051005
let args = List.flatten args in
10061006
let mode = Alloc_mode.For_allocations.from_lambda mode ~current_region in
@@ -1447,7 +1447,7 @@ let convert_lprim ~big_endian (prim : L.primitive) (args : Simple.t list list)
14471447
Naked_floats { size = Unknown }
14481448
in
14491449
[Binary (Block_load (block_access, mutability), arg, Simple field)]
1450-
| Pmixedfield (field, read, sem), [[arg]] -> (
1450+
| Pmixedfield (field, read, shape, sem), [[arg]] -> (
14511451
let imm = Targetint_31_63.of_int field in
14521452
check_non_negative_imm imm "Pmixedfield";
14531453
let field = Simple.const (Reg_width_const.tagged_immediate imm) in
@@ -1460,11 +1460,11 @@ let convert_lprim ~big_endian (prim : L.primitive) (args : Simple.t list list)
14601460
| Mread_flat_suffix read ->
14611461
Flat_suffix
14621462
(match read with
1463-
| Flat_read flat_element ->
1464-
P.Mixed_block_flat_element.from_lambda flat_element
1465-
| Flat_read_float_boxed _ -> Float_boxed)
1463+
| Flat_read flat_element -> K.from_lambda_flat_element flat_element
1464+
| Flat_read_float_boxed _ -> K.naked_float)
14661465
in
1467-
Mixed { tag = Unknown; field_kind; size = Unknown }
1466+
let shape = K.Mixed_block_shape.from_lambda shape in
1467+
Mixed { tag = Unknown; field_kind; shape; size = Unknown }
14681468
in
14691469
let block_access : H.expr_primitive =
14701470
Binary (Block_load (block_access, mutability), arg, Simple field)
@@ -1510,7 +1510,7 @@ let convert_lprim ~big_endian (prim : L.primitive) (args : Simple.t list list)
15101510
[ Ternary
15111511
(Block_set (block_access, init_or_assign), block, Simple field, value)
15121512
]
1513-
| ( Psetmixedfield (field, write, initialization_or_assignment),
1513+
| ( Psetmixedfield (field, write, shape, initialization_or_assignment),
15141514
[[block]; [value]] ) ->
15151515
let imm = Targetint_31_63.of_int field in
15161516
check_non_negative_imm imm "Psetmixedfield";
@@ -1523,9 +1523,10 @@ let convert_lprim ~big_endian (prim : L.primitive) (args : Simple.t list list)
15231523
Value_prefix
15241524
(convert_block_access_field_kind immediate_or_pointer)
15251525
| Mwrite_flat_suffix flat ->
1526-
Flat_suffix (P.Mixed_block_flat_element.from_lambda flat));
1527-
size = Unknown;
1528-
tag = Unknown
1526+
Flat_suffix (K.from_lambda_flat_element flat));
1527+
shape = K.Mixed_block_shape.from_lambda shape;
1528+
tag = Unknown;
1529+
size = Unknown
15291530
}
15301531
in
15311532
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)