Skip to content

Commit f88af3e

Browse files
authored
flambda-backend: Wire in the remaining Flambda 2 flags (#103)
1 parent 678d647 commit f88af3e

File tree

4 files changed

+149
-9
lines changed

4 files changed

+149
-9
lines changed

driver/main_args.ml

Lines changed: 108 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ let mk_inline_toplevel f =
180180

181181
let mk_inlining_report f =
182182
"-inlining-report", Arg.Unit f, " Emit `.<round>.inlining' file(s) (one per \
183-
round) showing the inliner's decisions"
183+
round) showing the inliner's decisions (Flambda 1 and 2)"
184184
;;
185185

186186
let mk_dump_pass f =
@@ -764,30 +764,30 @@ let mk_dclambda f =
764764
;;
765765

766766
let mk_dflambda f =
767-
"-dflambda", Arg.Unit f, " Print Flambda terms"
767+
"-dflambda", Arg.Unit f, " Print Flambda (1 or 2) terms on exit from Flambda"
768768
;;
769769

770770
let mk_drawflambda f =
771-
"-drawflambda", Arg.Unit f, " Print Flambda terms after closure conversion"
771+
"-drawflambda", Arg.Unit f, " Print Flambda terms after closure conversion\n\
772+
\ (for Flambda 2, after [Lambda_to_flambda])"
772773
;;
773774

774775
let mk_dflambda_invariants f =
775-
"-dflambda-invariants", Arg.Unit f, " Check Flambda invariants \
776-
around each pass"
776+
"-dflambda-invariants", Arg.Unit f, " Check Flambda (1 and 2) invariants"
777777
;;
778778

779779
let mk_dflambda_no_invariants f =
780-
"-dflambda-no-invariants", Arg.Unit f, " Do not Check Flambda invariants \
781-
around each pass"
780+
"-dflambda-no-invariants", Arg.Unit f, " Do not check Flambda (1 and 2) \
781+
invariants"
782782
;;
783783

784784
let mk_dflambda_let f =
785-
"-dflambda-let", Arg.Int f, "<stamp> Print when the given Flambda [Let] \
785+
"-dflambda-let", Arg.Int f, "<stamp> Print when the given Flambda 1 [Let] \
786786
is created"
787787
;;
788788

789789
let mk_dflambda_verbose f =
790-
"-dflambda-verbose", Arg.Unit f, " Print Flambda terms including around \
790+
"-dflambda-verbose", Arg.Unit f, " Print Flambda 1 terms including around \
791791
each pass"
792792
;;
793793

@@ -1151,6 +1151,52 @@ let mk_flambda2_inline_threshold f =
11511151
\ Aggressiveness of inlining (default %.02f, higher numbers mean\n\
11521152
\ more aggressive) (Flambda 2 only)"
11531153
Clflags.Flambda2.Inlining.Default.threshold
1154+
1155+
let mk_flambda2_treat_invalid_code_as_unreachable f =
1156+
"-flambda2-treat-invalid-code-as-unreachable", Arg.Unit f,
1157+
Printf.sprintf " Treat code deemed as\n\
1158+
\ invalid by the Flambda 2 type system as unreachable, thus causing\n\
1159+
\ it (and potentially calling code) to be deleted%s\n\
1160+
\ (Flambda 2 only)"
1161+
(format_default Flambda2.Default.treat_invalid_code_as_unreachable)
1162+
;;
1163+
1164+
let mk_no_flambda2_treat_invalid_code_as_unreachable f =
1165+
"-no-flambda2-treat-invalid-code-as-unreachable", Arg.Unit f,
1166+
Printf.sprintf " Do not treat code deemed as\n\
1167+
\ invalid by the Flambda 2 type system as unreachable, instead\n\
1168+
\ replacing it by a trap (which currently causes a segfault)%s\n\
1169+
\ (Flambda 2 only)"
1170+
(format_not_default Flambda2.Default.treat_invalid_code_as_unreachable)
1171+
;;
1172+
1173+
let mk_flambda2_inlining_report_bin f =
1174+
"-flambda2-inlining-report-bin", Arg.Unit f, " Write inlining report\n\
1175+
\ in binary format (Flambda 2 only)"
1176+
;;
1177+
1178+
let mk_flambda2_unicode f =
1179+
"-flambda2-unicode", Arg.Unit f, " Use Unicode output when printing\n\
1180+
\ Flambda 2 code"
1181+
;;
1182+
1183+
let mk_drawfexpr f =
1184+
"-drawfexpr", Arg.Unit f, " Like -drawflambda but outputs fexpr language\n\
1185+
\ (Flambda 2 only)"
1186+
;;
1187+
1188+
let mk_dfexpr f =
1189+
"-dfexpr", Arg.Unit f, " Like -dflambda but outputs fexpr language\n\
1190+
\ (Flambda 2 only)"
1191+
;;
1192+
1193+
let mk_dflexpect f =
1194+
"-dflexpect", Arg.Unit f, " Like -dflambda but outputs a .flt file\n\
1195+
\ whose basename matches that of the input .ml file (Flambda 2 only)"
1196+
;;
1197+
1198+
let mk_dclosure_offsets f =
1199+
"-dclosure-offsets", Arg.Unit f, " Dump closure offsets (Flambda 2 only)"
11541200
;;
11551201

11561202
module type Common_options = sig
@@ -1392,6 +1438,18 @@ module type Optcommon_options = sig
13921438
val _flambda2_inline_small_function_size : string -> unit
13931439
val _flambda2_inline_large_function_size : string -> unit
13941440
val _flambda2_inline_threshold : string -> unit
1441+
1442+
val _flambda2_inlining_report_bin : unit -> unit
1443+
1444+
val _flambda2_unicode : unit -> unit
1445+
1446+
val _flambda2_treat_invalid_code_as_unreachable : unit -> unit
1447+
val _no_flambda2_treat_invalid_code_as_unreachable : unit -> unit
1448+
1449+
val _drawfexpr : unit -> unit
1450+
val _dfexpr : unit -> unit
1451+
val _dflexpect : unit -> unit
1452+
val _dclosure_offsets : unit -> unit
13951453
end;;
13961454

13971455
module type Optcomp_options = sig
@@ -1778,6 +1836,15 @@ struct
17781836
F._flambda2_inline_large_function_size;
17791837
mk_flambda2_inline_threshold F._flambda2_inline_threshold;
17801838

1839+
mk_flambda2_inlining_report_bin F._flambda2_inlining_report_bin;
1840+
1841+
mk_flambda2_unicode F._flambda2_unicode;
1842+
1843+
mk_flambda2_treat_invalid_code_as_unreachable
1844+
F._flambda2_treat_invalid_code_as_unreachable;
1845+
mk_no_flambda2_treat_invalid_code_as_unreachable
1846+
F._no_flambda2_treat_invalid_code_as_unreachable;
1847+
17811848
mk_match_context_rows F._match_context_rows;
17821849
mk_dno_unique_ids F._dno_unique_ids;
17831850
mk_dunique_ids F._dunique_ids;
@@ -1796,6 +1863,10 @@ struct
17961863
mk_dflambda_no_invariants F._dflambda_no_invariants;
17971864
mk_dflambda_let F._dflambda_let;
17981865
mk_dflambda_verbose F._dflambda_verbose;
1866+
mk_drawfexpr F._drawfexpr;
1867+
mk_dfexpr F._dfexpr;
1868+
mk_dflexpect F._dflexpect;
1869+
mk_dclosure_offsets F._dclosure_offsets;
17991870
mk_dcmm F._dcmm;
18001871
mk_dsel F._dsel;
18011872
mk_dcombine F._dcombine;
@@ -1947,6 +2018,20 @@ module Make_opttop_options (F : Opttop_options) = struct
19472018
F._flambda2_inline_large_function_size;
19482019
mk_flambda2_inline_threshold F._flambda2_inline_threshold;
19492020

2021+
mk_flambda2_inlining_report_bin F._flambda2_inlining_report_bin;
2022+
2023+
mk_flambda2_unicode F._flambda2_unicode;
2024+
2025+
mk_flambda2_treat_invalid_code_as_unreachable
2026+
F._flambda2_treat_invalid_code_as_unreachable;
2027+
mk_no_flambda2_treat_invalid_code_as_unreachable
2028+
F._no_flambda2_treat_invalid_code_as_unreachable;
2029+
2030+
mk_drawfexpr F._drawfexpr;
2031+
mk_dfexpr F._dfexpr;
2032+
mk_dflexpect F._dflexpect;
2033+
mk_dclosure_offsets F._dclosure_offsets;
2034+
19502035
mk_dsource F._dsource;
19512036
mk_dparsetree F._dparsetree;
19522037
mk_dtypedtree F._dtypedtree;
@@ -2323,6 +2408,20 @@ module Default = struct
23232408
Float_arg_helper.parse spec
23242409
"Syntax: -flambda2-inline-threshold <float> | <round>=<float>[,...]"
23252410
Flambda2.Inlining.threshold
2411+
2412+
let _flambda2_inlining_report_bin = set Flambda2.Inlining.report_bin
2413+
2414+
let _flambda2_unicode = set Flambda2.unicode
2415+
2416+
let _flambda2_treat_invalid_code_as_unreachable =
2417+
set Flambda2.treat_invalid_code_as_unreachable
2418+
let _no_flambda2_treat_invalid_code_as_unreachable =
2419+
clear Flambda2.treat_invalid_code_as_unreachable
2420+
2421+
let _drawfexpr = set Flambda2.Dump.rawfexpr
2422+
let _dfexpr = set Flambda2.Dump.fexpr
2423+
let _dflexpect = set Flambda2.Dump.flexpect
2424+
let _dclosure_offsets = set Flambda2.Dump.closure_offsets
23262425
end
23272426

23282427
module Compiler = struct

driver/main_args.mli

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,18 @@ module type Optcommon_options = sig
254254
val _flambda2_inline_small_function_size : string -> unit
255255
val _flambda2_inline_large_function_size : string -> unit
256256
val _flambda2_inline_threshold : string -> unit
257+
258+
val _flambda2_inlining_report_bin : unit -> unit
259+
260+
val _flambda2_unicode : unit -> unit
261+
262+
val _flambda2_treat_invalid_code_as_unreachable : unit -> unit
263+
val _no_flambda2_treat_invalid_code_as_unreachable : unit -> unit
264+
265+
val _drawfexpr : unit -> unit
266+
val _dfexpr : unit -> unit
267+
val _dflexpect : unit -> unit
268+
val _dclosure_offsets : unit -> unit
257269
end;;
258270

259271
module type Optcomp_options = sig

utils/clflags.ml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,13 +463,25 @@ module Flambda2 = struct
463463
let unbox_along_intra_function_control_flow = true
464464
let backend_cse_at_toplevel = false
465465
let cse_depth = 2
466+
let treat_invalid_code_as_unreachable = false
467+
let unicode = true
466468
end
467469

468470
let join_points = ref Default.join_points
469471
let unbox_along_intra_function_control_flow =
470472
ref Default.unbox_along_intra_function_control_flow
471473
let backend_cse_at_toplevel = ref Default.backend_cse_at_toplevel
472474
let cse_depth = ref Default.cse_depth
475+
let treat_invalid_code_as_unreachable =
476+
ref Default.treat_invalid_code_as_unreachable
477+
let unicode = ref Default.unicode
478+
479+
module Dump = struct
480+
let rawfexpr = ref false
481+
let fexpr = ref false
482+
let flexpect = ref false
483+
let closure_offsets = ref false
484+
end
473485

474486
module Expert = struct
475487
module Default = struct
@@ -537,6 +549,8 @@ module Flambda2 = struct
537549
let large_function_size = ref (I.default Default.large_function_size)
538550

539551
let threshold = ref (F.default Default.threshold)
552+
553+
let report_bin = ref false
540554
end
541555

542556
let oclassic_flags () =

utils/clflags.mli

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,12 +243,25 @@ module Flambda2 : sig
243243
val unbox_along_intra_function_control_flow : bool
244244
val backend_cse_at_toplevel : bool
245245
val cse_depth : int
246+
val treat_invalid_code_as_unreachable : bool
247+
248+
val unicode : bool
246249
end
247250

248251
val join_points : bool ref
249252
val unbox_along_intra_function_control_flow : bool ref
250253
val backend_cse_at_toplevel : bool ref
251254
val cse_depth : int ref
255+
val treat_invalid_code_as_unreachable : bool ref
256+
257+
val unicode : bool ref
258+
259+
module Dump : sig
260+
val rawfexpr : bool ref
261+
val fexpr : bool ref
262+
val flexpect : bool ref
263+
val closure_offsets : bool ref
264+
end
252265

253266
module Expert : sig
254267
module Default : sig
@@ -308,6 +321,8 @@ module Flambda2 : sig
308321
val large_function_size : Int_arg_helper.parsed ref
309322

310323
val threshold : Float_arg_helper.parsed ref
324+
325+
val report_bin : bool ref
311326
end
312327

313328
val oclassic_flags : unit -> unit

0 commit comments

Comments
 (0)