Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unarization for Flambda 2 (unboxed products) #1250

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions backend/cmm_helpers.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1070,6 +1070,8 @@ module Extended_machtype = struct
typ_any_int
| Pvalue Pintval -> typ_tagged_int
| Pvalue _ -> typ_val
| Punboxed_product _ ->
Misc.fatal_error "Punboxed_product not expected here"
end

let machtype_of_layout layout =
Expand Down Expand Up @@ -4002,19 +4004,19 @@ let direct_call ~dbg ty pos f_code_sym args =
Cop (Capply (ty, pos), f_code_sym :: args, dbg)

let indirect_call ~dbg ty pos alloc_mode f args_type args =
match args with
| [arg] ->
match args_type with
| [_] ->
(* Use a variable to avoid duplicating the cmm code of the closure [f]. *)
let v = Backend_var.create_local "*closure*" in
let v' = Backend_var.With_provenance.create v in
letin v' ~defining_expr:f
~body:
(Cop
( Capply (Extended_machtype.to_machtype ty, pos),
[load ~dbg Word_int Asttypes.Mutable ~addr:(Cvar v); arg; Cvar v],
(load ~dbg Word_int Asttypes.Mutable ~addr:(Cvar v) :: args)
@ [Cvar v],
dbg ))
| args ->
call_caml_apply ty args_type Asttypes.Mutable f args pos alloc_mode dbg
| _ -> call_caml_apply ty args_type Asttypes.Mutable f args pos alloc_mode dbg

let indirect_full_call ~dbg ty pos alloc_mode f args_type = function
(* the single-argument case is already optimized by indirect_call *)
Expand Down Expand Up @@ -4143,5 +4145,5 @@ let kind_of_layout (layout : Lambda.layout) =
| Pvalue Pfloatval -> Boxed_float
| Pvalue (Pboxedintval bi) -> Boxed_integer bi
| Pvalue (Pgenval | Pintval | Pvariant _ | Parrayval _)
| Ptop | Pbottom | Punboxed_float | Punboxed_int _ ->
| Ptop | Pbottom | Punboxed_float | Punboxed_int _ | Punboxed_product _ ->
Any
2 changes: 2 additions & 0 deletions backend/cmmgen.ml
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ let get_field env layout ptr n dbg =
| Pvalue Pintval | Punboxed_int _ -> Word_int
| Pvalue _ -> Word_val
| Punboxed_float -> Double
| Punboxed_product _ -> Misc.fatal_error "TBD"
| Ptop ->
Misc.fatal_errorf "get_field with Ptop: %a" Debuginfo.print_compact dbg
| Pbottom ->
Expand Down Expand Up @@ -1322,6 +1323,7 @@ and transl_let env str (layout : Lambda.layout) id exp transl_body =
end
| Pvalue kind ->
transl_let_value env str kind id exp transl_body
| Punboxed_product _ -> Misc.fatal_error "TBD"

and make_catch (kind : Cmm.kind_for_unboxing) ncatch body handler dbg =
match body with
Expand Down
1 change: 1 addition & 0 deletions middle_end/clambda_primitives.ml
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ and layout = Lambda.layout =
| Pvalue of value_kind
| Punboxed_float
| Punboxed_int of boxed_integer
| Punboxed_product of layout list
| Pbottom

and block_shape = Lambda.block_shape
Expand Down
1 change: 1 addition & 0 deletions middle_end/clambda_primitives.mli
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ and layout = Lambda.layout =
| Pvalue of value_kind
| Punboxed_float
| Punboxed_int of boxed_integer
| Punboxed_product of layout list
| Pbottom

and block_shape = Lambda.block_shape
Expand Down
1 change: 1 addition & 0 deletions middle_end/closure/closure.ml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ let is_gc_ignorable kind =
| Punboxed_int _ -> true
| Pvalue Pintval -> true
| Pvalue (Pgenval | Pfloatval | Pboxedintval _ | Pvariant _ | Parrayval _) -> false
| Punboxed_product _ -> Misc.fatal_error "TBD"

let split_closure_fv kinds fv =
List.fold_right (fun id (not_scanned, scanned) ->
Expand Down
2 changes: 2 additions & 0 deletions middle_end/convert_primitives.ml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ let convert (prim : Lambda.primitive) : Clambda_primitives.primitive =
| Psetfloatfield (field, init_or_assign) ->
Psetfloatfield (field, init_or_assign)
| Pduprecord (repr, size) -> Pduprecord (repr, size)
| Pmake_unboxed_product _
| Punboxed_product_field _ -> Misc.fatal_error "TODO"
| Pccall prim -> Pccall prim
| Praise kind -> Praise kind
| Psequand -> Psequand
Expand Down
3 changes: 2 additions & 1 deletion middle_end/flambda/closure_offsets.ml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ let add_closure_offsets
| Punboxed_float -> true
| Punboxed_int _ -> true
| Pvalue Pintval -> true
| Pvalue _ -> false)
| Pvalue _ -> false
| Punboxed_product _ -> Misc.fatal_error "TODO")
free_vars
in
let free_variable_offsets, free_variable_pos =
Expand Down
3 changes: 2 additions & 1 deletion middle_end/flambda/flambda_to_clambda.ml
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,8 @@ and to_clambda_set_of_closures t env
| Punboxed_float -> true
| Punboxed_int _ -> true
| Pvalue Pintval -> true
| Pvalue _ -> false)
| Pvalue _ -> false
| Punboxed_product _ -> Misc.fatal_error "TBD")
free_vars
in
let to_closure_args free_vars =
Expand Down
6 changes: 5 additions & 1 deletion middle_end/flambda2/bound_identifiers/bound_parameters.ml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@ let var_set t = Variable.Set.of_list (vars t)

let rename t = List.map (fun t -> BP.rename t) t

let arity t = List.map (fun t -> BP.kind t) t |> Flambda_arity.create
let arity t =
List.map
(fun t -> Flambda_arity.Component_for_creation.Singleton (BP.kind t))
t
|> Flambda_arity.create

let free_names t =
List.fold_left
Expand Down
2 changes: 1 addition & 1 deletion middle_end/flambda2/bound_identifiers/bound_parameters.mli
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ val is_empty : t -> bool

val same_number : t -> t -> bool

val arity : t -> Flambda_arity.t
val arity : t -> [> `Unarized] Flambda_arity.t

val check_no_duplicates : t -> unit

Expand Down
Loading