Skip to content

Commit 07e0918

Browse files
authored
flambda-backend: Save cfg to file (#257)
1 parent 9427a8d commit 07e0918

File tree

7 files changed

+35
-15
lines changed

7 files changed

+35
-15
lines changed

driver/maindriver.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ let main argv ppf =
6363
are incompatible with -pack, -a, -output-obj"
6464
(String.concat "|"
6565
(P.available_pass_names ~filter:(fun _ -> true) ~native:false))
66-
| Some (P.Scheduling | P.Emit) -> assert false (* native only *)
66+
| Some (P.Scheduling | P.Simplify_cfg | P.Emit) -> assert false (* native only *)
6767
end;
6868
if !make_archive then begin
6969
Compmisc.init_path ();

driver/optmaindriver.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ let main argv ppf =
7575
| None ->
7676
Compenv.fatal "Please specify at most one of -pack, -a, -shared, -c, \
7777
-output-obj";
78-
| Some ((P.Parsing | P.Typing | P.Scheduling | P.Emit) as p) ->
78+
| Some ((P.Parsing | P.Typing | P.Scheduling
79+
| P.Simplify_cfg | P.Emit) as p) ->
7980
assert (P.is_compilation_pass p);
8081
Printf.ksprintf Compenv.fatal
8182
"Options -i and -stop-after (%s) \
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
wrong argument 'typing'; option '-save-ir-after' expects one of: scheduling.
1+
wrong argument 'typing'; option '-save-ir-after' expects one of: scheduling simplify_cfg.

utils/clflags.ml

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -420,18 +420,17 @@ let unboxed_types = ref false
420420

421421
(* This is used by the -save-ir-after option. *)
422422
module Compiler_ir = struct
423-
type t = Linear
423+
type t = Linear | Cfg
424424

425425
let all = [
426-
Linear;
426+
Linear; Cfg
427427
]
428428

429-
let extension t =
430-
let ext =
431-
match t with
432-
| Linear -> "linear"
433-
in
434-
".cmir-" ^ ext
429+
let to_string = function
430+
| Linear -> "linear"
431+
| Cfg -> "cfg"
432+
433+
let extension t = ".cmir-" ^ (to_string t)
435434

436435
(** [extract_extension_with_pass filename] returns the IR whose extension
437436
is a prefix of the extension of [filename], and the suffix,
@@ -699,24 +698,27 @@ module Compiler_pass = struct
699698
- the manpages in man/ocaml{c,opt}.m
700699
- the manual manual/manual/cmds/unified-options.etex
701700
*)
702-
type t = Parsing | Typing | Scheduling | Emit
701+
type t = Parsing | Typing | Scheduling | Emit | Simplify_cfg
703702

704703
let to_string = function
705704
| Parsing -> "parsing"
706705
| Typing -> "typing"
707706
| Scheduling -> "scheduling"
708707
| Emit -> "emit"
708+
| Simplify_cfg -> "simplify_cfg"
709709

710710
let of_string = function
711711
| "parsing" -> Some Parsing
712712
| "typing" -> Some Typing
713713
| "scheduling" -> Some Scheduling
714714
| "emit" -> Some Emit
715+
| "simplify_cfg" -> Some Simplify_cfg
715716
| _ -> None
716717

717718
let rank = function
718719
| Parsing -> 0
719720
| Typing -> 1
721+
| Simplify_cfg -> 49
720722
| Scheduling -> 50
721723
| Emit -> 60
722724

@@ -725,16 +727,19 @@ module Compiler_pass = struct
725727
Typing;
726728
Scheduling;
727729
Emit;
730+
Simplify_cfg;
728731
]
729732
let is_compilation_pass _ = true
730733
let is_native_only = function
731734
| Scheduling -> true
732735
| Emit -> true
733-
| _ -> false
736+
| Simplify_cfg -> true
737+
| Parsing | Typing -> false
734738

735739
let enabled is_native t = not (is_native_only t) || is_native
736740
let can_save_ir_after = function
737741
| Scheduling -> true
742+
| Simplify_cfg -> true
738743
| _ -> false
739744

740745
let available_pass_names ~filter ~native =
@@ -749,11 +754,13 @@ module Compiler_pass = struct
749754
let to_output_filename t ~prefix =
750755
match t with
751756
| Scheduling -> prefix ^ Compiler_ir.(extension Linear)
752-
| _ -> Misc.fatal_error "Not supported"
757+
| Simplify_cfg -> prefix ^ Compiler_ir.(extension Cfg)
758+
| Emit | Parsing | Typing -> Misc.fatal_error "Not supported"
753759

754760
let of_input_filename name =
755761
match Compiler_ir.extract_extension_with_pass name with
756762
| Some (Linear, _) -> Some Emit
763+
| Some (Cfg, _) -> None
757764
| None -> None
758765
end
759766

utils/clflags.mli

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,8 +311,16 @@ val set_oclassic : unit -> unit
311311
val set_o2 : unit -> unit
312312
val set_o3 : unit -> unit
313313

314+
module Compiler_ir : sig
315+
type t = Linear | Cfg
316+
val all : t list
317+
val to_string : t -> string
318+
val extension : t -> string
319+
val extract_extension_with_pass : string -> (t * string) option
320+
end
321+
314322
module Compiler_pass : sig
315-
type t = Parsing | Typing | Scheduling | Emit
323+
type t = Parsing | Typing | Scheduling | Emit | Simplify_cfg
316324
val of_string : string -> t option
317325
val to_string : t -> string
318326
val is_compilation_pass : t -> bool

utils/config.mli

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,9 @@ val cmt_magic_number: string
121121
val linear_magic_number: string
122122
(** Magic number for Linear internal representation files *)
123123

124+
val cfg_magic_number: string
125+
(** Magic number for Cfg internal representation files *)
126+
124127
val max_tag: int
125128
(** Biggest tag that can be stored in the header of a regular block. *)
126129

utils/config.mlp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ and ast_intf_magic_number = "Caml1999N029"
111111
and cmxs_magic_number = "Caml1999D029"
112112
and cmt_magic_number = "Caml1999T029"
113113
and linear_magic_number = "Caml1999L029"
114+
and cfg_magic_number = "Caml2021G029"
114115

115116
let interface_suffix = ref ".mli"
116117

0 commit comments

Comments
 (0)