Skip to content

Commit 3d7f37f

Browse files
committed
flambda-backend: Merge ocaml-jst
2 parents 4646c2e + e3076d2 commit 3d7f37f

File tree

185 files changed

+17979
-7923
lines changed

Some content is hidden

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

185 files changed

+17979
-7923
lines changed

.depend

Lines changed: 102 additions & 30 deletions
Large diffs are not rendered by default.

.github/workflows/build.yml

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,6 @@ jobs:
2121
use_runtime: d
2222
ocamlrunparam: "v=0,V=1"
2323

24-
- name: i386
25-
config: --enable-stack-allocation=no CC='cc32' AS='as --32' ASPP='gcc -m32 -c' -host i386-linux PARTIALLD='ld -r -melf_i386'
26-
os: ubuntu-20.04
27-
ocamlparam: ''
28-
boot_config: CC='cc32' AS='as --32' ASPP='gcc -m32 -c' -host i386-linux PARTIALLD='ld -r -melf_i386'
29-
boot_cachekey: 32bit
30-
3124
env:
3225
J: "3"
3326

@@ -36,11 +29,6 @@ jobs:
3629
if: matrix.os == 'macos-latest'
3730
run: HOMEBREW_NO_INSTALL_CLEANUP=TRUE brew install parallel
3831

39-
- name: Install GCC 32-bit libraries
40-
if: matrix.name == 'i386'
41-
run: |
42-
sudo apt-get install gcc-multilib gfortran-multilib
43-
4432
- name: Checkout the ocaml-jst repo
4533
uses: actions/checkout@master
4634
with:
@@ -61,13 +49,6 @@ jobs:
6149
path: 'ocaml-414'
6250
ref: '4.14'
6351

64-
- name: Setup 32-bit C compiler
65-
if: matrix.name == 'i386' && steps.cache.outputs.cache-hit != 'true'
66-
run: |
67-
mkdir -p ocaml-414/_install/bin
68-
{ echo '#!/bin/sh'; echo 'exec gcc -m32 "$@"'; } > ocaml-414/_install/bin/cc32
69-
chmod +x ocaml-414/_install/bin/cc32
70-
7152
- name: Build OCaml 4.14
7253
if: steps.cache.outputs.cache-hit != 'true'
7354
working-directory: ocaml-414

HACKING.jst.adoc

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,26 @@ To add a new printer, simply add a line of the form
8282

8383
to `tools/debug_printers.ml`, and then run `make debug_printers` in the `tools`
8484
directory to regenerate the printing script.
85+
86+
## Benchmarking
87+
88+
A small but relatively comprehensive benchmark is to run our compiler against `typing/typecore.ml`. First we install the
89+
opam switch with FP (frame pointers) enabled; adjust the version number as needed:
90+
91+
$ opam switch create 4.14.1-fp --packages=ocaml-variants.4.14.1+options,ocaml-option-fp --repos=default
92+
93+
Remember to check that the newly installed switch is being used:
94+
95+
$ opam switch
96+
# switch compiler description
97+
4.14.1 ocaml-base-compiler.4.14.1 4.14.1
98+
-> 4.14.1-fp ocaml-option-fp.1,ocaml-variants.4.14.1+options 4.14.1-fp
99+
100+
Then build the compiler - the following command will build the compiler using the opam switch, then use the newly-built compiler to build itself.
101+
102+
$ make -f Makefile.jst compiler
103+
104+
We can now benchmark our compiler against `typecore.ml`. The following `_bootinstall` is built using the opam switch and has FP enabled.
105+
106+
$ cd _build/main
107+
$ perf stat -r 5 ../_bootinstall/bin/ocamlc.opt -strict-sequence -principal -w +a-4-9-40-41-42-44-45-48-66-70 -warn-error A -bin-annot -safe-string -strict-formats -w -67 -g -bin-annot -I .ocamlcommon.objs/byte -I ../install/runtime_stdlib/lib/ocaml_runtime_stdlib/ -intf-suffix .ml -no-alias-deps -o .ocamlcommon.objs/byte/typecore.cmo -c -impl typecore.ml

asmcomp/afl_instrument.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ and instrument = function
8888
Ccatch (isrec, cases, instrument body, kind)
8989
| Cexit (ex, args) -> Cexit (ex, List.map instrument args)
9090
| Cregion e -> Cregion (instrument e)
91-
| Ctail e -> Ctail (instrument e)
91+
| Cexclave e -> Cexclave (instrument e)
9292

9393
(* these are base cases and have no logging *)
9494
| Cconst_int _ | Cconst_natint _ | Cconst_float _

asmcomp/cmm.ml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ type expression =
206206
| Ctrywith of expression * Backend_var.With_provenance.t * expression
207207
* Debuginfo.t * kind_for_unboxing
208208
| Cregion of expression
209-
| Ctail of expression
209+
| Cexclave of expression
210210

211211
type codegen_option =
212212
| Reduce_code_size
@@ -270,7 +270,7 @@ let iter_shallow_tail f = function
270270
| Cexit _ | Cop (Craise _, _, _) ->
271271
true
272272
| Cregion _
273-
| Ctail _
273+
| Cexclave _
274274
| Cconst_int _
275275
| Cconst_natint _
276276
| Cconst_float _
@@ -312,7 +312,7 @@ let map_shallow_tail ?kind f = function
312312
| Cexit _ | Cop (Craise _, _, _) as cmm ->
313313
cmm
314314
| Cregion _
315-
| Ctail _
315+
| Cexclave _
316316
| Cconst_int _
317317
| Cconst_natint _
318318
| Cconst_float _
@@ -325,7 +325,7 @@ let map_shallow_tail ?kind f = function
325325
let map_tail ?kind f =
326326
let rec loop = function
327327
| Cregion _
328-
| Ctail _
328+
| Cexclave _
329329
| Cconst_int _
330330
| Cconst_natint _
331331
| Cconst_float _
@@ -367,7 +367,7 @@ let iter_shallow f = function
367367
f e1; f e2
368368
| Cregion e ->
369369
f e
370-
| Ctail e ->
370+
| Cexclave e ->
371371
f e
372372
| Cconst_int _
373373
| Cconst_natint _
@@ -404,8 +404,8 @@ let map_shallow f = function
404404
Ctrywith (f e1, id, f e2, dbg, value_kind)
405405
| Cregion e ->
406406
Cregion (f e)
407-
| Ctail e ->
408-
Ctail (f e)
407+
| Cexclave e ->
408+
Cexclave (f e)
409409
| Cconst_int _
410410
| Cconst_natint _
411411
| Cconst_float _

asmcomp/cmm.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ type expression =
210210
| Ctrywith of expression * Backend_var.With_provenance.t * expression
211211
* Debuginfo.t * kind_for_unboxing
212212
| Cregion of expression
213-
| Ctail of expression
213+
| Cexclave of expression
214214

215215
type codegen_option =
216216
| Reduce_code_size

asmcomp/cmm_helpers.ml

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -619,13 +619,11 @@ let rec unbox_float dbg =
619619
map_tail ~kind:Any
620620
(function
621621
| Cop (Capply (_, Rc_close_at_apply), _, _) -> raise Exit
622-
| Ctail e -> Ctail (unbox_float dbg e)
623622
| e -> unbox_float dbg e)
624623
e
625624
with
626625
| e -> Cregion e
627626
| exception Exit -> Cop (Cload (Double, Immutable), [cmm], dbg))
628-
| Ctail e -> Ctail (unbox_float dbg e)
629627
| cmm -> Cop(Cload (Double, Immutable), [cmm], dbg)
630628
)
631629

@@ -1309,13 +1307,11 @@ let rec unbox_int dbg bi =
13091307
map_tail ~kind:Any
13101308
(function
13111309
| Cop (Capply (_, Rc_close_at_apply), _, _) -> raise Exit
1312-
| Ctail e -> Ctail (unbox_int dbg bi e)
13131310
| e -> unbox_int dbg bi e)
13141311
e
13151312
with
13161313
| e -> Cregion e
13171314
| exception Exit -> default cmm)
1318-
| Ctail e -> Ctail (unbox_int dbg bi e)
13191315
| cmm ->
13201316
default cmm
13211317
)
@@ -2018,15 +2014,15 @@ let has_local_allocs e =
20182014
let rec loop = function
20192015
| Cregion e ->
20202016
(* Local allocations within a nested region do not affect this region,
2021-
except inside a Ctail block *)
2017+
except inside a Cexclave block *)
20222018
loop_until_tail e
20232019
| Cop (Calloc Alloc_local, _, _)
20242020
| Cop ((Cextcall _ | Capply _), _, _) ->
20252021
raise Exit
20262022
| e ->
20272023
iter_shallow loop e
20282024
and loop_until_tail = function
2029-
| Ctail e -> loop e
2025+
| Cexclave e -> loop e
20302026
| Cregion _ -> ()
20312027
| e -> ignore (iter_shallow_tail loop_until_tail e)
20322028
in
@@ -2036,13 +2032,13 @@ let has_local_allocs e =
20362032

20372033
let remove_region_tail e =
20382034
let rec has_tail = function
2039-
| Ctail _
2035+
| Cexclave _
20402036
| Cop(Capply(_, Rc_close_at_apply), _, _) -> raise Exit
20412037
| Cregion _ -> ()
20422038
| e -> ignore (iter_shallow_tail has_tail e)
20432039
in
20442040
let rec remove_tail = function
2045-
| Ctail e -> e
2041+
| Cexclave e -> e
20462042
| Cop(Capply(mach, Rc_close_at_apply), args, dbg) ->
20472043
Cop(Capply(mach, Rc_normal), args, dbg)
20482044
| Cregion _ as e -> e

asmcomp/cmm_invariants.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ let rec check env (expr : Cmm.expression) =
174174
check env body;
175175
check env handler
176176
| Cregion e -> check env e
177-
| Ctail e -> check env e
177+
| Cexclave e -> check env e
178178

179179
let run ppf (fundecl : Cmm.fundecl) =
180180
let env = Env.init () in

asmcomp/cmmgen.ml

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -168,11 +168,14 @@ let rec expr_size env = function
168168
(* Pgenarray is excluded from recursive bindings by the
169169
check in Translcore.check_recursive_lambda *)
170170
RHS_nonrec
171-
| Uprim (Pduprecord ((Record_regular | Record_inlined _), sz), _, _) ->
171+
| Uprim (Pduprecord ((Record_boxed _ | Record_inlined (_, Variant_boxed _)),
172+
sz), _, _) ->
172173
RHS_block (Lambda.alloc_heap, sz)
173-
| Uprim (Pduprecord (Record_unboxed _, _), _, _) ->
174+
| Uprim (Pduprecord ((Record_unboxed _
175+
| Record_inlined (_, Variant_unboxed _)),
176+
_), _, _) ->
174177
assert false
175-
| Uprim (Pduprecord (Record_extension _, sz), _, _) ->
178+
| Uprim (Pduprecord (Record_inlined (_, Variant_extensible), sz), _, _) ->
176179
RHS_block (Lambda.alloc_heap, sz + 1)
177180
| Uprim (Pduprecord (Record_float, sz), _, _) ->
178181
RHS_floatblock (Lambda.alloc_heap, sz)
@@ -190,7 +193,7 @@ let rec expr_size env = function
190193
| _ -> assert false)
191194
| Uregion exp ->
192195
expr_size env exp
193-
| Utail exp ->
196+
| Uexclave exp ->
194197
expr_size env exp
195198
| _ -> RHS_nonrec
196199

@@ -368,7 +371,7 @@ let is_unboxed_number_cmm ~strict cmm =
368371
| _ ->
369372
notify No_unboxing
370373
end
371-
| Cregion e | Ctail e ->
374+
| Cregion e ->
372375
aux e
373376
| l ->
374377
if not (Cmm.iter_shallow_tail aux l) then
@@ -748,8 +751,8 @@ let rec transl env e =
748751
Cop(Cload (Word_int, Mutable), [Cconst_int (0, dbg)], dbg)
749752
| Uregion e ->
750753
region (transl env e)
751-
| Utail e ->
752-
Ctail (transl env e)
754+
| Uexclave e ->
755+
Cexclave (transl env e)
753756

754757
and transl_catch (kind : Cmm.kind_for_unboxing) env nfail ids body handler dbg =
755758
let ids = List.map (fun (id, kind) -> (id, kind, ref No_result)) ids in

asmcomp/printcmm.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,8 +272,8 @@ let rec expr ppf = function
272272
sequence e1 VP.print id sequence e2
273273
| Cregion e ->
274274
fprintf ppf "@[<2>(region@ %a)@]" sequence e
275-
| Ctail e ->
276-
fprintf ppf "@[<2>(tail@ %a)@]" sequence e
275+
| Cexclave e ->
276+
fprintf ppf "@[<2>(exclave@ %a)@]" sequence e
277277

278278
and sequence ppf = function
279279
| Csequence(e1, e2) -> fprintf ppf "%a@ %a" sequence e1 sequence e2

asmcomp/selectgen.ml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ method is_simple_expr = function
388388
| Ccmpf _ -> List.for_all self#is_simple_expr args
389389
end
390390
| Cassign _ | Cifthenelse _ | Cswitch _ | Ccatch _ | Cexit _
391-
| Ctrywith _ | Cregion _ | Ctail _ -> false
391+
| Ctrywith _ | Cregion _ | Cexclave _ -> false
392392

393393
(* Analyses the effects and coeffects of an expression. This is used across
394394
a whole list of expressions with a view to determining which expressions
@@ -435,7 +435,7 @@ method effects_of exp =
435435
in
436436
EC.join from_op (EC.join_list_map args self#effects_of)
437437
| Cassign _ | Cswitch _ | Ccatch _ | Cexit _ | Ctrywith _
438-
| Cregion _ | Ctail _ ->
438+
| Cregion _ | Cexclave _ ->
439439
EC.arbitrary
440440

441441
(* Says whether an integer constant is a suitable immediate argument for
@@ -974,9 +974,9 @@ method emit_expr_aux (env:environment) exp :
974974
assert (List.length unclosed <= List.length old_regions);
975975
Some (rd, unclosed)
976976
end
977-
| Ctail e ->
977+
| Cexclave e ->
978978
begin match env.regions with
979-
| [] -> Misc.fatal_error "Selectgen.emit_expr: Ctail but not in tail of a region"
979+
| [] -> Misc.fatal_error "Selectgen.emit_expr: Cexclave but not in tail of a region"
980980
| cl :: rest ->
981981
self#insert_endregions env [cl];
982982
self#emit_expr_aux { env with regions = rest } e
@@ -1320,9 +1320,9 @@ method emit_tail (env:environment) exp =
13201320
let reg = self#regs_for typ_int in
13211321
self#insert env (Iop Ibeginregion) [| |] reg;
13221322
self#emit_tail {env with regions = reg::env.regions} e
1323-
| Ctail e ->
1323+
| Cexclave e ->
13241324
begin match env.regions with
1325-
| [] -> Misc.fatal_error "Selectgen.emit_tail: Ctail not inside Cregion"
1325+
| [] -> Misc.fatal_error "Selectgen.emit_tail: Cexclave not inside Cregion"
13261326
| reg :: regions ->
13271327
self#insert_endregions env [reg];
13281328
self#emit_tail { env with regions } e

0 commit comments

Comments
 (0)