Skip to content

Commit 73f846e

Browse files
Merge branch 'main' into dkalinichenko/move-unboxed-defs-to-stable
2 parents 1214fde + ee71ef2 commit 73f846e

File tree

191 files changed

+10487
-5727
lines changed

Some content is hidden

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

191 files changed

+10487
-5727
lines changed

HACKING.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,7 @@ To rebuild after making changes, you can just type `make`. You need to
9696
have a working OCaml 4.14 or 4.14.1 compiler on your PATH before doing so,
9797
e.g. installed via OPAM. You also need to have dune and menhir.
9898

99-
<!-- CR someone: investigate this -->
100-
The build currently fails when using the latest version of `dune` (3.11.1).
101-
To install a known-good dune, run `opam pin add dune 3.8.1`. `menhir` should be pinned to a specific
102-
version as well: `opam pin add menhir 20210419`.
99+
`menhir` should be pinned to a specific version: `opam pin add menhir 20210419`.
103100

104101
There is a special target `make hacking` which starts Dune in polling mode. The rebuild
105102
performed here is equivalent to `make ocamlopt` in the upstream distribution: it rebuilds the

backend/.ocamlformat-enable

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ cmm_builtins.ml
44
cmm_builtins.mli
55
checks.ml
66
checks.mli
7-
checkmach.ml
8-
checkmach.mli
7+
zero_alloc_checker.ml
8+
zero_alloc_checker.mli
99
cfg/**/*.ml
1010
cfg/**/*.mli
1111
asm_targets/**/*.ml

backend/asmgen.ml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ let (pass_to_cfg : Cfg_format.cfg_unit_info Compiler_pass_map.t) =
8686
|> Compiler_pass_map.add Compiler_pass.Selection (new_cfg_unit_info ())
8787

8888
let reset () =
89-
Checkmach.reset_unit_info ();
89+
Zero_alloc_checker.reset_unit_info ();
9090
start_from_emit := false;
9191
Compiler_pass_map.iter (fun pass (cfg_unit_info : Cfg_format.cfg_unit_info) ->
9292
if should_save_ir_after pass then begin
@@ -277,8 +277,8 @@ let compile_fundecl ~ppf_dump ~funcnames fd_cmm =
277277
++ Profile.record ~accumulate:true "polling"
278278
(Polling.instrument_fundecl ~future_funcnames:funcnames)
279279
++ Compiler_hooks.execute_and_pipe Compiler_hooks.Mach_polling
280-
++ Profile.record ~accumulate:true "checkmach"
281-
(Checkmach.fundecl ~future_funcnames:funcnames ppf_dump)
280+
++ Profile.record ~accumulate:true "zero_alloc_checker"
281+
(Zero_alloc_checker.fundecl ~future_funcnames:funcnames ppf_dump)
282282
++ (fun fd ->
283283
match !Flambda_backend_flags.cfg_cse_optimize with
284284
| false ->
@@ -460,9 +460,9 @@ let compile_unit ~output_prefix ~asm_filename ~keep_asm ~obj_filename ~may_reduc
460460
Misc.try_finally
461461
(fun () ->
462462
gen ();
463-
Checkmach.record_unit_info ppf_dump;
463+
Zero_alloc_checker.record_unit_info ppf_dump;
464464
Compiler_hooks.execute Compiler_hooks.Check_allocations
465-
Checkmach.iter_witnesses;
465+
Zero_alloc_checker.iter_witnesses;
466466
write_ir output_prefix)
467467
~always:(fun () ->
468468
if create_asm then close_out !Emitaux.output_channel)

backend/cfg/cfg.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ let rec of_cmm_codegen_option : Cmm.codegen_option list -> codegen_option list =
5757
match hd with
5858
| No_CSE -> No_CSE :: of_cmm_codegen_option tl
5959
| Reduce_code_size -> Reduce_code_size :: of_cmm_codegen_option tl
60-
| Use_linscan_regalloc | Assume _ | Check _ -> of_cmm_codegen_option tl)
60+
| Use_linscan_regalloc | Assume_zero_alloc _ | Check_zero_alloc _ ->
61+
of_cmm_codegen_option tl)
6162

6263
type t =
6364
{ blocks : basic_block Label.Tbl.t;

backend/cmm.ml

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -312,17 +312,14 @@ type expression =
312312
* Backend_var.With_provenance.t * expression * Debuginfo.t
313313
* kind_for_unboxing
314314

315-
type property =
316-
| Zero_alloc
317-
318315
type codegen_option =
319316
| Reduce_code_size
320317
| No_CSE
321318
| Use_linscan_regalloc
322-
| Assume of { property: property; strict: bool; never_returns_normally: bool;
323-
never_raises: bool;
324-
loc: Location.t }
325-
| Check of { property: property; strict: bool; loc : Location.t; }
319+
| Assume_zero_alloc of { strict: bool; never_returns_normally: bool;
320+
never_raises: bool;
321+
loc: Location.t }
322+
| Check_zero_alloc of { strict: bool; loc : Location.t; }
326323

327324
type fundecl =
328325
{ fun_name: symbol;
@@ -686,6 +683,4 @@ let equal_integer_comparison left right =
686683
| Cge, (Ceq | Cne | Clt | Cgt | Cle) ->
687684
false
688685

689-
let all_properties = [Zero_alloc]
690-
691686
let caml_flambda2_invalid = "caml_flambda2_invalid"

backend/cmm.mli

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -314,17 +314,14 @@ type expression =
314314
active. This allows for sharing a single handler in several places, or
315315
having multiple entry and exit points to a single trywith block. *)
316316

317-
type property =
318-
| Zero_alloc
319-
320317
type codegen_option =
321318
| Reduce_code_size
322319
| No_CSE
323320
| Use_linscan_regalloc
324-
| Assume of { property: property; strict: bool; never_returns_normally: bool;
321+
| Assume_zero_alloc of { strict: bool; never_returns_normally: bool;
325322
never_raises: bool;
326323
loc: Location.t }
327-
| Check of { property: property; strict: bool; loc: Location.t }
324+
| Check_zero_alloc of { strict: bool; loc: Location.t }
328325

329326
type fundecl =
330327
{ fun_name: symbol;
@@ -401,6 +398,5 @@ val equal_float_width : float_width -> float_width -> bool
401398
val equal_float_comparison : float_comparison -> float_comparison -> bool
402399
val equal_memory_chunk : memory_chunk -> memory_chunk -> bool
403400
val equal_integer_comparison : integer_comparison -> integer_comparison -> bool
404-
val all_properties : property list
405401

406402
val caml_flambda2_invalid : string

backend/cmm_helpers.ml

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1287,6 +1287,35 @@ let setfield_unboxed_int64_or_nativeint arr ofs newval dbg =
12871287
[array_indexing log2_size_addr arr ofs dbg; newval],
12881288
dbg ))
12891289

1290+
(* Getters and setters for unboxed float32 fields *)
1291+
1292+
let get_field_unboxed_float32 mutability ~block ~index dbg =
1293+
(* CR layouts v5.1: Properly support big-endian. *)
1294+
if Arch.big_endian
1295+
then
1296+
Misc.fatal_error
1297+
"Unboxed float32 fields only supported on little-endian architectures";
1298+
let memory_chunk = Single { reg = Float32 } in
1299+
(* CR layouts v5.1: We'll need to vary log2_size_addr to efficiently pack
1300+
* float32s *)
1301+
let field_address = array_indexing log2_size_addr block index dbg in
1302+
Cop
1303+
(Cload { memory_chunk; mutability; is_atomic = false }, [field_address], dbg)
1304+
1305+
let setfield_unboxed_float32 arr ofs newval dbg =
1306+
(* CR layouts v5.1: Properly support big-endian. *)
1307+
if Arch.big_endian
1308+
then
1309+
Misc.fatal_error
1310+
"Unboxed float32 fields only supported on little-endian architectures";
1311+
(* CR layouts v5.1: We will need to vary log2_size_addr when float32 fields
1312+
are efficiently packed. *)
1313+
return_unit dbg
1314+
(Cop
1315+
( Cstore (Single { reg = Float32 }, Assignment),
1316+
[array_indexing log2_size_addr arr ofs dbg; newval],
1317+
dbg ))
1318+
12901319
(* String length *)
12911320

12921321
(* Length of string block *)
@@ -1566,12 +1595,13 @@ let make_mixed_alloc ~mode dbg tag shape args =
15661595
match flat_suffix.(idx - value_prefix_len) with
15671596
| Imm -> int_array_set arr ofs newval dbg
15681597
| Float | Float64 -> float_array_set arr ofs newval dbg
1598+
| Float32 -> setfield_unboxed_float32 arr ofs newval dbg
15691599
| Bits32 -> setfield_unboxed_int32 arr ofs newval dbg
15701600
| Bits64 | Word -> setfield_unboxed_int64_or_nativeint arr ofs newval dbg
15711601
in
15721602
let size =
1573-
(* CR layouts 5.1: When we pack int32s more efficiently, this code will need
1574-
to change. *)
1603+
(* CR layouts 5.1: When we pack int32s/float32s more efficiently, this code
1604+
will need to change. *)
15751605
value_prefix_len + Array.length flat_suffix
15761606
in
15771607
if size_float <> size_addr

backend/cmm_helpers.mli

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1006,7 +1006,8 @@ val unboxed_int64_or_nativeint_array_set :
10061006
Debuginfo.t ->
10071007
expression
10081008

1009-
(** {2 Getters and setters for unboxed int fields of mixed blocks} *)
1009+
(** {2 Getters and setters for unboxed int and float32 fields of mixed
1010+
blocks} *)
10101011

10111012
(** The argument structure for getters is parallel to [get_field_computed]. *)
10121013

@@ -1017,6 +1018,13 @@ val get_field_unboxed_int32 :
10171018
Debuginfo.t ->
10181019
expression
10191020

1021+
val get_field_unboxed_float32 :
1022+
Asttypes.mutable_flag ->
1023+
block:expression ->
1024+
index:expression ->
1025+
Debuginfo.t ->
1026+
expression
1027+
10201028
val get_field_unboxed_int64_or_nativeint :
10211029
Asttypes.mutable_flag ->
10221030
block:expression ->
@@ -1032,4 +1040,6 @@ val get_field_unboxed_int64_or_nativeint :
10321040

10331041
val setfield_unboxed_int32 : ternary_primitive
10341042

1043+
val setfield_unboxed_float32 : ternary_primitive
1044+
10351045
val setfield_unboxed_int64_or_nativeint : ternary_primitive

backend/printcmm.ml

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -392,21 +392,17 @@ and sequence ppf = function
392392

393393
and expression ppf e = fprintf ppf "%a" expr e
394394

395-
let property_to_string : Cmm.property -> string = function
396-
| Zero_alloc -> "zero_alloc"
397-
398395
let codegen_option = function
399396
| Reduce_code_size -> "reduce_code_size"
400397
| No_CSE -> "no_cse"
401398
| Use_linscan_regalloc -> "linscan"
402-
| Assume { property; strict; never_returns_normally = _; loc = _ } ->
403-
Printf.sprintf "assume_%s%s%s"
404-
(property_to_string property)
399+
| Assume_zero_alloc { strict; never_returns_normally; never_raises; loc = _ } ->
400+
Printf.sprintf "assume_zero_alloc_%s%s%s"
405401
(if strict then "_strict" else "")
406-
(if strict then "_never_returns_normally" else "")
407-
| Check { property; strict; loc = _ } ->
408-
Printf.sprintf "assert_%s%s"
409-
(property_to_string property)
402+
(if never_returns_normally then "_never_returns_normally" else "")
403+
(if never_raises then "_never_raises" else "")
404+
| Check_zero_alloc { strict; loc = _ } ->
405+
Printf.sprintf "assert_zero_alloc%s"
410406
(if strict then "_strict" else "")
411407

412408
let print_codegen_options ppf l =

backend/printcmm.mli

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,4 @@ val fundecl : formatter -> Cmm.fundecl -> unit
3434
val data : formatter -> Cmm.data_item list -> unit
3535
val phrase : formatter -> Cmm.phrase -> unit
3636
val temporal_locality : Cmm.prefetch_temporal_locality_hint -> string
37-
val property_to_string : Cmm.property -> string
3837
val print_codegen_options : formatter -> Cmm.codegen_option list -> unit

backend/selectgen.ml

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,9 @@ let size_component : machtype_component -> int = function
206206
| Int -> Arch.size_int
207207
| Float -> Arch.size_float
208208
| Float32 ->
209-
assert (Arch.size_float = 8);
210-
Arch.size_float / 2
209+
(* CR layouts v5.1: reconsider when float32 fields are efficiently packed.
210+
Note that packed float32# arrays are handled via a separate path. *)
211+
Arch.size_float
211212
| Vec128 -> Arch.size_vec128
212213

213214
let size_machtype mty =
@@ -222,10 +223,11 @@ let size_expr (env:environment) exp =
222223
Cconst_int _ | Cconst_natint _ -> Arch.size_int
223224
| Cconst_symbol _ ->
224225
Arch.size_addr
225-
| Cconst_float32 _ ->
226-
assert (Arch.size_float = 8);
227-
Arch.size_float / 2
228226
| Cconst_float _ -> Arch.size_float
227+
| Cconst_float32 _ ->
228+
(* CR layouts v5.1: reconsider when float32 fields are efficiently packed.
229+
Note that packed float32# arrays are handled via a separate path. *)
230+
Arch.size_float
229231
| Cconst_vec128 _ -> Arch.size_vec128
230232
| Cvar id ->
231233
begin try
@@ -1751,7 +1753,8 @@ method private emit_tail_sequence ?at_start env exp =
17511753
method emit_fundecl ~future_funcnames f =
17521754
current_function_name := f.Cmm.fun_name.sym_name;
17531755
current_function_is_check_enabled :=
1754-
Checkmach.is_check_enabled f.Cmm.fun_codegen_options f.Cmm.fun_name.sym_name f.Cmm.fun_dbg;
1756+
Zero_alloc_checker.is_check_enabled f.Cmm.fun_codegen_options
1757+
f.Cmm.fun_name.sym_name f.Cmm.fun_dbg;
17551758
let num_regs_per_arg = Array.make (List.length f.Cmm.fun_args) 0 in
17561759
let rargs =
17571760
List.mapi

0 commit comments

Comments
 (0)