Skip to content

Commit aeb6b25

Browse files
lthlsGbury
authored andcommitted
[WIP] Flambda2 Makefile-based compilation (#36)
* Update Makefile to compile Flambda2 * Update .gitignore * Disable -O3 * Stop generating allocs of size 0 * Fix dune compilation * Fix Makefile for Monad and Top_closure * Add support for ilambdac
1 parent 3048fc2 commit aeb6b25

File tree

119 files changed

+5470
-2478
lines changed

Some content is hidden

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

119 files changed

+5470
-2478
lines changed

.depend

Lines changed: 5006 additions & 2000 deletions
Large diffs are not rendered by default.

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ _build
9292
/manual/manual/cmds/warnings-help.etex
9393
/manual/manual/warnings-help.etex
9494

95+
middle_end/flambda2.0/simplify/simplify.ml
96+
middle_end/flambda2.0/terms/flambda.ml
97+
middle_end/flambda2.0/types/flambda_type0.ml
98+
9599
/ocamldoc/ocamldoc
96100
/ocamldoc/ocamldoc.opt
97101
/ocamldoc/odoc

Makefile

Lines changed: 265 additions & 140 deletions
Large diffs are not rendered by default.

asmcomp/asmgen.ml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,12 +181,12 @@ let compile_implementation ?toplevel ~backend ~filename ~prefixname ~middle_end
181181
type middle_end2 =
182182
ppf_dump:Format.formatter
183183
-> prefixname:string
184-
-> backend:(module Flambda2.Flambda2_backend_intf.S)
184+
-> backend:(module Flambda2_backend_intf.S)
185185
-> size:int
186186
-> filename:string
187187
-> module_ident:Ident.t
188188
-> module_initializer:Lambda.lambda
189-
-> Flambda2.Flambda_static.Program.t
189+
-> Flambda_static.Program.t
190190

191191
let compile_implementation2 ?toplevel ~backend ~filename ~prefixname ~size
192192
~module_ident ~module_initializer ~middle_end ~ppf_dump required_globals =
@@ -202,7 +202,7 @@ let compile_implementation2 ?toplevel ~backend ~filename ~prefixname ~size
202202
(middle_end : middle_end2) ~backend ~size ~filename ~prefixname
203203
~ppf_dump ~module_ident ~module_initializer
204204
in
205-
end_gen_implementation ?toplevel ~ppf_dump Flambda2_to_cmm.Un_cps.program
205+
end_gen_implementation ?toplevel ~ppf_dump Un_cps.program
206206
translated_program)
207207

208208
let compile_implementation_flambda ?toplevel ~prefixname
@@ -216,7 +216,7 @@ let compile_implementation_flambda ?toplevel ~prefixname
216216
(fun () ->
217217
Ident.Set.iter Compilenv.require_global required_globals;
218218
end_gen_implementation ?toplevel ~ppf_dump
219-
Flambda2_to_cmm.Un_cps.program program)
219+
Un_cps.program program)
220220

221221
(* Error report *)
222222

asmcomp/asmgen.mli

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,17 @@ val compile_implementation
3939
type middle_end2 =
4040
ppf_dump:Format.formatter
4141
-> prefixname:string
42-
-> backend:(module Flambda2.Flambda2_backend_intf.S)
42+
-> backend:(module Flambda2_backend_intf.S)
4343
-> size:int
4444
-> filename:string
4545
-> module_ident:Ident.t
4646
-> module_initializer:Lambda.lambda
47-
-> Flambda2.Flambda_static.Program.t
47+
-> Flambda_static.Program.t
4848

4949
(** Compile an implementation from Lambda using the given middle end. *)
5050
val compile_implementation2
5151
: ?toplevel:(string -> bool)
52-
-> backend:(module Flambda2.Flambda2_backend_intf.S)
52+
-> backend:(module Flambda2_backend_intf.S)
5353
-> filename:string
5454
-> prefixname:string
5555
-> size:int
@@ -66,7 +66,7 @@ val compile_implementation_flambda
6666
-> prefixname:string
6767
-> ppf_dump:Format.formatter
6868
-> required_globals:Ident.Set.t
69-
-> Flambda2.Flambda_static.Program.t
69+
-> Flambda_static.Program.t
7070
-> unit
7171

7272
val compile_phrase :

asmcomp/asmlibrarian.ml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,7 @@ type error =
2626
exception Error of error
2727

2828
let default_ui_export_info =
29-
if Config.flambda then
30-
Cmx_format.Flambda Export_info.empty
31-
else
32-
Cmx_format.Clambda Clambda.Value_unknown
29+
Cmx_format.Clambda Clambda.Value_unknown
3330

3431
let read_info name =
3532
let filename =

asmcomp/asmpackager.ml

Lines changed: 15 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -101,35 +101,20 @@ let make_package_object ~ppf_dump members targetobj targetname coercion
101101
let prefixname = Filename.remove_extension objtemp in
102102
let required_globals = Ident.Set.empty in
103103
let program, middle_end =
104-
if Config.flambda then
105-
let main_module_block_size, code =
106-
Translmod.transl_package_flambda components coercion
107-
in
108-
let code = Simplif.simplify_lambda code in
109-
let program =
110-
{ Lambda.
111-
code;
112-
main_module_block_size;
113-
module_ident;
114-
required_globals;
115-
}
116-
in
117-
program, Flambda_middle_end.lambda_to_clambda
118-
else
119-
let main_module_block_size, code =
120-
Translmod.transl_store_package components
121-
(Ident.create_persistent targetname) coercion
122-
in
123-
let code = Simplif.simplify_lambda code in
124-
let program =
125-
{ Lambda.
126-
code;
127-
main_module_block_size;
128-
module_ident;
129-
required_globals;
130-
}
131-
in
132-
program, Closure_middle_end.lambda_to_clambda
104+
let main_module_block_size, code =
105+
Translmod.transl_store_package components
106+
(Ident.create_persistent targetname) coercion
107+
in
108+
let code = Simplif.simplify_lambda code in
109+
let program =
110+
{ Lambda.
111+
code;
112+
main_module_block_size;
113+
module_ident;
114+
required_globals;
115+
}
116+
in
117+
program, Closure_middle_end.lambda_to_clambda
133118
in
134119
Asmgen.compile_implementation ~backend
135120
~filename:targetname
@@ -150,16 +135,9 @@ let make_package_object ~ppf_dump members targetobj targetname coercion
150135

151136
(* Make the .cmx file for the package *)
152137

153-
let get_export_info ui =
154-
assert(Config.flambda);
155-
match ui.ui_export_info with
156-
| Clambda _ -> assert false
157-
| Flambda info -> info
158-
159138
let get_approx ui =
160139
assert(not Config.flambda);
161140
match ui.ui_export_info with
162-
| Flambda _ -> assert false
163141
| Clambda info -> info
164142

165143
let build_package_cmx members cmxfile =
@@ -177,42 +155,10 @@ let build_package_cmx members cmxfile =
177155
(fun m accu ->
178156
match m.pm_kind with PM_intf -> accu | PM_impl info -> info :: accu)
179157
members [] in
180-
let pack_units =
181-
List.fold_left
182-
(fun set info ->
183-
let unit_id = Compilenv.unit_id_from_name info.ui_name in
184-
Compilation_unit.Set.add
185-
(Compilenv.unit_for_global unit_id) set)
186-
Compilation_unit.Set.empty units in
187-
let units =
188-
if Config.flambda then
189-
List.map (fun info ->
190-
{ info with
191-
ui_export_info =
192-
Flambda
193-
(Export_info_for_pack.import_for_pack ~pack_units
194-
~pack:(Compilenv.current_unit ())
195-
(get_export_info info)) })
196-
units
197-
else
198-
units
199-
in
200158
let ui = Compilenv.current_unit_infos() in
201159
let ui_export_info =
202-
if Config.flambda then
203-
let ui_export_info =
204-
List.fold_left (fun acc info ->
205-
Export_info.merge acc (get_export_info info))
206-
(Export_info_for_pack.import_for_pack ~pack_units
207-
~pack:(Compilenv.current_unit ())
208-
(get_export_info ui))
209-
units
210-
in
211-
Flambda ui_export_info
212-
else
213-
Clambda (get_approx ui)
160+
Clambda (get_approx ui)
214161
in
215-
Export_info_for_pack.clear_import_state ();
216162
let pkg_infos =
217163
{ ui_name = ui.ui_name;
218164
ui_symbol = ui.ui_symbol;

driver/ilambdac.ml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
module Flambda2_backend = struct
22
let symbol_for_global' id =
3-
Flambda2.Symbol.unsafe_create
4-
(Flambda2.Compilation_unit.get_current_exn ())
5-
(Flambda2.Linkage_name.create (Compilenv.symbol_for_global id))
3+
Symbol.unsafe_create
4+
(Compilation_unit.get_current_exn ())
5+
(Linkage_name.create (Compilenv.symbol_for_global id))
66

77
let division_by_zero =
88
symbol_for_global' Predef.ident_division_by_zero
@@ -14,7 +14,7 @@ module Flambda2_backend = struct
1414
let really_import_approx _ = failwith "Not yet implemented"
1515
let import_symbol _ = failwith "Not yet implemented"
1616

17-
let all_predefined_exception_symbols = Flambda2.Symbol.Set.empty (* XXX *)
17+
let all_predefined_exception_symbols = Symbol.Set.empty (* XXX *)
1818

1919
let size_int = Arch.size_int
2020
let big_endian = Arch.big_endian
@@ -23,12 +23,12 @@ module Flambda2_backend = struct
2323
Proc.max_arguments_for_tailcalls - 1
2424
end
2525
let flambda2_backend =
26-
(module Flambda2_backend : Flambda2.Flambda2_backend_intf.S)
26+
(module Flambda2_backend : Flambda2_backend_intf.S)
2727

2828
let () =
2929
Clflags.dump_cmm := true;
3030
Clflags.keep_asm_file := true;
31-
let fl = Flambda2.Parse_ilambda.go ~backend:flambda2_backend () in
31+
let fl = Parse_ilambda.go ~backend:flambda2_backend () in
3232
Asmgen.compile_implementation_flambda
3333
?toplevel:None
3434
~prefixname:"test"

driver/optcompile.ml

Lines changed: 10 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -36,32 +36,32 @@ module Flambda2_backend = struct
3636
let symbol_for_global' ?comp_unit id =
3737
let comp_unit =
3838
match comp_unit with
39-
| None -> Flambda2.Compilation_unit.get_current_exn ()
39+
| None -> Compilation_unit.get_current_exn ()
4040
| Some comp_unit -> comp_unit
4141
in
42-
Flambda2.Symbol.unsafe_create
42+
Symbol.unsafe_create
4343
comp_unit
44-
(Flambda2.Linkage_name.create (Compilenv.symbol_for_global id))
44+
(Linkage_name.create (Compilenv.symbol_for_global id))
4545

4646
let closure_symbol _ = failwith "Not yet implemented"
4747

4848
let division_by_zero =
4949
symbol_for_global'
50-
~comp_unit:(Flambda2.Compilation_unit.predefined_exception ())
50+
~comp_unit:(Compilation_unit.predefined_exception ())
5151
Predef.ident_division_by_zero
5252

5353
let invalid_argument =
5454
symbol_for_global'
55-
~comp_unit:(Flambda2.Compilation_unit.predefined_exception ())
55+
~comp_unit:(Compilation_unit.predefined_exception ())
5656
Predef.ident_invalid_argument
5757

5858
let all_predefined_exception_symbols =
59-
Flambda2.Symbol.Set.of_list [
59+
Symbol.Set.of_list [
6060
division_by_zero;
6161
invalid_argument;
6262
] (* CR mshinwell: and the rest... *)
6363

64-
let symbol_for_global' id : Flambda2.Symbol.t = symbol_for_global' id
64+
let symbol_for_global' id : Symbol.t = symbol_for_global' id
6565

6666
let size_int = Arch.size_int
6767
let big_endian = Arch.big_endian
@@ -70,42 +70,7 @@ module Flambda2_backend = struct
7070
Proc.max_arguments_for_tailcalls - 1
7171
end
7272
let flambda2_backend =
73-
(module Flambda2_backend : Flambda2.Flambda2_backend_intf.S)
74-
75-
let flambda i backend typed =
76-
if !Clflags.classic_inlining then begin
77-
Clflags.default_simplify_rounds := 1;
78-
Clflags.use_inlining_arguments_set Clflags.classic_arguments;
79-
Clflags.unbox_free_vars_of_closures := false;
80-
Clflags.unbox_specialised_args := false
81-
end;
82-
typed
83-
|> Profile.(record transl)
84-
(Translmod.transl_implementation_flambda i.module_name)
85-
|> Profile.(record generate)
86-
(fun {Lambda.module_ident; main_module_block_size;
87-
required_globals; code } ->
88-
((module_ident, main_module_block_size), code)
89-
|>> print_if i.ppf_dump Clflags.dump_rawlambda Printlambda.lambda
90-
|>> Simplif.simplify_lambda
91-
|>> print_if i.ppf_dump Clflags.dump_lambda Printlambda.lambda
92-
|> (fun ((module_ident, main_module_block_size), code) ->
93-
let program : Lambda.program =
94-
{ Lambda.
95-
module_ident;
96-
main_module_block_size;
97-
required_globals;
98-
code;
99-
}
100-
in
101-
Asmgen.compile_implementation
102-
~backend
103-
~filename:i.source_file
104-
~prefixname:i.output_prefix
105-
~middle_end:Flambda_middle_end.lambda_to_clambda
106-
~ppf_dump:i.ppf_dump
107-
program);
108-
Compilenv.save_unit_info (cmx i))
73+
(module Flambda2_backend : Flambda2_backend_intf.S)
10974

11075
let flambda2 i typed =
11176
if !Clflags.classic_inlining then begin
@@ -133,7 +98,7 @@ let flambda2 i typed =
13398
~module_ident
13499
~module_initializer:code
135100
~ppf_dump:i.ppf_dump
136-
~middle_end:Flambda2.Flambda2_middle_end.middle_end);
101+
~middle_end:Flambda2_middle_end.middle_end);
137102
Compilenv.save_unit_info (cmx i)
138103
)
139104

@@ -156,16 +121,11 @@ let clambda i backend typed =
156121
~ppf_dump:i.ppf_dump;
157122
Compilenv.save_unit_info (cmx i))
158123

159-
let config_flambda2 () =
160-
try ignore (Sys.getenv "FLAMBDA2"); true
161-
with Not_found -> false
162-
163124
let implementation ~backend ~source_file ~output_prefix =
164125
let backend info typed =
165126
Compilenv.reset ?packname:!Clflags.for_package info.module_name;
166127
if Config.flambda then
167-
if config_flambda2 () then flambda2 info typed
168-
else flambda info backend typed
128+
flambda2 info typed
169129
else clambda info backend typed
170130
in
171131
with_info ~source_file ~output_prefix ~dump_ext:"cmx" @@ fun info ->

driver/optcompile.mli

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,3 @@ val clambda :
3030
(** [clambda info typed] applies the regular compilation pipeline to the
3131
given typechecked implementation and outputs the resulting files.
3232
*)
33-
34-
val flambda :
35-
Compile_common.info ->
36-
(module Backend_intf.S) ->
37-
Typedtree.structure * Typedtree.module_coercion -> unit
38-
(** [flambda info backend typed] applies the Flambda compilation pipeline to the
39-
given typechecked implementation and outputs the resulting files.
40-
*)

0 commit comments

Comments
 (0)