Skip to content

Commit f1710d6

Browse files
committed
Merge flambda-backend changes
2 parents cc18534 + 49fea78 commit f1710d6

File tree

135 files changed

+3580
-2368
lines changed

Some content is hidden

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

135 files changed

+3580
-2368
lines changed

Makefile.common-jst

+22-11
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,15 @@ endef
5151
.DEFAULT_GOAL := compiler
5252
.PHONY: boot-compiler boot-runtest runtime-stdlib compiler runtest
5353

54+
boot_targets = \
55+
$(boot_ocamlc) \
56+
$(boot_ocamlopt) \
57+
$(boot_ocamlmklib) \
58+
$(boot_ocamldep) \
59+
$(boot_ocamlobjinfo)
60+
5461
boot-compiler: _build/_bootinstall
55-
$(dune) build $(ws_boot) $(coverage_dune_flags) \
56-
$(boot_ocamlc) \
57-
$(boot_ocamlopt) \
58-
$(boot_ocamlmklib) \
59-
$(boot_ocamldep) \
60-
$(boot_ocamlobjinfo)
62+
$(dune) build $(ws_boot) $(coverage_dune_flags) $(boot_targets)
6163

6264
boot-runtest: boot-compiler
6365
$(dune) runtest $(ws_boot) $(coverage_dune_flags) --force
@@ -139,6 +141,13 @@ _install: compiler
139141
$(cpl) -R _build/install/runtime_stdlib/lib/ocaml_runtime_stdlib/* _install/lib/ocaml/
140142
rm -f _install/lib/ocaml/{META,dune-package,Makefile.config,dynlink.cmxa}
141143
$(cpl) -R _build/install/main/lib/ocaml/* _install/lib/ocaml/
144+
if [ "x$(legacy_layout)" == "xyes" ] ; \
145+
then \
146+
for libdir in unix str dynlink bigarray ; do \
147+
mv _install/lib/ocaml/$${libdir}/* _install/lib/ocaml/ ; \
148+
rmdir _install/lib/ocaml/$${libdir} ; \
149+
done \
150+
fi
142151
rm -f _install/lib/ocaml/{META,dune-package}
143152
rm -f _install/lib/ocaml/compiler-libs/*.cmo
144153
$(cpl) {_build/install/main,_install}/lib/ocaml/compiler-libs/topstart.cmo
@@ -202,11 +211,12 @@ install_for_test: _install
202211
done; \
203212
ln -s . lex; ln -s . yacc; \
204213
ln -s _install/lib/ocaml/compiler-libs compilerlibs; \
205-
mkdir -p otherlibs/{unix,dynlink/native,str}; \
214+
mkdir -p otherlibs/{unix,dynlink/native,str,bigarray}; \
206215
ln -s ../stdlib/threads otherlibs/systhreads; \
207-
$(cpl) stdlib/{lib,}unix* otherlibs/unix; \
208-
$(cpl) stdlib/dynlink* otherlibs/dynlink; \
209-
$(cpl) stdlib/{lib,}str* otherlibs/str; \
216+
$(cpl) stdlib/unix/{lib,}unix* otherlibs/unix; \
217+
$(cpl) stdlib/dynlink/dynlink* otherlibs/dynlink; \
218+
$(cpl) stdlib/str/{lib,}str* otherlibs/str; \
219+
${cpl} stdlib/bigarray/bigarray* otherlibs/bigarray; \
210220
ln -s ../_build/main/$(ocamldir)/toplevel/byte/.ocamltoplevel.objs/byte toplevel; \
211221
)
212222

@@ -218,6 +228,7 @@ install_for_test: _install
218228
cp $(main_build)/$(ocamldir)/.ocamlcommon.objs/byte/*.cmo _runtest/utils
219229
rm -f _runtest/utils/{topdirs,opttopdirs}.cmi
220230
cp _install/lib/ocaml/*.{cmi,cma,a,cmxa} _runtest/utils
231+
cp _install/lib/ocaml/{unix,str,dynlink,bigarray}/*.{cmi,cma,a,cmxa} _runtest/utils
221232
cp $(main_build)/$(ocamldir)/.ocamlcommon.objs/native/config.o _runtest/utils
222233
# Needed for tests/warnings
223234
cp $(ocamldir)/utils/warnings.ml _runtest/utils
@@ -302,4 +313,4 @@ promote-one: install_for_test
302313
# This target is like a polling version of upstream "make ocamlopt"
303314
.PHONY: hacking
304315
hacking: _build/_bootinstall
305-
$(dune) build $(ws_boot) -w $(boot_ocamlopt)
316+
$(dune) build $(ws_boot) -w $(boot_targets)

Makefile.menhir

+3
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ import-menhirLib:
111111
@ cp \
112112
$(addprefix `$(MENHIR) --suggest-menhirLib`/menhirLib.,ml mli) \
113113
boot/menhir
114+
# Partial applications of the form Obj.magic f x in menhirLib cause an issue with locals,
115+
# so rewrite these to Obj.magic (f x)
116+
@ sed -i 's/\b\(in\|then\|with\|else\)\b/@@@\1/g; s/Obj.magic \([a-z0-9_]\+\( [a-z0-9_]\+\)\+\)/Obj.magic (\1)/g; s/@@@//g' boot/menhir/menhirLib.ml
114117

115118

116119
## demote-menhir

asmcomp/afl_instrument.ml

+8-8
Original file line numberDiff line numberDiff line change
@@ -56,19 +56,19 @@ let rec with_afl_logging b dbg =
5656

5757
and instrument = function
5858
(* these cases add logging, as they may be targets of conditional branches *)
59-
| Cifthenelse (cond, t_dbg, t, f_dbg, f, dbg) ->
59+
| Cifthenelse (cond, t_dbg, t, f_dbg, f, dbg, kind) ->
6060
Cifthenelse (instrument cond, t_dbg, with_afl_logging t t_dbg,
61-
f_dbg, with_afl_logging f f_dbg, dbg)
62-
| Ctrywith (e, ex, handler, dbg) ->
63-
Ctrywith (instrument e, ex, with_afl_logging handler dbg, dbg)
64-
| Cswitch (e, cases, handlers, dbg) ->
61+
f_dbg, with_afl_logging f f_dbg, dbg, kind)
62+
| Ctrywith (e, ex, handler, dbg, value_kind) ->
63+
Ctrywith (instrument e, ex, with_afl_logging handler dbg, dbg, value_kind)
64+
| Cswitch (e, cases, handlers, dbg, value_kind) ->
6565
let handlers =
6666
Array.map (fun (handler, handler_dbg) ->
6767
let handler = with_afl_logging handler handler_dbg in
6868
handler, handler_dbg)
6969
handlers
7070
in
71-
Cswitch (instrument e, cases, handlers, dbg)
71+
Cswitch (instrument e, cases, handlers, dbg, value_kind)
7272

7373
(* these cases add no logging, but instrument subexpressions *)
7474
| Clet (v, e, body) -> Clet (v, instrument e, instrument body)
@@ -80,12 +80,12 @@ and instrument = function
8080
| Ctuple es -> Ctuple (List.map instrument es)
8181
| Cop (op, es, dbg) -> Cop (op, List.map instrument es, dbg)
8282
| Csequence (e1, e2) -> Csequence (instrument e1, instrument e2)
83-
| Ccatch (isrec, cases, body) ->
83+
| Ccatch (isrec, cases, body, kind) ->
8484
let cases =
8585
List.map (fun (nfail, ids, e, dbg) -> nfail, ids, instrument e, dbg)
8686
cases
8787
in
88-
Ccatch (isrec, cases, instrument body)
88+
Ccatch (isrec, cases, instrument body, kind)
8989
| Cexit (ex, args) -> Cexit (ex, List.map instrument args)
9090
| Cregion e -> Cregion (instrument e)
9191
| Ctail e -> Ctail (instrument e)

asmcomp/asmlink.ml

+5-2
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,9 @@ let make_startup_file ~ppf_dump units_list ~crc_interfaces =
273273
List.flatten (List.map (fun (info,_,_) -> info.ui_defines) units_list) in
274274
compile_phrase (Cmm_helpers.entry_point name_list);
275275
let units = List.map (fun (info,_,_) -> info) units_list in
276-
List.iter compile_phrase (Cmm_helpers.generic_functions false units);
276+
List.iter compile_phrase
277+
(Cmm_helpers.emit_preallocated_blocks []
278+
(Cmm_helpers.generic_functions false units));
277279
Array.iteri
278280
(fun i name -> compile_phrase (Cmm_helpers.predef_exception i name))
279281
Runtimedef.builtin_exceptions;
@@ -309,7 +311,8 @@ let make_shared_startup_file ~ppf_dump units =
309311
Compilenv.reset shared_startup_comp_unit;
310312
Emit.begin_assembly ();
311313
List.iter compile_phrase
312-
(Cmm_helpers.generic_functions true (List.map fst units));
314+
(Cmm_helpers.emit_preallocated_blocks []
315+
(Cmm_helpers.generic_functions true (List.map fst units)));
313316
compile_phrase (Cmm_helpers.plugin_header units);
314317
compile_phrase
315318
(Cmm_helpers.global_table (List.map (fun (ui,_) -> ui.ui_unit) units));

asmcomp/asmpackager.ml

+20-30
Original file line numberDiff line numberDiff line change
@@ -111,36 +111,26 @@ let make_package_object ~ppf_dump members targetobj targetname coercion
111111
let compilation_unit = CU.create for_pack_prefix modname in
112112
let prefixname = Filename.remove_extension objtemp in
113113
let required_globals = CU.Set.empty in
114-
let program, middle_end =
115-
if Config.flambda then
116-
let main_module_block_size, code =
117-
Translmod.transl_package_flambda components coercion
118-
in
119-
let code = Simplif.simplify_lambda code in
120-
let program =
121-
{ Lambda.
122-
code;
123-
main_module_block_size;
124-
compilation_unit;
125-
required_globals;
126-
}
127-
in
128-
program, Flambda_middle_end.lambda_to_clambda
129-
else
130-
let main_module_block_size, code =
131-
Translmod.transl_store_package components
132-
compilation_unit coercion
133-
in
134-
let code = Simplif.simplify_lambda code in
135-
let program =
136-
{ Lambda.
137-
code;
138-
main_module_block_size;
139-
compilation_unit;
140-
required_globals;
141-
}
142-
in
143-
program, Closure_middle_end.lambda_to_clambda
114+
let transl_style : Translmod.compilation_unit_style =
115+
if Config.flambda || Config.flambda2 then Plain_block
116+
else Set_individual_fields
117+
in
118+
let main_module_block_size, code =
119+
Translmod.transl_package components compilation_unit coercion
120+
~style:transl_style
121+
in
122+
let code = Simplif.simplify_lambda code in
123+
let program =
124+
{ Lambda.
125+
code;
126+
main_module_block_size;
127+
compilation_unit;
128+
required_globals;
129+
}
130+
in
131+
let middle_end =
132+
if Config.flambda then Flambda_middle_end.lambda_to_clambda
133+
else Closure_middle_end.lambda_to_clambda
144134
in
145135
Asmgen.compile_implementation ~backend
146136
~prefixname

asmcomp/cmm.ml

+44-34
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
(* *)
1414
(**************************************************************************)
1515

16-
type machtype_component =
16+
type machtype_component = Cmx_format.machtype_component =
1717
| Val
1818
| Addr
1919
| Int
@@ -173,6 +173,12 @@ and operation =
173173
| Copaque
174174
| Cbeginregion | Cendregion
175175

176+
type value_kind =
177+
| Vval of Lambda.value_kind (* Valid OCaml values *)
178+
| Vint (* Untagged integers and off-heap pointers *)
179+
| Vaddr (* Derived pointers *)
180+
| Vfloat (* Unboxed floating-point numbers *)
181+
176182
type expression =
177183
Cconst_int of int * Debuginfo.t
178184
| Cconst_natint of nativeint * Debuginfo.t
@@ -189,17 +195,17 @@ type expression =
189195
| Cop of operation * expression list * Debuginfo.t
190196
| Csequence of expression * expression
191197
| Cifthenelse of expression * Debuginfo.t * expression
192-
* Debuginfo.t * expression * Debuginfo.t
198+
* Debuginfo.t * expression * Debuginfo.t * value_kind
193199
| Cswitch of expression * int array * (expression * Debuginfo.t) array
194-
* Debuginfo.t
200+
* Debuginfo.t * value_kind
195201
| Ccatch of
196202
rec_flag
197203
* (int * (Backend_var.With_provenance.t * machtype) list
198204
* expression * Debuginfo.t) list
199-
* expression
205+
* expression * value_kind
200206
| Cexit of int * expression list
201207
| Ctrywith of expression * Backend_var.With_provenance.t * expression
202-
* Debuginfo.t
208+
* Debuginfo.t * value_kind
203209
| Cregion of expression
204210
| Ctail of expression
205211

@@ -234,8 +240,8 @@ type phrase =
234240
Cfunction of fundecl
235241
| Cdata of data_item list
236242

237-
let ccatch (i, ids, e1, e2, dbg) =
238-
Ccatch(Nonrecursive, [i, ids, e2, dbg], e1)
243+
let ccatch (i, ids, e1, e2, dbg, kind) =
244+
Ccatch(Nonrecursive, [i, ids, e2, dbg], e1, kind)
239245

240246
let reset () =
241247
label_counter := init_label
@@ -244,21 +250,21 @@ let iter_shallow_tail f = function
244250
| Clet(_, _, body) | Cphantom_let (_, _, body) | Clet_mut(_, _, _, body) ->
245251
f body;
246252
true
247-
| Cifthenelse(_cond, _ifso_dbg, ifso, _ifnot_dbg, ifnot, _dbg) ->
253+
| Cifthenelse(_cond, _ifso_dbg, ifso, _ifnot_dbg, ifnot, _dbg, _value_kind) ->
248254
f ifso;
249255
f ifnot;
250256
true
251257
| Csequence(_e1, e2) ->
252258
f e2;
253259
true
254-
| Cswitch(_e, _tbl, el, _dbg') ->
260+
| Cswitch(_e, _tbl, el, _dbg', _value_kind) ->
255261
Array.iter (fun (e, _dbg) -> f e) el;
256262
true
257-
| Ccatch(_rec_flag, handlers, body) ->
263+
| Ccatch(_rec_flag, handlers, body, _value_kind) ->
258264
List.iter (fun (_, _, h, _dbg) -> f h) handlers;
259265
f body;
260266
true
261-
| Ctrywith(e1, _id, e2, _dbg) ->
267+
| Ctrywith(e1, _id, e2, _dbg, _value_kind) ->
262268
f e1;
263269
f e2;
264270
true
@@ -280,30 +286,34 @@ let iter_shallow_tail f = function
280286
| Cop _ ->
281287
false
282288

283-
let map_shallow_tail f = function
289+
let map_shallow_tail ?kind f = function
284290
| Clet(id, exp, body) ->
285291
Clet(id, exp, f body)
286292
| Clet_mut(id, kind, exp, body) ->
287293
Clet_mut(id, kind, exp, f body)
288294
| Cphantom_let(id, exp, body) ->
289295
Cphantom_let (id, exp, f body)
290-
| Cifthenelse(cond, ifso_dbg, ifso, ifnot_dbg, ifnot, dbg) ->
296+
| Cifthenelse(cond, ifso_dbg, ifso, ifnot_dbg, ifnot, dbg, kind_before) ->
291297
Cifthenelse
292298
(
293299
cond,
294300
ifso_dbg, f ifso,
295301
ifnot_dbg, f ifnot,
296-
dbg
302+
dbg,
303+
Option.value kind ~default:kind_before
297304
)
298305
| Csequence(e1, e2) ->
299306
Csequence(e1, f e2)
300-
| Cswitch(e, tbl, el, dbg') ->
301-
Cswitch(e, tbl, Array.map (fun (e, dbg) -> f e, dbg) el, dbg')
302-
| Ccatch(rec_flag, handlers, body) ->
307+
| Cswitch(e, tbl, el, dbg', kind_before) ->
308+
Cswitch(e, tbl, Array.map (fun (e, dbg) -> f e, dbg) el, dbg',
309+
Option.value kind ~default:kind_before)
310+
| Ccatch(rec_flag, handlers, body, kind_before) ->
303311
let map_h (n, ids, handler, dbg) = (n, ids, f handler, dbg) in
304-
Ccatch(rec_flag, List.map map_h handlers, f body)
305-
| Ctrywith(e1, id, e2, dbg) ->
306-
Ctrywith(f e1, id, f e2, dbg)
312+
Ccatch(rec_flag, List.map map_h handlers, f body,
313+
Option.value kind ~default:kind_before)
314+
| Ctrywith(e1, id, e2, dbg, kind_before) ->
315+
Ctrywith(f e1, id, f e2, dbg,
316+
Option.value kind ~default:kind_before)
307317
| Cregion e ->
308318
Cregion(f e)
309319
| Ctail e ->
@@ -319,7 +329,7 @@ let map_shallow_tail f = function
319329
| Ctuple _
320330
| Cop _ as cmm -> cmm
321331

322-
let map_tail f =
332+
let map_tail ?kind f =
323333
let rec loop = function
324334
| Cconst_int _
325335
| Cconst_natint _
@@ -330,7 +340,7 @@ let map_tail f =
330340
| Ctuple _
331341
| Cop _ as c ->
332342
f c
333-
| cmm -> map_shallow_tail loop cmm
343+
| cmm -> map_shallow_tail ?kind loop cmm
334344
in
335345
loop
336346

@@ -349,16 +359,16 @@ let iter_shallow f = function
349359
List.iter f el
350360
| Csequence (e1, e2) ->
351361
f e1; f e2
352-
| Cifthenelse(cond, _ifso_dbg, ifso, _ifnot_dbg, ifnot, _dbg) ->
362+
| Cifthenelse(cond, _ifso_dbg, ifso, _ifnot_dbg, ifnot, _dbg, _value_kind) ->
353363
f cond; f ifso; f ifnot
354-
| Cswitch (_e, _ia, ea, _dbg) ->
364+
| Cswitch (_e, _ia, ea, _dbg, _value_kind) ->
355365
Array.iter (fun (e, _) -> f e) ea
356-
| Ccatch (_rf, hl, body) ->
366+
| Ccatch (_rf, hl, body, _value_kind) ->
357367
let iter_h (_n, _ids, handler, _dbg) = f handler in
358368
List.iter iter_h hl; f body
359369
| Cexit (_n, el) ->
360370
List.iter f el
361-
| Ctrywith (e1, _id, e2, _dbg) ->
371+
| Ctrywith (e1, _id, e2, _dbg, _value_kind) ->
362372
f e1; f e2
363373
| Cregion e ->
364374
f e
@@ -386,17 +396,17 @@ let map_shallow f = function
386396
Cop (op, List.map f el, dbg)
387397
| Csequence (e1, e2) ->
388398
Csequence (f e1, f e2)
389-
| Cifthenelse(cond, ifso_dbg, ifso, ifnot_dbg, ifnot, dbg) ->
390-
Cifthenelse(f cond, ifso_dbg, f ifso, ifnot_dbg, f ifnot, dbg)
391-
| Cswitch (e, ia, ea, dbg) ->
392-
Cswitch (e, ia, Array.map (fun (e, dbg) -> f e, dbg) ea, dbg)
393-
| Ccatch (rf, hl, body) ->
399+
| Cifthenelse(cond, ifso_dbg, ifso, ifnot_dbg, ifnot, dbg, kind) ->
400+
Cifthenelse(f cond, ifso_dbg, f ifso, ifnot_dbg, f ifnot, dbg, kind)
401+
| Cswitch (e, ia, ea, dbg, kind) ->
402+
Cswitch (e, ia, Array.map (fun (e, dbg) -> f e, dbg) ea, dbg, kind)
403+
| Ccatch (rf, hl, body, kind) ->
394404
let map_h (n, ids, handler, dbg) = (n, ids, f handler, dbg) in
395-
Ccatch (rf, List.map map_h hl, f body)
405+
Ccatch (rf, List.map map_h hl, f body, kind)
396406
| Cexit (n, el) ->
397407
Cexit (n, List.map f el)
398-
| Ctrywith (e1, id, e2, dbg) ->
399-
Ctrywith (f e1, id, f e2, dbg)
408+
| Ctrywith (e1, id, e2, dbg, value_kind) ->
409+
Ctrywith (f e1, id, f e2, dbg, value_kind)
400410
| Cregion e ->
401411
Cregion (f e)
402412
| Ctail e ->

0 commit comments

Comments
 (0)