Skip to content

Commit cbb50c9

Browse files
authored
Add -dranges command-line flag and remove DEBUG_RANGES env var test (#1742)
1 parent 025d23f commit cbb50c9

File tree

5 files changed

+26
-16
lines changed

5 files changed

+26
-16
lines changed

backend/debug/compute_ranges.ml

+16-16
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,6 @@
1515
open! Int_replace_polymorphic_compare
1616
module L = Linear
1717

18-
let debug =
19-
match Sys.getenv "DEBUG_RANGES" with
20-
| exception Not_found -> false
21-
| _ -> true
22-
2318
module Make (S : Compute_ranges_intf.S_functor) = struct
2419
module Subrange_state = S.Subrange_state
2520
module Subrange_info = S.Subrange_info
@@ -301,12 +296,12 @@ module Make (S : Compute_ranges_intf.S_functor) = struct
301296
~(prev_insn : L.instruction option) ~known_available_after_prev_insn =
302297
let available_before = S.available_before insn in
303298
let available_across = S.available_across insn in
304-
if debug
299+
if !Flambda_backend_flags.dranges
305300
then
306301
Format.eprintf "canonicalised available_before:@ %a\n"
307302
(Misc.Stdlib.Option.print KS.print)
308303
available_before;
309-
if debug
304+
if !Flambda_backend_flags.dranges
310305
then
311306
Format.eprintf "canonicalised available_across:@ %a\n"
312307
(Misc.Stdlib.Option.print KS.print)
@@ -324,7 +319,7 @@ module Make (S : Compute_ranges_intf.S_functor) = struct
324319
~fun_num_stack_slots ~(first_insn : L.instruction) ~(insn : L.instruction)
325320
~(prev_insn : L.instruction option) ~currently_open_subranges
326321
~subrange_state =
327-
if debug
322+
if !Flambda_backend_flags.dranges
328323
then Format.eprintf "process_instruction:@ %a\n" Printlinear.instr insn;
329324
let used_label = ref None in
330325
let get_label () =
@@ -354,12 +349,13 @@ module Make (S : Compute_ranges_intf.S_functor) = struct
354349
then Misc.fatal_errorf "Key %a already has an open range" S.Key.print key;
355350
(* If the range is later discarded, the inserted label may actually be
356351
useless, but this doesn't matter. It does not generate any code. *)
357-
if debug then Format.eprintf "opening subrange for %a\n%!" S.Key.print key;
352+
if !Flambda_backend_flags.dranges
353+
then Format.eprintf "opening subrange for %a\n%!" S.Key.print key;
358354
let label, label_insn = get_label () in
359355
KM.add key (label, start_pos_offset, label_insn) currently_open_subranges
360356
in
361357
let close_subrange key ~end_pos_offset ~currently_open_subranges =
362-
if debug
358+
if !Flambda_backend_flags.dranges
363359
then Format.eprintf "closing subrange for key %a\n" S.Key.print key;
364360
match KM.find key currently_open_subranges with
365361
| exception Not_found ->
@@ -412,12 +408,14 @@ module Make (S : Compute_ranges_intf.S_functor) = struct
412408
in
413409
(* Apply actions *)
414410
let no_actions = List.compare_length_with actions 0 = 0 in
415-
if debug && no_actions then Format.eprintf "no actions to apply\n%!";
416-
if debug && not no_actions then Format.eprintf "applying actions:\n%!";
411+
if !Flambda_backend_flags.dranges && no_actions
412+
then Format.eprintf "no actions to apply\n%!";
413+
if !Flambda_backend_flags.dranges && not no_actions
414+
then Format.eprintf "applying actions:\n%!";
417415
let currently_open_subranges =
418416
List.fold_left
419417
(fun currently_open_subranges (key, (action : action)) ->
420-
if debug
418+
if !Flambda_backend_flags.dranges
421419
then
422420
Format.eprintf " --> action for key %a: %a\n" S.Key.print key
423421
print_action action;
@@ -437,13 +435,14 @@ module Make (S : Compute_ranges_intf.S_functor) = struct
437435
close_subrange key ~end_pos_offset:1 ~currently_open_subranges)
438436
currently_open_subranges actions
439437
in
440-
if debug && not no_actions
438+
if !Flambda_backend_flags.dranges && not no_actions
441439
then Format.eprintf "finished applying actions.\n%!";
442440
(* Close all subranges if at last instruction *)
443441
let currently_open_subranges =
444442
match insn.desc with
445443
| Lend ->
446-
if debug then Format.eprintf "closing subranges for last insn\n%!";
444+
if !Flambda_backend_flags.dranges
445+
then Format.eprintf "closing subranges for last insn\n%!";
447446
let currently_open_subranges =
448447
KM.fold
449448
(fun key _ currently_open_subranges ->
@@ -521,7 +520,8 @@ module Make (S : Compute_ranges_intf.S_functor) = struct
521520
let empty = { ranges = S.Index.Tbl.create 1 }
522521

523522
let create (fundecl : L.fundecl) =
524-
if debug then Format.eprintf "Compute_ranges for %s\n" fundecl.fun_name;
523+
if !Flambda_backend_flags.dranges
524+
then Format.eprintf "Compute_ranges for %s\n" fundecl.fun_name;
525525
let t = { ranges = S.Index.Tbl.create 42 } in
526526
let first_insn =
527527
process_instructions t fundecl

driver/flambda_backend_args.ml

+7
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,9 @@ let mk_dump_inlining_paths f =
130130
let mk_davail f =
131131
"-davail", Arg.Unit f, " Dump register availability information"
132132

133+
let mk_dranges f =
134+
"-dranges", Arg.Unit f, " Dump results of Compute_ranges"
135+
133136
let mk_ddebug_invariants f =
134137
"-ddebug-invariants", Arg.Unit f, " Run invariant checks during generation of debugging information"
135138

@@ -551,6 +554,7 @@ module type Flambda_backend_options = sig
551554
val no_ocamlcfg : unit -> unit
552555
val dump_inlining_paths : unit -> unit
553556
val davail : unit -> unit
557+
val dranges : unit -> unit
554558
val ddebug_invariants : unit -> unit
555559
val dcfg : unit -> unit
556560
val dcfg_invariants : unit -> unit
@@ -650,6 +654,7 @@ struct
650654
let list2 = [
651655
mk_dump_inlining_paths F.dump_inlining_paths;
652656
mk_davail F.davail;
657+
mk_dranges F.dranges;
653658
mk_ddebug_invariants F.ddebug_invariants;
654659
mk_ocamlcfg F.ocamlcfg;
655660
mk_no_ocamlcfg F.no_ocamlcfg;
@@ -807,6 +812,7 @@ module Flambda_backend_options_impl = struct
807812
let dump_inlining_paths = set' Flambda_backend_flags.dump_inlining_paths
808813

809814
let davail = set' Flambda_backend_flags.davail
815+
let dranges = set' Flambda_backend_flags.dranges
810816

811817
let ddebug_invariants = set' Dwarf_flags.ddebug_invariants
812818

@@ -1062,6 +1068,7 @@ module Extra_params = struct
10621068
| "cfg-peephole-optimize" -> set' Flambda_backend_flags.cfg_peephole_optimize
10631069
| "dump-inlining-paths" -> set' Flambda_backend_flags.dump_inlining_paths
10641070
| "davail" -> set' Flambda_backend_flags.davail
1071+
| "dranges" -> set' Flambda_backend_flags.dranges
10651072
| "ddebug-invariants" -> set' Dwarf_flags.ddebug_invariants
10661073
| "reorder-blocks-random" ->
10671074
set_int_option' Flambda_backend_flags.reorder_blocks_random

driver/flambda_backend_args.mli

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ module type Flambda_backend_options = sig
2424
val no_ocamlcfg : unit -> unit
2525
val dump_inlining_paths : unit -> unit
2626
val davail : unit -> unit
27+
val dranges : unit -> unit
2728
val ddebug_invariants : unit -> unit
2829
val dcfg : unit -> unit
2930
val dcfg_invariants : unit -> unit

driver/flambda_backend_flags.ml

+1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ type 'a or_default = Set of 'a | Default
5757

5858
let dump_inlining_paths = ref false
5959
let davail = ref false
60+
let dranges = ref false
6061

6162
let opt_level = ref Default
6263

driver/flambda_backend_flags.mli

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ val heap_reduction_threshold : int ref
3434
val dump_checkmach : bool ref
3535

3636
val davail : bool ref
37+
val dranges : bool ref
3738

3839
type checkmach_details_cutoff =
3940
| Keep_all

0 commit comments

Comments
 (0)