Skip to content

Commit 40c1f45

Browse files
authored
Merge branch 'main' into lambda-layout
2 parents c95688c + 53f391a commit 40c1f45

File tree

264 files changed

+15036
-9226
lines changed

Some content is hidden

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

264 files changed

+15036
-9226
lines changed

.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"ocaml.sandbox": {
33
"kind": "opam",
4-
"switch": "4.14.0"
4+
"switch": "4.14.1"
55
}
66
}

HACKING.md

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,23 @@
33
This page is intended to keep track of useful information for people who
44
want to modify the Flambda backend. Jump to:
55

6-
- [Branches, pull requests, etc.](#branches-pull-requests-etc)
7-
- [Upstream subtree](#upstream-subtree)
8-
- [Code formatting](#code-formatting)
9-
- [Rebuilding during dev work](#rebuilding-during-dev-work)
10-
- [Running tests](#running-tests)
11-
- [Running only part of the upstream testsuite](#running-only-part-of-the-upstream-testsuite)
12-
- [Running tests with coverage analysis](#running-tests-with-coverage-analysis)
13-
- [Running the compiler produced by "make hacking" on an example without the stdlib](#running-the-compiler-produced-by-make-hacking-on-an-example-without-the-stdlib)
14-
- [Getting the compilation command for a stdlib file](#getting-the-compilation-command-for-a-stdlib-file)
15-
- [Bootstrapping the ocaml subtree](#bootstrapping-the-ocaml-subtree)
16-
- [Testing the compiler built locally with OPAM](#testing-the-compiler-built-locally-with-opam)
17-
- [Pulling changes onto a release branch](#pulling-changes-onto-a-release-branch)
18-
- [Rebasing to a new major version of the upstream compiler](#rebasing-to-a-new-major-version-of-the-upstream-compiler)
19-
- [How to add a new intrinsic to the compiler](#how-to-add-a-new-intrinsic-to-the-compiler)
20-
- [How to add a new command line option](#how-to-add-a-new-command-line-option)
21-
- [Installation tree comparison script](#installation-tree-comparison-script)
6+
- [Branches, pull requests, etc.](#branches-pull-requests-etc)
7+
- [Upstream subtree](#upstream-subtree)
8+
- [Code formatting](#code-formatting)
9+
- [Rebuilding during dev work](#rebuilding-during-dev-work)
10+
- [Updating magic numbers](#updating-magic-numbers)
11+
- [Running tests](#running-tests)
12+
- [Running only part of the upstream testsuite](#running-only-part-of-the-upstream-testsuite)
13+
- [Running tests with coverage analysis](#running-tests-with-coverage-analysis)
14+
- [Running the compiler produced by "make hacking" on an example without the stdlib](#running-the-compiler-produced-by-make-hacking-on-an-example-without-the-stdlib)
15+
- [Getting the compilation command for a stdlib file](#getting-the-compilation-command-for-a-stdlib-file)
16+
- [Bootstrapping the ocaml subtree](#bootstrapping-the-ocaml-subtree)
17+
- [Testing the compiler built locally with OPAM](#testing-the-compiler-built-locally-with-opam)
18+
- [Pulling changes onto a release branch](#pulling-changes-onto-a-release-branch)
19+
- [Rebasing to a new major version of the upstream compiler](#rebasing-to-a-new-major-version-of-the-upstream-compiler)
20+
- [How to add a new intrinsic to the compiler](#how-to-add-a-new-intrinsic-to-the-compiler)
21+
- [How to add a new command line option](#how-to-add-a-new-command-line-option)
22+
- [Installation tree comparison script](#installation-tree-comparison-script)
2223

2324
## Branches, pull requests, etc.
2425

@@ -112,6 +113,22 @@ Any changes in `ocaml/asmcomp` and `ocaml/middle_end` directories
112113
should also be applied to the corresponding directories `backend` and
113114
`middle_end`.
114115

116+
## Updating magic numbers
117+
118+
Start from a completely clean tree. Then change into the `ocaml` subdirectory
119+
and proceed as follows:
120+
```
121+
./configure
122+
make coldstart
123+
make coreall
124+
```
125+
Then edit `runtime/exec.h` and `utils/config.mlp` to bump the numbers. Then:
126+
```
127+
make coreall
128+
make bootstrap
129+
```
130+
and commit the result.
131+
115132
## Running tests
116133

117134
Prior to `make install` you can do:

Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ fmt:
9393
$$(find backend/debug \
9494
\( -name "*.ml" -or -name "*.mli" \))
9595
ocamlformat -i backend/cmm_helpers.ml{,i}
96+
ocamlformat -i backend/cmm_builtins.ml{,i}
9697
ocamlformat -i backend/checkmach.ml{,i}
9798
ocamlformat -i tools/merge_archives.ml
9899
ocamlformat -i \
@@ -101,6 +102,9 @@ fmt:
101102
ocamlformat -i \
102103
$$(find utils \
103104
\( -name "*.ml" -or -name "*.mli" \))
105+
ocamlformat -i \
106+
$$(find ocaml/utils \
107+
\( -name "*.ml" -or -name "*.mli" \))
104108

105109
.PHONY: check-fmt
106110
check-fmt:
@@ -111,8 +115,10 @@ check-fmt:
111115
[ "$$(git status --porcelain backend/asm_targets)" != "" ] || \
112116
[ "$$(git status --porcelain backend/debug)" != "" ] || \
113117
[ "$$(git status --porcelain backend/cmm_helpers.ml{,i})" != "" ] || \
118+
[ "$$(git status --porcelain backend/cmm_builtins.ml{,i})" != "" ] || \
114119
[ "$$(git status --porcelain backend/checkmach.ml{,i})" != "" ] || \
115120
[ "$$(git status --porcelain tools/merge_archives.ml)" != "" ] || \
121+
[ "$$(git status --porcelain ocaml/utils)" != "" ] || \
116122
[ "$$(git status --porcelain utils)" != "" ]; then \
117123
echo; \
118124
echo "Tree must be clean before running 'make check-fmt'"; \
@@ -126,8 +132,10 @@ check-fmt:
126132
[ "$$(git diff backend/asm_targets)" != "" ] || \
127133
[ "$$(git diff backend/debug)" != "" ] || \
128134
[ "$$(git diff backend/cmm_helpers.ml{,i})" != "" ] || \
135+
[ "$$(git diff backend/cmm_builtins.ml{,i})" != "" ] || \
129136
[ "$$(git diff backend/checkmach.ml{,i})" != "" ] || \
130137
[ "$$(git diff tools/merge_archives.ml)" != "" ] || \
138+
[ "$$(git diff ocaml/utils)" != "" ] || \
131139
[ "$$(git diff utils)" != "" ]; then \
132140
echo; \
133141
echo "The following code was not formatted correctly:"; \

backend/.ocamlformat-enable

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
cmm_helpers.ml
22
cmm_helpers.mli
3+
cmm_builtins.ml
4+
cmm_builtins.mli
35
internal_assembler/*.ml
46
internal_assembler/*.mli
57
checkmach.ml

backend/amd64/emit.mlp

Lines changed: 68 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,52 @@ let emit_call_bound_errors () =
361361
emit_call "caml_ml_array_bound_error"
362362
end
363363

364+
(* Record function info for dwarf and emit label if needed. *)
365+
let emit_dwarf_for_fundecl fun_name fun_dbg =
366+
match Emitaux.Dwarf_helpers.record_dwarf_for_fundecl ~fun_name fun_dbg with
367+
| None -> ()
368+
| Some label -> def_label label
369+
370+
let build_asm_directives () : (module Asm_targets.Asm_directives_intf.S) = (
371+
module Asm_targets.Asm_directives.Make(struct
372+
373+
let emit_line str = X86_dsl.D.comment str
374+
375+
let get_file_num file_name =
376+
Emitaux.get_file_num ~file_emitter:X86_dsl.D.file file_name
377+
378+
let debugging_comments_in_asm_files =
379+
!Flambda_backend_flags.dasm_comments
380+
381+
module D = struct
382+
open X86_ast
383+
384+
include X86_dsl.D
385+
386+
type data_type =
387+
| NONE | DWORD | QWORD
388+
389+
type nonrec constant = constant
390+
let const_int64 num = Const num
391+
let const_label str = ConstLabel str
392+
let const_add c1 c2 = ConstAdd (c1, c2)
393+
let const_sub c1 c2 = ConstSub (c1, c2)
394+
395+
let label ?data_type str =
396+
let typ =
397+
Option.map
398+
(function
399+
| NONE -> X86_ast.NONE
400+
| DWORD -> X86_ast.DWORD
401+
| QWORD -> X86_ast.QWORD)
402+
data_type
403+
in
404+
label ?typ str
405+
end
406+
end)
407+
)
408+
409+
364410
(* Names for instructions *)
365411

366412
let instr_for_intop = function
@@ -525,13 +571,16 @@ let emit_float_constant f lbl =
525571
_label (emit_label lbl);
526572
D.qword (Const f)
527573

528-
let emit_global_label s =
529-
let lbl = Cmm_helpers.make_symbol s in
574+
let emit_global_label_for_symbol lbl =
530575
add_def_symbol lbl;
531576
let lbl = emit_symbol lbl in
532577
D.global lbl;
533578
_label lbl
534579

580+
let emit_global_label s =
581+
let lbl = Cmm_helpers.make_symbol s in
582+
emit_global_label_for_symbol lbl
583+
535584
let move (src : Reg.t) (dst : Reg.t) =
536585
if src.loc <> dst.loc then
537586
begin match src.typ, src.loc, dst.typ, dst.loc with
@@ -1303,7 +1352,7 @@ let fundecl fundecl =
13031352
cfi_adjust_cfa_offset (-n);
13041353
end;
13051354
end;
1306-
def_label fundecl.fun_end_label;
1355+
emit_dwarf_for_fundecl fundecl.fun_name fundecl.fun_dbg;
13071356
cfi_endproc ();
13081357
emit_function_type_and_size fundecl.fun_name
13091358

@@ -1341,10 +1390,17 @@ let reset_all () =
13411390
float_constants := [];
13421391
all_functions := []
13431392

1344-
let begin_assembly ~init_dwarf =
1393+
let begin_assembly unix =
13451394
reset_all ();
13461395

1347-
init_dwarf ();
1396+
if !Flambda_backend_flags.internal_assembler &&
1397+
!Emitaux.binary_backend_available then
1398+
X86_proc.register_internal_assembler (Internal_assembler.assemble unix);
1399+
1400+
let code_begin = Cmm_helpers.make_symbol "code_begin" in
1401+
let code_end = Cmm_helpers.make_symbol "code_end" in
1402+
Emitaux.Dwarf_helpers.begin_dwarf ~build_asm_directives ~code_begin ~code_end
1403+
~file_emitter:D.file;
13481404

13491405
if system = S_win64 then begin
13501406
D.extrn "caml_call_gc" NEAR;
@@ -1378,8 +1434,8 @@ let begin_assembly ~init_dwarf =
13781434
D.data ();
13791435
emit_global_label "data_begin";
13801436

1381-
emit_named_text_section (Cmm_helpers.make_symbol "code_begin");
1382-
emit_global_label "code_begin";
1437+
emit_named_text_section code_begin;
1438+
emit_global_label_for_symbol code_begin;
13831439
if system = S_macosx then I.nop (); (* PR#4690 *)
13841440
()
13851441

@@ -1677,7 +1733,7 @@ let emit_trap_notes () =
16771733
D.data ()
16781734
end
16791735

1680-
let end_assembly dwarf =
1736+
let end_assembly () =
16811737
if !float_constants <> [] then begin
16821738
begin match system with
16831739
| S_macosx -> D.section ["__TEXT";"__literal8"] None ["8byte_literals"]
@@ -1692,11 +1748,12 @@ let end_assembly dwarf =
16921748
(* Emit probe handler wrappers *)
16931749
List.iter emit_probe_handler_wrapper !probes;
16941750

1695-
emit_named_text_section (Cmm_helpers.make_symbol "code_end");
1751+
let code_end = Cmm_helpers.make_symbol "code_end" in
1752+
emit_named_text_section code_end;
16961753
if system = S_macosx then I.nop ();
16971754
(* suppress "ld warning: atom sorting error" *)
16981755

1699-
emit_global_label "code_end";
1756+
emit_global_label_for_symbol code_end;
17001757

17011758
emit_imp_table();
17021759

@@ -1769,6 +1826,6 @@ let end_assembly dwarf =
17691826
else
17701827
None
17711828
in
1772-
Option.iter Dwarf_ocaml.Dwarf.emit dwarf;
1829+
Emitaux.Dwarf_helpers.emit_dwarf ();
17731830
X86_proc.generate_code asm;
17741831
reset_all ()

backend/arm64/emit.mlp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1151,7 +1151,10 @@ let fundecl fundecl =
11511151
List.iter emit_call_bound_error !bound_error_sites;
11521152
assert (List.length !call_gc_sites = num_call_gc);
11531153
assert (List.length !bound_error_sites = num_check_bound);
1154-
`{emit_label fundecl.fun_end_label}:\n`;
1154+
(match Emitaux.Dwarf_helpers.record_dwarf_for_fundecl
1155+
~fun_name:fundecl.fun_name fundecl.fun_dbg with
1156+
| None -> ()
1157+
| Some label -> `{emit_label label}:\n`);
11551158
cfi_endproc();
11561159
emit_symbol_type emit_symbol fundecl.fun_name "function";
11571160
emit_symbol_size fundecl.fun_name;
@@ -1188,7 +1191,7 @@ let data l =
11881191

11891192
(* Beginning / end of an assembly file *)
11901193

1191-
let begin_assembly ~init_dwarf:_ =
1194+
let begin_assembly _unix =
11921195
reset_debug_info();
11931196
` .file \"\"\n`; (* PR#7037 *)
11941197
let lbl_begin = Cmm_helpers.make_symbol "data_begin" in

0 commit comments

Comments
 (0)