Skip to content

Commit 4478a35

Browse files
authored
Enable Domain module fully on runtime5 (#2464)
1 parent 4de9d2f commit 4478a35

16 files changed

+424
-281
lines changed

backend/cmm_helpers.ml

+2
Original file line numberDiff line numberDiff line change
@@ -4106,3 +4106,5 @@ let allocate_unboxed_nativeint_array =
41064106

41074107
(* Drop internal optional arguments from exported interface *)
41084108
let block_header x y = block_header x y
4109+
4110+
let dls_get ~dbg = Cop (Cdls_get, [], dbg)

backend/cmm_helpers.mli

+2
Original file line numberDiff line numberDiff line change
@@ -1067,3 +1067,5 @@ val setfield_unboxed_int32 : ternary_primitive
10671067
val setfield_unboxed_float32 : ternary_primitive
10681068

10691069
val setfield_unboxed_int64_or_nativeint : ternary_primitive
1070+
1071+
val dls_get : dbg:Debuginfo.t -> expression

backend/zero_alloc_checker.ml

+2-2
Original file line numberDiff line numberDiff line change
@@ -2247,7 +2247,7 @@ end = struct
22472247
let w = create_witnesses t (Extcall { callee = func }) dbg in
22482248
transform_top t ~next ~exn w ("external call to " ^ func) dbg
22492249
| Ispecific s -> transform_specific t s ~next ~exn dbg
2250-
| Idls_get -> Misc.fatal_error "Idls_get not supported"
2250+
| Idls_get -> next
22512251

22522252
module D = Dataflow.Backward ((Value : Dataflow.DOMAIN))
22532253

@@ -2574,7 +2574,7 @@ end = struct
25742574
in
25752575
transform t ~effect ~next ~exn:Value.bot "heap allocation" dbg
25762576
| Specific s -> transform_specific t s ~next ~exn:Value.bot dbg
2577-
| Dls_get -> Misc.fatal_error "Idls_get not supported"
2577+
| Dls_get -> next
25782578

25792579
let basic next (i : Cfg.basic Cfg.instruction) t : (domain, error) result
25802580
=

middle_end/flambda2/from_lambda/lambda_to_flambda.ml

+2-1
Original file line numberDiff line numberDiff line change
@@ -702,9 +702,10 @@ let primitive_can_raise (prim : Lambda.primitive) =
702702
| Punboxed_product_field _ | Pget_header _ ->
703703
false
704704
| Patomic_exchange | Patomic_cas | Patomic_fetch_add | Patomic_load _ -> false
705-
| Prunstack | Pperform | Presume | Preperform | Pdls_get ->
705+
| Prunstack | Pperform | Presume | Preperform ->
706706
Misc.fatal_errorf "Primitive %a is not yet supported by Flambda 2"
707707
Printlambda.primitive prim
708+
| Pdls_get -> false
708709

709710
type non_tail_continuation =
710711
Acc.t ->

middle_end/flambda2/from_lambda/lambda_to_flambda_primitives.ml

+2-1
Original file line numberDiff line numberDiff line change
@@ -1887,6 +1887,7 @@ let convert_lprim ~big_endian (prim : L.primitive) (args : Simple.t list list)
18871887
[Ternary (Atomic_compare_and_set, atomic, old_value, new_value)]
18881888
| Patomic_fetch_add, [[atomic]; [i]] ->
18891889
[Binary (Atomic_fetch_and_add, atomic, i)]
1890+
| Pdls_get, _ -> [Nullary Dls_get]
18901891
| ( ( Pmodint Unsafe
18911892
| Pdivbint { is_safe = Unsafe; size = _; mode = _ }
18921893
| Pmodbint { is_safe = Unsafe; size = _; mode = _ }
@@ -2000,7 +2001,7 @@ let convert_lprim ~big_endian (prim : L.primitive) (args : Simple.t list list)
20002001
Misc.fatal_errorf
20012002
"[%a] should have been handled by [Closure_conversion.close_primitive]"
20022003
Printlambda.primitive prim
2003-
| (Prunstack | Pperform | Presume | Preperform | Pdls_get), _ ->
2004+
| (Prunstack | Pperform | Presume | Preperform), _ ->
20042005
Misc.fatal_errorf "Primitive %a is not yet supported by Flambda 2"
20052006
Printlambda.primitive prim
20062007

middle_end/flambda2/parser/flambda_to_fexpr.ml

+2-1
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,8 @@ let nullop _env (op : Flambda_primitive.nullary_primitive) : Fexpr.nullop =
516516
match op with
517517
| Begin_region -> Begin_region
518518
| Begin_try_region -> Begin_try_region
519-
| Invalid _ | Optimised_out _ | Probe_is_enabled _ | Enter_inlined_apply _ ->
519+
| Invalid _ | Optimised_out _ | Probe_is_enabled _ | Enter_inlined_apply _
520+
| Dls_get ->
520521
Misc.fatal_errorf "TODO: Nullary primitive: %a" Flambda_primitive.print
521522
(Flambda_primitive.Nullary op)
522523

middle_end/flambda2/simplify/simplify_nullary_primitive.ml

+5
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,8 @@ let simplify_nullary_primitive dacc original_prim (prim : P.nullary_primitive)
4949
let ty = T.this_tagged_immediate Targetint_31_63.zero in
5050
let dacc = DA.add_variable dacc result_var ty in
5151
Simplify_primitive_result.create named ~try_reify:false dacc
52+
| Dls_get ->
53+
let named = Named.create_prim original_prim dbg in
54+
let ty = T.any_value in
55+
let dacc = DA.add_variable dacc result_var ty in
56+
Simplify_primitive_result.create named ~try_reify:false dacc

middle_end/flambda2/terms/code_size.ml

+1
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,7 @@ let nullary_prim_size prim =
341341
| Begin_region -> 1
342342
| Begin_try_region -> 1
343343
| Enter_inlined_apply _ -> 0
344+
| Dls_get -> 1
344345

345346
let unary_prim_size prim =
346347
match (prim : Flambda_primitive.unary_primitive) with

middle_end/flambda2/terms/flambda_primitive.ml

+21-11
Original file line numberDiff line numberDiff line change
@@ -937,10 +937,11 @@ type nullary_primitive =
937937
| Begin_region
938938
| Begin_try_region
939939
| Enter_inlined_apply of { dbg : Inlined_debuginfo.t }
940+
| Dls_get
940941

941942
let nullary_primitive_eligible_for_cse = function
942943
| Invalid _ | Optimised_out _ | Probe_is_enabled _ | Begin_region
943-
| Begin_try_region | Enter_inlined_apply _ ->
944+
| Begin_try_region | Enter_inlined_apply _ | Dls_get ->
944945
false
945946

946947
let compare_nullary_primitive p1 p2 =
@@ -953,29 +954,35 @@ let compare_nullary_primitive p1 p2 =
953954
| Begin_try_region, Begin_try_region -> 0
954955
| Enter_inlined_apply { dbg = dbg1 }, Enter_inlined_apply { dbg = dbg2 } ->
955956
Inlined_debuginfo.compare dbg1 dbg2
957+
| Dls_get, Dls_get -> 0
956958
| ( Invalid _,
957959
( Optimised_out _ | Probe_is_enabled _ | Begin_region | Begin_try_region
958-
| Enter_inlined_apply _ ) ) ->
960+
| Enter_inlined_apply _ | Dls_get ) ) ->
959961
-1
960962
| ( Optimised_out _,
961963
( Probe_is_enabled _ | Begin_region | Begin_try_region
962-
| Enter_inlined_apply _ ) ) ->
964+
| Enter_inlined_apply _ | Dls_get ) ) ->
963965
-1
964966
| Optimised_out _, Invalid _ -> 1
965-
| Probe_is_enabled _, (Begin_region | Begin_try_region | Enter_inlined_apply _)
966-
->
967+
| ( Probe_is_enabled _,
968+
(Begin_region | Begin_try_region | Enter_inlined_apply _ | Dls_get) ) ->
967969
-1
968970
| Probe_is_enabled _, (Invalid _ | Optimised_out _) -> 1
969-
| Begin_region, (Begin_try_region | Enter_inlined_apply _) -> -1
971+
| Begin_region, (Begin_try_region | Enter_inlined_apply _ | Dls_get) -> -1
970972
| Begin_region, (Invalid _ | Optimised_out _ | Probe_is_enabled _) -> 1
971-
| Begin_try_region, Enter_inlined_apply _ -> -1
973+
| Begin_try_region, (Enter_inlined_apply _ | Dls_get) -> -1
972974
| ( Begin_try_region,
973975
(Invalid _ | Optimised_out _ | Probe_is_enabled _ | Begin_region) ) ->
974976
1
975977
| ( Enter_inlined_apply _,
976978
( Invalid _ | Optimised_out _ | Probe_is_enabled _ | Begin_region
977979
| Begin_try_region ) ) ->
978980
1
981+
| Enter_inlined_apply _, Dls_get -> -1
982+
| ( Dls_get,
983+
( Invalid _ | Optimised_out _ | Probe_is_enabled _ | Begin_region
984+
| Begin_try_region | Enter_inlined_apply _ ) ) ->
985+
1
979986

980987
let equal_nullary_primitive p1 p2 = compare_nullary_primitive p1 p2 = 0
981988

@@ -994,6 +1001,7 @@ let print_nullary_primitive ppf p =
9941001
| Enter_inlined_apply { dbg } ->
9951002
Format.fprintf ppf "@[<hov 1>(Enter_inlined_apply@ %a)@]"
9961003
Inlined_debuginfo.print dbg
1004+
| Dls_get -> Format.pp_print_string ppf "Dls_get"
9971005

9981006
let result_kind_of_nullary_primitive p : result_kind =
9991007
match p with
@@ -1003,6 +1011,7 @@ let result_kind_of_nullary_primitive p : result_kind =
10031011
| Begin_region -> Singleton K.region
10041012
| Begin_try_region -> Singleton K.region
10051013
| Enter_inlined_apply _ -> Unit
1014+
| Dls_get -> Singleton K.value
10061015

10071016
let coeffects_of_mode : Alloc_mode.For_allocations.t -> Coeffects.t = function
10081017
| Local _ -> Coeffects.Has_coeffects
@@ -1025,11 +1034,12 @@ let effects_and_coeffects_of_nullary_primitive p : Effects_and_coeffects.t =
10251034
(* This doesn't really have effects, but without effects, these primitives
10261035
get deleted during lambda_to_flambda. *)
10271036
Arbitrary_effects, Has_coeffects, Strict
1037+
| Dls_get -> No_effects, Has_coeffects, Strict
10281038

10291039
let nullary_classify_for_printing p =
10301040
match p with
10311041
| Invalid _ | Optimised_out _ | Probe_is_enabled _ | Begin_region
1032-
| Begin_try_region | Enter_inlined_apply _ ->
1042+
| Begin_try_region | Enter_inlined_apply _ | Dls_get ->
10331043
Neither
10341044

10351045
type unary_primitive =
@@ -2187,7 +2197,7 @@ let free_names t =
21872197
match t with
21882198
| Nullary
21892199
( Invalid _ | Optimised_out _ | Probe_is_enabled _ | Begin_region
2190-
| Begin_try_region | Enter_inlined_apply _ ) ->
2200+
| Begin_try_region | Enter_inlined_apply _ | Dls_get ) ->
21912201
Name_occurrences.empty
21922202
| Unary (prim, x0) ->
21932203
Name_occurrences.union
@@ -2214,7 +2224,7 @@ let apply_renaming t renaming =
22142224
match t with
22152225
| Nullary
22162226
( Invalid _ | Optimised_out _ | Probe_is_enabled _ | Begin_region
2217-
| Begin_try_region | Enter_inlined_apply _ ) ->
2227+
| Begin_try_region | Enter_inlined_apply _ | Dls_get ) ->
22182228
t
22192229
| Unary (prim, x0) ->
22202230
let prim' = apply_renaming_unary_primitive prim renaming in
@@ -2244,7 +2254,7 @@ let ids_for_export t =
22442254
match t with
22452255
| Nullary
22462256
( Invalid _ | Optimised_out _ | Probe_is_enabled _ | Begin_region
2247-
| Begin_try_region | Enter_inlined_apply _ ) ->
2257+
| Begin_try_region | Enter_inlined_apply _ | Dls_get ) ->
22482258
Ids_for_export.empty
22492259
| Unary (prim, x0) ->
22502260
Ids_for_export.union

middle_end/flambda2/terms/flambda_primitive.mli

+1
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,7 @@ type nullary_primitive =
325325
| Enter_inlined_apply of { dbg : Inlined_debuginfo.t }
326326
(** Used in classic mode to denote the start of an inlined function body.
327327
This is then used in to_cmm to correctly add inlined debuginfo. *)
328+
| Dls_get (** Obtain the domain-local state block. *)
328329

329330
(** Untagged binary integer arithmetic operations.
330331

middle_end/flambda2/to_cmm/to_cmm_primitive.ml

+1
Original file line numberDiff line numberDiff line change
@@ -664,6 +664,7 @@ let nullary_primitive _env res dbg prim =
664664
"The primitive [Enter_inlined_apply] should not be translated by \
665665
[to_cmm_primitive] but should instead be handled in [to_cmm_expr] to \
666666
correctly adjust the inlined debuginfo in the env."
667+
| Dls_get -> None, res, C.dls_get ~dbg
667668

668669
let unary_primitive env res dbg f arg =
669670
match (f : P.unary_primitive) with

ocaml/asmcomp/amd64/emit.mlp

+1-1
Original file line numberDiff line numberDiff line change
@@ -932,7 +932,7 @@ let emit_instr env fallthrough i =
932932
I.movzx (res8 i 0) (res i 0)
933933
| Lop (Idls_get) ->
934934
if Config.runtime5
935-
then I.mov (domain_field Domainstate.Domain_dls_root) (res i 0)
935+
then I.mov (domain_field Domainstate.Domain_dls_root) (res i 0)
936936
else Misc.fatal_error "Idls_get not implemented in runtime4."
937937
| Lreloadretaddr ->
938938
()

ocaml/middle_end/semantics_of_primitives.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ let for_primitive (prim : Clambda_primitives.primitive) =
160160
| Pget_header _ -> No_effects, No_coeffects
161161
| Pdls_get ->
162162
(* only read *)
163-
No_effects, No_coeffects
163+
No_effects, Has_coeffects
164164

165165
type return_type =
166166
| Float

ocaml/runtime4/domain.c

+37
Original file line numberDiff line numberDiff line change
@@ -175,3 +175,40 @@ CAMLprim value caml_ml_condition_broadcast(value wrapper)
175175

176176
return (*caml_hook_condition_broadcast)(wrapper);
177177
}
178+
179+
/* Dummy implementations to enable [Stdlib.Domain] to link. */
180+
181+
CAMLprim value caml_recommended_domain_count(void)
182+
{
183+
caml_failwith("Domains not supported on runtime4");
184+
}
185+
186+
CAMLprim value caml_ml_domain_cpu_relax(void)
187+
{
188+
caml_failwith("Domains not supported on runtime4");
189+
}
190+
191+
CAMLprim value caml_init_domain_self(void)
192+
{
193+
caml_failwith("Domains not supported on runtime4");
194+
}
195+
196+
CAMLprim value caml_domain_spawn(void)
197+
{
198+
caml_failwith("Domains not supported on runtime4");
199+
}
200+
201+
CAMLprim value caml_ml_domain_id(void)
202+
{
203+
caml_failwith("Domains not supported on runtime4");
204+
}
205+
206+
CAMLprim value caml_domain_dls_set(void)
207+
{
208+
caml_failwith("Domains not supported on runtime4");
209+
}
210+
211+
CAMLprim value caml_domain_dls_get(void)
212+
{
213+
caml_failwith("Domains not supported on runtime4");
214+
}

0 commit comments

Comments
 (0)