Skip to content

Remove flambda-backend copies of Closure, Flambda 1, Clambda, Cmmgen, etc. #1937

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@ jobs:
check_arch: true

- name: build_upstream_closure
config: --enable-middle-end=closure
config: --enable-middle-end=upstream-closure
os: ubuntu-20.04

- name: build_upstream_closure_runtime5
config: --enable-middle-end=closure --enable-runtime5
config: --enable-middle-end=upstream-closure --enable-runtime5
os: ubuntu-20.04
expected_fail: true

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ocamlformat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
run: |
./configure \
--prefix=$GITHUB_WORKSPACE/_install \
--enable-middle-end=closure \
--enable-middle-end=flambda2 \
--with-dune=/bin/false

- name: Check formatting of Flambda 2 and Cfg code
Expand Down
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,8 @@ The Flambda backend tree has to be configured before building. The configure sc
in; you have to run `autoconf`. For example:
```
$ autoconf
$ ./configure --prefix=/path/to/install/dir --enable-middle-end=closure
$ ./configure --prefix=/path/to/install/dir
```
You can also specify `--enable-middle-end=flambda` or `--enable-middle-end=flambda2`. (The Flambda 2
compiler is not yet ready for production use.)

## Building and installing

Expand Down
18 changes: 0 additions & 18 deletions backend/asmgen.ml
Original file line number Diff line number Diff line change
Expand Up @@ -471,14 +471,6 @@ let end_gen_implementation unix ?toplevel ~ppf_dump ~sourcefile make_cmm =
!Translmod.primitive_declarations));
emit_end_assembly sourcefile ()

type middle_end =
backend:(module Backend_intf.S)
-> filename:string
-> prefixname:string
-> ppf_dump:Format.formatter
-> Lambda.program
-> Clambda.with_constants

type direct_to_cmm =
ppf_dump:Format.formatter
-> prefixname:string
Expand All @@ -487,10 +479,6 @@ type direct_to_cmm =
-> Cmm.phrase list

type pipeline =
| Via_clambda of {
backend : (module Backend_intf.S);
middle_end : middle_end;
}
| Direct_to_cmm of direct_to_cmm

let asm_filename output_prefix =
Expand All @@ -508,12 +496,6 @@ let compile_implementation unix ?toplevel ~pipeline
Compilation_unit.Set.iter Compilenv.require_global
program.required_globals;
match pipeline with
| Via_clambda { middle_end; backend; } ->
let clambda_with_constants =
middle_end ~backend ~filename ~prefixname ~ppf_dump program
in
end_gen_implementation unix ?toplevel ~ppf_dump ~sourcefile:filename
(fun () -> Profile.record "cmm" Cmmgen.compunit clambda_with_constants)
| Direct_to_cmm direct_to_cmm ->
let cmm_phrases =
direct_to_cmm ~ppf_dump ~prefixname ~filename program
Expand Down
15 changes: 1 addition & 14 deletions backend/asmgen.mli
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,6 @@

(** From Lambda to assembly code *)

(** The type of converters from Lambda to Clambda. *)
type middle_end =
backend:(module Backend_intf.S)
-> filename:string
-> prefixname:string
-> ppf_dump:Format.formatter
-> Lambda.program
-> Clambda.with_constants

(** The type of converters straight from Lambda to Cmm. This is how Flambda 2
operates. *)
type direct_to_cmm =
Expand All @@ -33,12 +24,8 @@ type direct_to_cmm =
-> Lambda.program
-> Cmm.phrase list

(** The ways to get from Lambda to Cmm. *)
(** The one true way to get from Lambda to Cmm. *)
type pipeline =
| Via_clambda of {
backend : (module Backend_intf.S);
middle_end : middle_end;
}
| Direct_to_cmm of direct_to_cmm

(** Compile an implementation from Lambda using the given middle end. *)
Expand Down
7 changes: 1 addition & 6 deletions backend/asmlibrarian.ml
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,7 @@ type error =
exception Error of error

let default_ui_export_info =
if Config.flambda then
Cmx_format.Flambda1 Export_info.empty
else if Config.flambda2 then
Cmx_format.Flambda2 None
else
Cmx_format.Clambda Clambda.Value_unknown
Cmx_format.Flambda2 None

let read_info name =
let filename =
Expand Down
5 changes: 3 additions & 2 deletions backend/asmlink.ml
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,8 @@ let make_startup_file unix ~ppf_dump ~sourcefile_for_dwarf genfns units =
List.flatten (List.map (fun u -> u.defines) units) in
List.iter compile_phrase (Cmm_helpers.entry_point name_list);
List.iter compile_phrase
(Cmm_helpers.emit_preallocated_blocks [] (* add gc_roots (for dynlink) *)
(* Emit the GC roots table, for dynlink. *)
(Cmm_helpers.emit_gc_roots_table ~symbols:[]
(Generic_fns.compile ~shared:false genfns));
Array.iteri
(fun i name -> compile_phrase (Cmm_helpers.predef_exception i name))
Expand Down Expand Up @@ -404,7 +405,7 @@ let make_shared_startup_file unix ~ppf_dump ~sourcefile_for_dwarf genfns units =
sourcefile_for_dwarf;
Emit.begin_assembly unix;
List.iter compile_phrase
(Cmm_helpers.emit_preallocated_blocks [] (* add gc_roots (for dynlink) *)
(Cmm_helpers.emit_gc_roots_table ~symbols:[]
(Generic_fns.compile ~shared:true genfns));
let dynunits = List.map (fun u -> Option.get u.dynunit) units in
compile_phrase (Cmm_helpers.plugin_header dynunits);
Expand Down
64 changes: 14 additions & 50 deletions backend/asmpackager.ml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ type flambda2 =
Cmm.phrase list

let make_package_object unix ~ppf_dump members targetobj targetname coercion
~backend ~(flambda2 : flambda2) =
~(flambda2 : flambda2) =
Profile.record_call (Printf.sprintf "pack(%s)" targetname) (fun () ->
let objtemp =
if !Clflags.keep_asm_file
Expand Down Expand Up @@ -137,14 +137,7 @@ let make_package_object unix ~ppf_dump members targetobj targetname coercion
}
in
let pipeline : Asmgen.pipeline =
if Config.flambda2 then
Direct_to_cmm (flambda2 ~keep_symbol_tables:true)
else
let middle_end =
if Config.flambda then Flambda_middle_end.lambda_to_clambda
else Closure_middle_end.lambda_to_clambda
in
Via_clambda { middle_end; backend }
Direct_to_cmm (flambda2 ~keep_symbol_tables:true)
in
Asmgen.compile_implementation ~pipeline unix
~filename:targetname
Expand All @@ -167,24 +160,8 @@ let make_package_object unix ~ppf_dump members targetobj targetname coercion
let get_export_info_flambda2 ui : Flambda2_cmx.Flambda_cmx_format.t option =
assert(Config.flambda2);
match ui.ui_export_info with
| Clambda _ -> assert false
| Flambda1 _ -> assert false
| Flambda2 info -> info

let get_export_info_flambda1 ui : Export_info.t =
assert(Config.flambda);
match ui.ui_export_info with
| Clambda _ -> assert false
| Flambda1 (info : Export_info.t) -> info
| Flambda2 _ -> assert false

let get_approx ui : Clambda.value_approximation =
assert(not (Config.flambda || Config.flambda2));
match ui.ui_export_info with
| Clambda info -> info
| Flambda1 _ -> assert false
| Flambda2 _ -> assert false

let build_package_cmx members cmxfile =
let unit_names =
List.map (fun m -> m.pm_name) members in
Expand All @@ -203,26 +180,14 @@ let build_package_cmx members cmxfile =
members [] in
let ui = Compilenv.current_unit_infos() in
let ui_export_info =
if Config.flambda then
let ui_export_info =
List.fold_left (fun acc info ->
Export_info.merge acc
(get_export_info_flambda1 info))
(get_export_info_flambda1 ui)
units
in
Flambda1 ui_export_info
else if Config.flambda2 then
let flambda_export_info =
List.fold_left (fun acc info ->
Flambda2_cmx.Flambda_cmx_format.merge
(get_export_info_flambda2 info) acc)
(get_export_info_flambda2 ui)
units
in
Flambda2 flambda_export_info
else
Clambda (get_approx ui)
let flambda_export_info =
List.fold_left (fun acc info ->
Flambda2_cmx.Flambda_cmx_format.merge
(get_export_info_flambda2 info) acc)
(get_export_info_flambda2 ui)
units
in
Flambda2 flambda_export_info
in
let ui_checks = Checks.create () in
List.iter (fun info -> Checks.merge info.ui_checks ~into:ui_checks) units;
Expand Down Expand Up @@ -255,7 +220,7 @@ let build_package_cmx members cmxfile =
(* Make the .cmx and the .o for the package *)

let package_object_files unix ~ppf_dump files targetcmx
targetobj targetname coercion ~backend ~flambda2 =
targetobj targetname coercion ~flambda2 =
let pack_path =
let for_pack_prefix = CU.Prefix.from_clflags () in
let name = targetname |> CU.Name.of_string in
Expand All @@ -264,13 +229,12 @@ let package_object_files unix ~ppf_dump files targetcmx
let members = map_left_right (read_member_info pack_path) files in
check_units members;
make_package_object unix ~ppf_dump members targetobj targetname coercion
~backend ~flambda2;
~flambda2;
build_package_cmx members targetcmx

(* The entry point *)

let package_files unix ~ppf_dump initial_env files targetcmx ~backend
~flambda2 =
let package_files unix ~ppf_dump initial_env files targetcmx ~flambda2 =
let files =
List.map
(fun f ->
Expand All @@ -293,7 +257,7 @@ let package_files unix ~ppf_dump initial_env files targetcmx ~backend
let coercion =
Typemod.package_units initial_env files targetcmi comp_unit in
package_object_files unix ~ppf_dump files targetcmx targetobj targetname
coercion ~backend ~flambda2
coercion ~flambda2
)
~exceptionally:(fun () -> remove_file targetcmx; remove_file targetobj)

Expand Down
1 change: 0 additions & 1 deletion backend/asmpackager.mli
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ val package_files
-> Env.t
-> string list
-> string
-> backend:(module Backend_intf.S)
-> flambda2:(
ppf_dump:Format.formatter ->
prefixname:string ->
Expand Down
Loading