Skip to content

Commit 9385be7

Browse files
gretay-jsd-kalinichenko
authored andcommitted
Zero alloc: refactor to remove "property" and improve naming (#2416)
* Remove "Lambda.property" and rename "Lambda.check_attribute" and propagate this name down to Cmm. * Rename files checkmach.ml to zero_alloc_checker.ml check_attribute.ml to zero_alloc_attribute.ml * Rename compilation flags "checkmach" to "zero-alloc-checker" * Update autogenerated dune.inc file * Refactoring: simplify zero_alloc_checker by removing unused functor * Format * Update depend * Fix upstream testsuite * Lots of fixes after rebase (makes separate commits useless) too much diff to fix up in the right commit * Regenerate dune.inc * Fix chamelon build * Rename [check] labelled arguments to [zero_alloc_attribute] * fix up [dune] to list more things alphabetically * Fix assorted typos and improve printing * Format * Remove unused copy of is_check_enabled
1 parent 6468f4c commit 9385be7

Some content is hidden

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

64 files changed

+547
-644
lines changed

backend/.ocamlformat-enable

+2-2
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

+5-5
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

+2-1
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

+4-9
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

+2-6
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/printcmm.ml

+6-10
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

-1
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

+2-1
Original file line numberDiff line numberDiff line change
@@ -1753,7 +1753,8 @@ method private emit_tail_sequence ?at_start env exp =
17531753
method emit_fundecl ~future_funcnames f =
17541754
current_function_name := f.Cmm.fun_name.sym_name;
17551755
current_function_is_check_enabled :=
1756-
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;
17571758
let num_regs_per_arg = Array.make (List.length f.Cmm.fun_args) 0 in
17581759
let rargs =
17591760
List.mapi

0 commit comments

Comments
 (0)