forked from ocaml-flambda/flambda-backend
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathflambda_backend_args.ml
930 lines (810 loc) · 37.6 KB
/
flambda_backend_args.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
(**************************************************************************)
(* *)
(* OCaml *)
(* *)
(* Pierre Chambart, OCamlPro *)
(* Mark Shinwell and Leo White, Jane Street Europe *)
(* *)
(* Copyright 2013--2021 OCamlPro SAS *)
(* Copyright 2014--2021 Jane Street Group LLC *)
(* *)
(* All rights reserved. This file is distributed under the terms of *)
(* the GNU Lesser General Public License version 2.1, with the *)
(* special exception on linking described in the file LICENSE. *)
(* *)
(**************************************************************************)
let format_default flag = if flag then " (default)" else ""
let format_not_default flag = if flag then "" else " (default)"
let mk_ocamlcfg f =
"-ocamlcfg", Arg.Unit f, " Use ocamlcfg"
let mk_no_ocamlcfg f =
"-no-ocamlcfg", Arg.Unit f, " Do not use ocamlcfg"
;;
let mk_dcfg f =
"-dcfg", Arg.Unit f, " (undocumented)"
;;
let mk_dcfg_invariants f =
"-dcfg-invariants", Arg.Unit f, " Extra sanity checks on Cfg"
let mk_dcfg_equivalence_check f =
"-dcfg-equivalence-check", Arg.Unit f, " Extra sanity checks on Cfg transformations"
let mk_reorder_blocks_random f =
"-reorder-blocks-random",
Arg.Int f,
Printf.sprintf "<seed> Randomly reorder basic blocks in every function, \
using the provided seed (intended for testing, off by default)."
let mk_dasm_comments f =
"-dasm-comments", Arg.Unit f, " Add comments in .s files (e.g. for DWARF)"
let mk_dno_asm_comments f =
"-dno-asm-comments", Arg.Unit f, " Do not add comments in .s files"
let mk_heap_reduction_threshold f =
"-heap-reduction-threshold",
Arg.Int f,
Printf.sprintf " Threshold (in major words, defaulting to %d) to trigger a heap reduction before code emission"
Flambda_backend_flags.default_heap_reduction_threshold
;;
let mk_dump_inlining_paths f =
"-dump-inlining-paths", Arg.Unit f, " Dump inlining paths when dumping flambda2 terms"
let mk_internal_assembler f =
"-internal-assembler", Arg.Unit f, "Write object files directly instead of using the system assembler (x86-64 ELF only)"
module Flambda2 = Flambda_backend_flags.Flambda2
let mk_flambda2_result_types_functors_only f =
"-flambda2-result-types-functors-only", Arg.Unit f,
Printf.sprintf " Infer result types for functors (but no other\n\
\ functions)%s (Flambda 2 only)"
(format_default (
match Flambda2.Default.function_result_types with
| Functors_only -> true
| Never | All_functions -> false))
;;
let mk_flambda2_result_types_all_functions f =
"-flambda2-result-types-all-functions", Arg.Unit f,
Printf.sprintf " Infer result types for all functions\n\
\ (including functors)%s (Flambda 2 only)"
(format_default (
match Flambda2.Default.function_result_types with
| All_functions -> true
| Never | Functors_only -> false))
;;
let mk_no_flambda2_result_types f =
"-flambda2-result-types", Arg.Unit f,
Printf.sprintf " Do not infer result types for functions (or\n\
\ functors)%s (Flambda 2 only)"
(format_default (
match Flambda2.Default.function_result_types with
| Never -> true
| Functors_only | All_functions -> false))
;;
let mk_flambda2_join_points f =
"-flambda2-join-points", Arg.Unit f,
Printf.sprintf " Propagate information from all incoming edges to a join\n\
\ point%s (Flambda 2 only)"
(format_default Flambda2.Default.join_points)
;;
let mk_no_flambda2_join_points f =
"-no-flambda2-join-points", Arg.Unit f,
Printf.sprintf " Propagate information to a join point only if there are\n\
\ zero or one incoming edge(s)%s (Flambda 2 only)"
(format_not_default Flambda2.Default.join_points)
;;
let mk_flambda2_unbox_along_intra_function_control_flow f =
"-flambda2-unbox-along-intra-function-control-flow", Arg.Unit f,
Printf.sprintf " Pass values within\n\
\ a function as unboxed where possible%s (Flambda 2 only)"
(format_default Flambda2.Default.unbox_along_intra_function_control_flow)
;;
let mk_no_flambda2_unbox_along_intra_function_control_flow f =
"-no-flambda2-unbox-along-intra-function-control-flow", Arg.Unit f,
Printf.sprintf " Pass values within\n\
\ a function in their normal representation%s (Flambda 2 only)"
(format_not_default
Flambda2.Default.unbox_along_intra_function_control_flow)
;;
let mk_flambda2_backend_cse_at_toplevel f =
"-flambda2-backend-cse-at-toplevel", Arg.Unit f,
Printf.sprintf " Apply the backend CSE pass to module\n\
\ initializers%s (Flambda 2 only)"
(format_default Flambda2.Default.backend_cse_at_toplevel)
;;
let mk_no_flambda2_backend_cse_at_toplevel f =
"-no-flambda2-backend-cse-at-toplevel", Arg.Unit f,
Printf.sprintf " Do not apply the backend CSE pass to\n\
\ module initializers%s (Flambda 2 only)"
(format_not_default Flambda2.Default.backend_cse_at_toplevel)
;;
let mk_flambda2_cse_depth f =
"-flambda2-cse-depth", Arg.Int f,
Printf.sprintf " Depth threshold for eager tracking of CSE equations\n\
\ (default %d) (Flambda 2 only)"
Flambda2.Default.cse_depth
;;
let mk_flambda2_join_depth f =
"-flambda2-join-depth", Arg.Int f,
Printf.sprintf " Depth threshold for alias expansion in join\n\
\ (default %d) (Flambda 2 only)"
Flambda2.Default.join_depth
;;
let mk_flambda2_expert_fallback_inlining_heuristic f =
"-flambda2-expert-fallback-inlining-heuristic", Arg.Unit f,
Printf.sprintf " Prevent inlining of functions\n\
\ whose bodies contain closures%s (Flambda 2 only)"
(format_default Flambda2.Expert.Default.fallback_inlining_heuristic)
;;
let mk_no_flambda2_expert_fallback_inlining_heuristic f =
"-no-flambda2-expert-fallback-inlining-heuristic", Arg.Unit f,
Printf.sprintf " Allow inlining of functions\n\
\ whose bodies contain closures%s (Flambda 2 only)"
(format_not_default Flambda2.Expert.Default.fallback_inlining_heuristic)
;;
let mk_flambda2_expert_inline_effects_in_cmm f =
"-flambda2-expert-inline-effects-in-cmm", Arg.Unit f,
Printf.sprintf " Allow inlining of effectful\n\
\ expressions in the produced Cmm code\n\
\ into any context%s (Flambda 2 only)"
(format_default Flambda2.Expert.Default.inline_effects_in_cmm)
;;
let mk_no_flambda2_expert_inline_effects_in_cmm f =
"-no-flambda2-expert-inline-effects-in-cmm", Arg.Unit f,
Printf.sprintf " Only allow inlining of effectful\n\
\ expressions in the produced Cmm code into\n\
\ the arguments of allocation primitives%s (Flambda 2 only)"
(format_not_default Flambda2.Expert.Default.inline_effects_in_cmm)
;;
let mk_flambda2_expert_phantom_lets f =
"-flambda2-expert-phantom-lets", Arg.Unit f,
Printf.sprintf " Generate phantom lets when -g\n\
\ is specified%s (Flambda 2 only)"
(format_default Flambda2.Expert.Default.phantom_lets)
;;
let mk_no_flambda2_expert_phantom_lets f =
"-no-flambda2-expert-phantom-lets", Arg.Unit f,
Printf.sprintf " Do not generate phantom lets even when -g\n\
\ is specified%s (Flambda 2 only)"
(format_not_default Flambda2.Expert.Default.phantom_lets)
;;
let mk_flambda2_expert_max_block_size_for_projections f =
"-flambda2-expert-max-block-size-for-projections", Arg.Int f,
Printf.sprintf " Do not simplify projections\n\
\ from blocks if the block size exceeds this value (default %s)\n\
\ (Flambda 2 only)"
(match Flambda2.Expert.Default.max_block_size_for_projections with
| None -> "not set"
| Some max -> string_of_int max)
;;
let mk_flambda2_expert_max_unboxing_depth f =
"-flambda2-expert-max-unboxing-depth", Arg.Int f,
Printf.sprintf " Do not unbox (nested) values deeper\n\
\ than this many levels (default %d) (Flambda 2 only)"
Flambda2.Expert.Default.max_unboxing_depth
;;
let mk_flambda2_expert_can_inline_recursive_functions f =
"-flambda2-expert-can-inline-recursive-functions", Arg.Unit f,
Printf.sprintf " Consider inlining\n\
\ recursive functions (default %s) (Flambda 2 only)"
(format_default Flambda2.Expert.Default.can_inline_recursive_functions)
;;
let mk_no_flambda2_expert_can_inline_recursive_functions f =
"-no-flambda2-expert-can-inline-recursive-functions", Arg.Unit f,
Printf.sprintf " Only inline recursive\n\
\ functions if forced to so do by an attribute\n\
\ (default %s) (Flambda 2 only)"
(format_not_default Flambda2.Expert.Default.can_inline_recursive_functions)
;;
let mk_flambda2_debug_concrete_types_only_on_canonicals f =
"-flambda2-debug-concrete-types-only-on-canonicals", Arg.Unit f,
Printf.sprintf " Check that concrete\n\
\ types are only assigned to canonical\n\
\ names%s (Flambda 2 only)"
(format_default Flambda2.Debug.Default.concrete_types_only_on_canonicals)
;;
let mk_no_flambda2_debug_concrete_types_only_on_canonicals f =
"-no-flambda2-debug-concrete-types-only-on-canonicals", Arg.Unit f,
Printf.sprintf " Do not check that\n\
\ concrete types are only assigned to canonical\n\
\ names%s (Flambda 2 only)"
(format_not_default
Flambda2.Debug.Default.concrete_types_only_on_canonicals)
;;
let mk_flambda2_debug_keep_invalid_handlers f =
"-flambda2-debug-keep-invalid-handlers", Arg.Unit f,
Printf.sprintf " Keep branches simplified\n\
\ to Invalid%s (Flambda 2 only)"
(format_default Flambda2.Debug.Default.keep_invalid_handlers)
;;
let mk_no_flambda2_debug_keep_invalid_handlers f =
"-no-flambda2-debug-keep-invalid-handlers", Arg.Unit f,
Printf.sprintf " Delete branches simplified\n\
\ to Invalid%s (Flambda 2 only)"
(format_not_default Flambda2.Debug.Default.keep_invalid_handlers)
;;
let mk_flambda2_inline_max_depth f =
"-flambda2-inline-max-depth", Arg.String f,
Printf.sprintf "<int>|<round>=<int>[,...]\n\
\ Maximum depth of search for inlining opportunities inside\n\
\ inlined functions (default %d) (Flambda 2 only)"
Flambda_backend_flags.Flambda2.Inlining.Default.max_depth
;;
let mk_flambda2_inline_max_rec_depth f =
"-flambda2-inline-max-rec-depth", Arg.String f,
Printf.sprintf "<int>|<round>=<int>[,...]\n\
\ Maximum depth of search for inlining opportunities inside\n\
\ inlined recursive functions (default %d) (Flambda 2 only)"
Flambda_backend_flags.Flambda2.Inlining.Default.max_rec_depth
;;
let mk_flambda2_inline_cost arg descr ~default f =
Printf.sprintf "-flambda2-inline-%s-cost" arg,
Arg.String f,
Printf.sprintf "<float>|<round>=<float>[,...]\n\
\ The cost of not removing %s during inlining\n\
\ (default %.03f, higher = more costly) (Flambda 2 only)"
descr
default
;;
let mk_flambda2_inline_call_cost =
mk_flambda2_inline_cost "call" "a call"
~default:Flambda_backend_flags.Flambda2.Inlining.Default.call_cost
let mk_flambda2_inline_alloc_cost =
mk_flambda2_inline_cost "alloc" "an allocation"
~default:Flambda_backend_flags.Flambda2.Inlining.Default.alloc_cost
let mk_flambda2_inline_prim_cost =
mk_flambda2_inline_cost "prim" "a primitive"
~default:Flambda_backend_flags.Flambda2.Inlining.Default.prim_cost
let mk_flambda2_inline_branch_cost =
mk_flambda2_inline_cost "branch" "a conditional"
~default:Flambda_backend_flags.Flambda2.Inlining.Default.branch_cost
let mk_flambda2_inline_indirect_call_cost =
mk_flambda2_inline_cost "indirect" "an indirect call"
~default:Flambda_backend_flags.Flambda2.Inlining.Default.indirect_call_cost
let mk_flambda2_inline_poly_compare_cost =
mk_flambda2_inline_cost "poly-compare" "a polymorphic comparison"
~default:Flambda_backend_flags.Flambda2.Inlining.Default.poly_compare_cost
(* CR-someday mshinwell: We should have a check that the parameters provided by
the user are sensible, e.g. small_function_size <= large_function_size. *)
let mk_flambda2_inline_small_function_size f =
"-flambda2-inline-small-function-size", Arg.String f,
Printf.sprintf "<int>|<round>=<int>[,...]\n\
\ Functions with a cost less than this will always be inlined\n\
\ unless an attribute instructs otherwise (default %d)\n\
\ (Flambda 2 only)"
Flambda_backend_flags.Flambda2.Inlining.Default.small_function_size
;;
let mk_flambda2_inline_large_function_size f =
"-flambda2-inline-large-function-size", Arg.String f,
Printf.sprintf "<int>|<round>=<int>[,...]\n\
\ Functions with a cost greater than this will never be inlined\n\
\ unless an attribute instructs otherwise (default %d); speculative\n\
\ inlining will be disabled if equal to the small function size\n\
\ (Flambda 2 only)"
Flambda_backend_flags.Flambda2.Inlining.Default.large_function_size
;;
let mk_flambda2_inline_threshold f =
"-flambda2-inline-threshold", Arg.String f,
Printf.sprintf "<float>|<round>=<float>[,...]\n\
\ Aggressiveness of inlining (default %.02f, higher numbers mean\n\
\ more aggressive) (Flambda 2 only)"
Flambda_backend_flags.Flambda2.Inlining.Default.threshold
let mk_flambda2_speculative_inlining_only_if_arguments_useful f =
"-flambda2-speculative-inlining-only-if-arguments-useful", Arg.Unit f,
Printf.sprintf " Only\n\
\ perform speculative inlining if the Flambda type system has\n\
\ useful information about the argument(s) at the call site%s\n\
\ (Flambda 2 only)"
(format_default
Flambda2.Inlining.Default.speculative_inlining_only_if_arguments_useful)
let mk_no_flambda2_speculative_inlining_only_if_arguments_useful f =
"-no-flambda2-speculative-inlining-only-if-arguments-useful", Arg.Unit f,
Printf.sprintf " Ignore\n\
\ whether the Flambda type system has useful information\n\
\ about the argument(s) at the call site when performing\n\
\ speculative inlining%s (Flambda 2 only)"
(format_not_default
Flambda2.Inlining.Default.speculative_inlining_only_if_arguments_useful)
let mk_flambda2_inlining_report_bin f =
"-flambda2-inlining-report-bin", Arg.Unit f, " Write inlining report\n\
\ in binary format (Flambda 2 only)"
;;
let mk_flambda2_unicode f =
"-flambda2-unicode", Arg.Unit f, " Use Unicode output when printing\n\
\ Flambda 2 code"
;;
let mk_drawfexpr f =
"-drawfexpr", Arg.Unit f, " Like -drawflambda but outputs fexpr language\n\
\ (Flambda 2 only)"
;;
let mk_dfexpr f =
"-dfexpr", Arg.Unit f, " Like -dflambda but outputs fexpr language\n\
\ (Flambda 2 only)"
;;
let mk_dflexpect f =
"-dflexpect", Arg.Unit f, " Like -dflambda but outputs a .flt file\n\
\ whose basename matches that of the input .ml file (Flambda 2 only)"
;;
let mk_dslot_offsets f =
"-dslot-offsets", Arg.Unit f, " Dump closure offsets (Flambda 2 only)"
;;
let mk_dfreshen f =
"-dfreshen", Arg.Unit f, " Freshen bound names when printing (Flambda 2 only)"
;;
module Debugging = Dwarf_flags
(* CR mshinwell: These help texts should show the default values. *)
let mk_restrict_to_upstream_dwarf f =
"-gupstream-dwarf", Arg.Unit f, " Only emit the same DWARF information as the upstream compiler"
let mk_no_restrict_to_upstream_dwarf f =
"-gno-upstream-dwarf", Arg.Unit f, " Emit potentially more DWARF information than the upstream compiler"
let mk_dwarf_for_startup_file f =
"-gstartup", Arg.Unit f, " Emit potentially more DWARF information\n\
\ for the startup file than the upstream compiler\n\
\ (only takes effect with -gno-upstream-dwarf)"
let mk_no_dwarf_for_startup_file f =
"-gno-startup", Arg.Unit f, " Emit the same DWARF information for the\n\
\ startup file as the upstream compiler"
module type Flambda_backend_options = sig
val ocamlcfg : unit -> unit
val no_ocamlcfg : unit -> unit
val dump_inlining_paths : unit -> unit
val dcfg : unit -> unit
val dcfg_invariants : unit -> unit
val dcfg_equivalence_check : unit -> unit
val reorder_blocks_random : int -> unit
val dasm_comments : unit -> unit
val dno_asm_comments : unit -> unit
val heap_reduction_threshold : int -> unit
val internal_assembler : unit -> unit
val flambda2_join_points : unit -> unit
val no_flambda2_join_points : unit -> unit
val flambda2_result_types_functors_only : unit -> unit
val flambda2_result_types_all_functions : unit -> unit
val no_flambda2_result_types : unit -> unit
val flambda2_unbox_along_intra_function_control_flow : unit -> unit
val no_flambda2_unbox_along_intra_function_control_flow : unit -> unit
val flambda2_backend_cse_at_toplevel : unit -> unit
val no_flambda2_backend_cse_at_toplevel : unit -> unit
val flambda2_cse_depth : int -> unit
val flambda2_join_depth : int -> unit
val flambda2_expert_fallback_inlining_heuristic : unit -> unit
val no_flambda2_expert_fallback_inlining_heuristic : unit -> unit
val flambda2_expert_inline_effects_in_cmm : unit -> unit
val no_flambda2_expert_inline_effects_in_cmm : unit -> unit
val flambda2_expert_phantom_lets : unit -> unit
val no_flambda2_expert_phantom_lets : unit -> unit
val flambda2_expert_max_block_size_for_projections : int -> unit
val flambda2_expert_max_unboxing_depth : int -> unit
val flambda2_expert_can_inline_recursive_functions : unit -> unit
val no_flambda2_expert_can_inline_recursive_functions : unit -> unit
val flambda2_debug_concrete_types_only_on_canonicals : unit -> unit
val no_flambda2_debug_concrete_types_only_on_canonicals : unit -> unit
val flambda2_debug_keep_invalid_handlers : unit -> unit
val no_flambda2_debug_keep_invalid_handlers : unit -> unit
val flambda2_inline_max_depth : string -> unit
val flambda2_inline_max_rec_depth : string -> unit
val flambda2_inline_call_cost : string -> unit
val flambda2_inline_alloc_cost : string -> unit
val flambda2_inline_prim_cost : string -> unit
val flambda2_inline_branch_cost : string -> unit
val flambda2_inline_indirect_call_cost : string -> unit
val flambda2_inline_poly_compare_cost : string -> unit
val flambda2_inline_small_function_size : string -> unit
val flambda2_inline_large_function_size : string -> unit
val flambda2_inline_threshold : string -> unit
val flambda2_speculative_inlining_only_if_arguments_useful : unit -> unit
val no_flambda2_speculative_inlining_only_if_arguments_useful : unit -> unit
val flambda2_inlining_report_bin : unit -> unit
val flambda2_unicode : unit -> unit
val drawfexpr : unit -> unit
val dfexpr : unit -> unit
val dflexpect : unit -> unit
val dslot_offsets : unit -> unit
val dfreshen : unit -> unit
end
module Make_flambda_backend_options (F : Flambda_backend_options) =
struct
let list2 = [
mk_dump_inlining_paths F.dump_inlining_paths;
mk_ocamlcfg F.ocamlcfg;
mk_no_ocamlcfg F.no_ocamlcfg;
mk_dcfg F.dcfg;
mk_dcfg_invariants F.dcfg_invariants;
mk_dcfg_equivalence_check F.dcfg_equivalence_check;
mk_reorder_blocks_random F.reorder_blocks_random;
mk_dasm_comments F.dasm_comments;
mk_dno_asm_comments F.dno_asm_comments;
mk_heap_reduction_threshold F.heap_reduction_threshold;
mk_internal_assembler F.internal_assembler;
mk_flambda2_join_points F.flambda2_join_points;
mk_no_flambda2_join_points F.no_flambda2_join_points;
mk_flambda2_result_types_functors_only
F.flambda2_result_types_functors_only;
mk_flambda2_result_types_all_functions
F.flambda2_result_types_all_functions;
mk_no_flambda2_result_types
F.no_flambda2_result_types;
mk_flambda2_unbox_along_intra_function_control_flow
F.flambda2_unbox_along_intra_function_control_flow;
mk_no_flambda2_unbox_along_intra_function_control_flow
F.no_flambda2_unbox_along_intra_function_control_flow;
mk_flambda2_backend_cse_at_toplevel F.flambda2_backend_cse_at_toplevel;
mk_no_flambda2_backend_cse_at_toplevel
F.no_flambda2_backend_cse_at_toplevel;
mk_flambda2_cse_depth F.flambda2_cse_depth;
mk_flambda2_join_depth F.flambda2_join_depth;
mk_flambda2_expert_fallback_inlining_heuristic
F.flambda2_expert_fallback_inlining_heuristic;
mk_no_flambda2_expert_fallback_inlining_heuristic
F.no_flambda2_expert_fallback_inlining_heuristic;
mk_flambda2_expert_inline_effects_in_cmm
F.flambda2_expert_inline_effects_in_cmm;
mk_no_flambda2_expert_inline_effects_in_cmm
F.no_flambda2_expert_inline_effects_in_cmm;
mk_flambda2_expert_phantom_lets
F.flambda2_expert_phantom_lets;
mk_no_flambda2_expert_phantom_lets
F.no_flambda2_expert_phantom_lets;
mk_flambda2_expert_max_block_size_for_projections
F.flambda2_expert_max_block_size_for_projections;
mk_flambda2_expert_max_unboxing_depth
F.flambda2_expert_max_unboxing_depth;
mk_flambda2_expert_can_inline_recursive_functions
F.flambda2_expert_can_inline_recursive_functions;
mk_no_flambda2_expert_can_inline_recursive_functions
F.no_flambda2_expert_can_inline_recursive_functions;
mk_flambda2_debug_concrete_types_only_on_canonicals
F.flambda2_debug_concrete_types_only_on_canonicals;
mk_no_flambda2_debug_concrete_types_only_on_canonicals
F.no_flambda2_debug_concrete_types_only_on_canonicals;
mk_flambda2_debug_keep_invalid_handlers
F.flambda2_debug_keep_invalid_handlers;
mk_no_flambda2_debug_keep_invalid_handlers
F.no_flambda2_debug_keep_invalid_handlers;
mk_flambda2_inline_max_depth F.flambda2_inline_max_depth;
mk_flambda2_inline_max_rec_depth F.flambda2_inline_max_rec_depth;
mk_flambda2_inline_alloc_cost F.flambda2_inline_alloc_cost;
mk_flambda2_inline_branch_cost F.flambda2_inline_branch_cost;
mk_flambda2_inline_call_cost F.flambda2_inline_call_cost;
mk_flambda2_inline_prim_cost F.flambda2_inline_prim_cost;
mk_flambda2_inline_indirect_call_cost F.flambda2_inline_indirect_call_cost;
mk_flambda2_inline_poly_compare_cost F.flambda2_inline_poly_compare_cost;
mk_flambda2_inline_small_function_size
F.flambda2_inline_small_function_size;
mk_flambda2_inline_large_function_size
F.flambda2_inline_large_function_size;
mk_flambda2_inline_threshold F.flambda2_inline_threshold;
mk_flambda2_speculative_inlining_only_if_arguments_useful
F.flambda2_speculative_inlining_only_if_arguments_useful;
mk_no_flambda2_speculative_inlining_only_if_arguments_useful
F.no_flambda2_speculative_inlining_only_if_arguments_useful;
mk_flambda2_inlining_report_bin F.flambda2_inlining_report_bin;
mk_flambda2_unicode F.flambda2_unicode;
mk_drawfexpr F.drawfexpr;
mk_dfexpr F.dfexpr;
mk_dflexpect F.dflexpect;
mk_dslot_offsets F.dslot_offsets;
mk_dfreshen F.dfreshen;
]
end
module Flambda_backend_options_impl = struct
let set r () = r := Flambda_backend_flags.Set true
let clear r () = r := Flambda_backend_flags.Set false
let set' r () = r := true
let clear' r () = r := false
let ocamlcfg = set' Flambda_backend_flags.use_ocamlcfg
let no_ocamlcfg = clear' Flambda_backend_flags.use_ocamlcfg
let dcfg = set' Flambda_backend_flags.dump_cfg
let dcfg_invariants = set' Flambda_backend_flags.cfg_invariants
let dcfg_equivalence_check = set' Flambda_backend_flags.cfg_equivalence_check
let reorder_blocks_random seed =
Flambda_backend_flags.reorder_blocks_random := Some seed
let dasm_comments =
set' Flambda_backend_flags.dasm_comments
let dno_asm_comments =
clear' Flambda_backend_flags.dasm_comments
let dump_inlining_paths = set' Flambda_backend_flags.dump_inlining_paths
let heap_reduction_threshold x =
Flambda_backend_flags.heap_reduction_threshold := x
let internal_assembler = set' Flambda_backend_flags.internal_assembler
let flambda2_join_points = set Flambda2.join_points
let no_flambda2_join_points = clear Flambda2.join_points
let flambda2_result_types_functors_only () =
Flambda2.function_result_types := Flambda_backend_flags.Set Flambda_backend_flags.Functors_only
let flambda2_result_types_all_functions () =
Flambda2.function_result_types := Flambda_backend_flags.Set Flambda_backend_flags.All_functions
let no_flambda2_result_types () =
Flambda2.function_result_types := Flambda_backend_flags.Set Flambda_backend_flags.Never
let flambda2_unbox_along_intra_function_control_flow =
set Flambda2.unbox_along_intra_function_control_flow
let no_flambda2_unbox_along_intra_function_control_flow =
clear Flambda2.unbox_along_intra_function_control_flow
let flambda2_backend_cse_at_toplevel =
set Flambda2.backend_cse_at_toplevel
let no_flambda2_backend_cse_at_toplevel =
clear Flambda2.backend_cse_at_toplevel
let flambda2_cse_depth n = Flambda2.cse_depth := Flambda_backend_flags.Set n
let flambda2_join_depth n = Flambda2.join_depth := Flambda_backend_flags.Set n
let flambda2_expert_fallback_inlining_heuristic =
set Flambda2.Expert.fallback_inlining_heuristic
let no_flambda2_expert_fallback_inlining_heuristic =
clear Flambda2.Expert.fallback_inlining_heuristic
let flambda2_expert_inline_effects_in_cmm =
set Flambda2.Expert.inline_effects_in_cmm
let no_flambda2_expert_inline_effects_in_cmm =
clear Flambda2.Expert.inline_effects_in_cmm
let flambda2_expert_phantom_lets =
set Flambda2.Expert.phantom_lets
let no_flambda2_expert_phantom_lets =
clear Flambda2.Expert.phantom_lets
let flambda2_expert_max_block_size_for_projections size =
Flambda2.Expert.max_block_size_for_projections := Flambda_backend_flags.Set (Some size)
let flambda2_expert_max_unboxing_depth depth =
Flambda2.Expert.max_unboxing_depth := Flambda_backend_flags.Set depth
let flambda2_expert_can_inline_recursive_functions () =
Flambda2.Expert.can_inline_recursive_functions := Flambda_backend_flags.Set true
let no_flambda2_expert_can_inline_recursive_functions () =
Flambda2.Expert.can_inline_recursive_functions := Flambda_backend_flags.Set false
let flambda2_debug_concrete_types_only_on_canonicals =
set' Flambda2.Debug.concrete_types_only_on_canonicals
let no_flambda2_debug_concrete_types_only_on_canonicals =
clear' Flambda2.Debug.concrete_types_only_on_canonicals
let flambda2_debug_keep_invalid_handlers =
set' Flambda2.Debug.keep_invalid_handlers
let no_flambda2_debug_keep_invalid_handlers =
clear' Flambda2.Debug.keep_invalid_handlers
let flambda2_inline_max_depth spec =
Clflags.Int_arg_helper.parse spec
"Syntax: -flambda2-inline-max-depth <int> | <round>=<int>[,...]"
Flambda2.Inlining.max_depth
let flambda2_inline_max_rec_depth spec =
Clflags.Int_arg_helper.parse spec
"Syntax: -flambda2-inline-max-rec-depth <int> | <round>=<int>[,...]"
Flambda2.Inlining.max_rec_depth
let flambda2_inline_alloc_cost spec =
Clflags.Float_arg_helper.parse spec
"Syntax: -flambda2-inline-alloc-cost <float> | <round>=<float>[,...]"
Flambda2.Inlining.alloc_cost
let flambda2_inline_branch_cost spec =
Clflags.Float_arg_helper.parse spec
"Syntax: -flambda2-inline-branch-cost <float> | <round>=<float>[,...]"
Flambda2.Inlining.branch_cost
let flambda2_inline_call_cost spec =
Clflags.Float_arg_helper.parse spec
"Syntax: -flambda2-inline-call-cost <float> | <round>=<float>[,...]"
Flambda2.Inlining.call_cost
let flambda2_inline_prim_cost spec =
Clflags.Float_arg_helper.parse spec
"Syntax: -flambda2-inline-prim-cost <float> | <round>=<float>[,...]"
Flambda2.Inlining.prim_cost
let flambda2_inline_indirect_call_cost spec =
Clflags.Float_arg_helper.parse spec
"Syntax: -flambda2-inline-indirect-call-cost <float> | \
<round>=<float>[,...]"
Flambda2.Inlining.indirect_call_cost
let flambda2_inline_poly_compare_cost spec =
Clflags.Float_arg_helper.parse spec
"Syntax: -flambda2-inline-poly-compare-cost <float> | \
<round>=<float>[,...]"
Flambda2.Inlining.poly_compare_cost
let flambda2_inline_small_function_size spec =
Clflags.Int_arg_helper.parse spec
"Syntax: -flambda2-inline-small-function-size <int> | \
<round>=<int>[,...]"
Flambda2.Inlining.small_function_size
let flambda2_inline_large_function_size spec =
Clflags.Int_arg_helper.parse spec
"Syntax: -flambda2-inline-large-function-size <int> | \
<round>=<int>[,...]"
Flambda2.Inlining.large_function_size
let flambda2_inline_threshold spec =
Clflags.Float_arg_helper.parse spec
"Syntax: -flambda2-inline-threshold <float> | <round>=<float>[,...]"
Flambda2.Inlining.threshold
let flambda2_speculative_inlining_only_if_arguments_useful =
set' Flambda2.Inlining.speculative_inlining_only_if_arguments_useful
let no_flambda2_speculative_inlining_only_if_arguments_useful =
clear' Flambda2.Inlining.speculative_inlining_only_if_arguments_useful
let flambda2_inlining_report_bin = set' Flambda2.Inlining.report_bin
let flambda2_unicode = set Flambda2.unicode
let drawfexpr = set' Flambda2.Dump.rawfexpr
let dfexpr = set' Flambda2.Dump.fexpr
let dflexpect = set' Flambda2.Dump.flexpect
let dslot_offsets = set' Flambda2.Dump.slot_offsets
let dfreshen = set' Flambda2.Dump.freshen
end
module type Debugging_options = sig
val _restrict_to_upstream_dwarf : unit -> unit
val _no_restrict_to_upstream_dwarf : unit -> unit
val _dwarf_for_startup_file : unit -> unit
val _no_dwarf_for_startup_file : unit -> unit
end
module Make_debugging_options (F : Debugging_options) = struct
let list3 = [
mk_restrict_to_upstream_dwarf F._restrict_to_upstream_dwarf;
mk_no_restrict_to_upstream_dwarf F._no_restrict_to_upstream_dwarf;
mk_dwarf_for_startup_file F._dwarf_for_startup_file;
mk_no_dwarf_for_startup_file F._no_dwarf_for_startup_file;
]
end
module Debugging_options_impl = struct
let _restrict_to_upstream_dwarf () =
Debugging.restrict_to_upstream_dwarf := true
let _no_restrict_to_upstream_dwarf () =
Debugging.restrict_to_upstream_dwarf := false
let _dwarf_for_startup_file () =
Debugging.dwarf_for_startup_file := true
let _no_dwarf_for_startup_file () =
Debugging.dwarf_for_startup_file := false
end
module Extra_params = struct
let read_param ppf _position name v =
let set option =
let b = Compenv.check_bool ppf name v in
option := Flambda_backend_flags.Set b;
true
in
let _clear option =
let b = Compenv.check_bool ppf name v in
option := Flambda_backend_flags.Set (not b);
false
in
let set_int option =
begin match Compenv.check_int ppf name v with
| Some i -> option := Flambda_backend_flags.Set i
| None -> ()
end;
true
in
let set' option =
Compenv.setter ppf (fun b -> b) name [ option ] v; true
in
let set_int' option =
Compenv.int_setter ppf name option v; true
in
let set_int_option' option =
begin match Compenv.check_int ppf name v with
| Some seed -> option := Some seed
| None -> ()
end;
true
in
let clear' option =
Compenv.setter ppf (fun b -> b) name [ option ] v; false
in
match name with
| "internal-assembler" -> set' Flambda_backend_flags.internal_assembler
| "ocamlcfg" -> set' Flambda_backend_flags.use_ocamlcfg
| "cfg-invariants" -> set' Flambda_backend_flags.cfg_invariants
| "cfg-equivalence-check" -> set' Flambda_backend_flags.cfg_equivalence_check
| "dump-inlining-paths" -> set' Flambda_backend_flags.dump_inlining_paths
| "reorder-blocks-random" ->
set_int_option' Flambda_backend_flags.reorder_blocks_random
| "heap-reduction-threshold" -> set_int' Flambda_backend_flags.heap_reduction_threshold
| "dasm-comments" -> set' Flambda_backend_flags.dasm_comments
| "dno-asm-comments" -> clear' Flambda_backend_flags.dasm_comments
| "gupstream-dwarf" -> set' Debugging.restrict_to_upstream_dwarf
| "gno-upstream-dwarf" -> clear' Debugging.restrict_to_upstream_dwarf
| "gstartup" -> set' Debugging.dwarf_for_startup_file
| "gno-startup" -> clear' Debugging.dwarf_for_startup_file
| "flambda2-join-points" -> set Flambda2.join_points
| "flambda2-result-types" ->
(match String.lowercase_ascii v with
| "never" ->
Flambda2.function_result_types := Flambda_backend_flags.(Set Never)
| "functors-only" ->
Flambda2.function_result_types := Flambda_backend_flags.(Set Functors_only)
| "all-functions" ->
Flambda2.function_result_types := Flambda_backend_flags.(Set All_functions)
| _ ->
Misc.fatal_error "Syntax: flambda2-result-types=\
never|functors-only|all-functions");
true
| "flambda2-result-types-all-functions" ->
Flambda2.function_result_types := Flambda_backend_flags.(Set All_functions);
true
| "flambda2-unbox-along-intra-function-control-flow" ->
set Flambda2.unbox_along_intra_function_control_flow
| "flambda2-backend-cse-at-toplevel" ->
set Flambda2.backend_cse_at_toplevel
| "flambda2-cse-depth" ->
set_int Flambda2.cse_depth
| "flambda2-join-depth" ->
set_int Flambda2.join_depth
| "flambda2-expert-inline-effects-in-cmm" ->
set Flambda2.Expert.inline_effects_in_cmm
| "flambda2-expert-phantom-lets" ->
set Flambda2.Expert.phantom_lets
| "flambda2-expert-max-unboxing-depth" ->
set_int Flambda2.Expert.max_unboxing_depth
| "flambda2-expert-can-inline-recursive-functions" ->
set Flambda2.Expert.can_inline_recursive_functions
| "flambda2-inline-max-depth" ->
Clflags.Int_arg_helper.parse v
"Bad syntax in OCAMLPARAM for 'flambda2-inline-max-depth'"
Flambda2.Inlining.max_depth; true
| "flambda2-inline-max-rec-depth" ->
Clflags.Int_arg_helper.parse v
"Bad syntax in OCAMLPARAM for 'flambda2-inline-max-rec-depth'"
Flambda2.Inlining.max_rec_depth; true
| "flambda2-inline-call-cost" ->
Clflags.Float_arg_helper.parse v
"Bad syntax in OCAMLPARAM for 'flambda2-inline-call-cost'"
Flambda2.Inlining.call_cost; true
| "flambda2-inline-alloc-cost" ->
Clflags.Float_arg_helper.parse v
"Bad syntax in OCAMLPARAM for 'flambda2-inline-alloc-cost'"
Flambda2.Inlining.alloc_cost; true
| "flambda2-inline-prim-cost" ->
Clflags.Float_arg_helper.parse v
"Bad syntax in OCAMLPARAM for 'flambda2-inline-prim-cost'"
Flambda2.Inlining.prim_cost; true
| "flambda2-inline-branch-cost" ->
Clflags.Float_arg_helper.parse v
"Bad syntax in OCAMLPARAM for 'flambda2-inline-branch-cost'"
Flambda2.Inlining.branch_cost; true
| "flambda2-inline-indirect-cost" ->
Clflags.Float_arg_helper.parse v
"Bad syntax in OCAMLPARAM for 'flambda2-inline-indirect-cost'"
Flambda2.Inlining.indirect_call_cost; true
| "flambda2-inline-poly-compare-cost" ->
Clflags.Float_arg_helper.parse v
"Bad syntax in OCAMLPARAM for 'flambda2-inline-poly-compare-cost'"
Flambda2.Inlining.poly_compare_cost; true
| "flambda2-inline-small-function-size" ->
Clflags.Int_arg_helper.parse v
"Bad syntax in OCAMLPARAM for 'flambda2-inline-small-function-size'"
Flambda2.Inlining.small_function_size; true
| "flambda2-inline-large-function-size" ->
Clflags.Int_arg_helper.parse v
"Bad syntax in OCAMLPARAM for 'flambda2-inline-large-function-size'"
Flambda2.Inlining.large_function_size; true
| "flambda2-inline-threshold" ->
Clflags.Float_arg_helper.parse v
"Bad syntax in OCAMLPARAM for 'flambda2-inline-threshold'"
Flambda2.Inlining.threshold; true
| "flambda2-speculative-inlining-only-if-arguments-useful" ->
set' Flambda2.Inlining.speculative_inlining_only_if_arguments_useful
| "flambda2-inlining-report-bin" ->
set' Flambda2.Inlining.report_bin
| "flambda2-expert-fallback-inlining-heuristic" ->
set Flambda2.Expert.fallback_inlining_heuristic
| "flambda2-debug-concrete-types-only-on-canonicals" ->
set' Flambda2.Debug.concrete_types_only_on_canonicals
| "flambda2-debug-keep-invalid-handlers" ->
set' Flambda2.Debug.keep_invalid_handlers
| _ -> false
end
module type Optcomp_options = sig
include Main_args.Optcomp_options
include Flambda_backend_options
include Debugging_options
end
module type Opttop_options = sig
include Main_args.Opttop_options
include Flambda_backend_options
include Debugging_options
end
module Make_optcomp_options (F : Optcomp_options) =
struct
include Make_debugging_options(F) (* provides [list3] *)
include Make_flambda_backend_options(F) (* provides [list2] *)
include Main_args.Make_optcomp_options(F) (* provides [list] *)
(* Overwrite [list] with the combination of the above options.
If the same string input can be recognized by two options,
the flambda-backend implementation will take precedence,
but this should be avoided. To override an option from Main_args,
redefine it in the implementation of this functor's argument. *)
let list = list3 @ list2 @ list
end
module Make_opttop_options (F : Opttop_options) = struct
include Make_debugging_options(F)
include Make_flambda_backend_options(F)
include Main_args.Make_opttop_options(F)
let list = list3 @ list2 @ list
end
module Default = struct
module Optmain = struct
include Main_args.Default.Optmain
include Flambda_backend_options_impl
include Debugging_options_impl
end
module Opttopmain = struct
include Main_args.Default.Opttopmain
include Flambda_backend_options_impl
include Debugging_options_impl
end
end