Skip to content

Asmgen changes for Flambda 2 #105

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 1 commit into from
Jul 23, 2021
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
36 changes: 32 additions & 4 deletions backend/asmgen.ml
Original file line number Diff line number Diff line change
Expand Up @@ -203,11 +203,9 @@ let compile_unit ~output_prefix ~asm_filename ~keep_asm ~obj_filename gen =
if create_asm && not keep_asm then remove_file asm_filename
)

let end_gen_implementation ?toplevel ~ppf_dump
(clambda : Clambda.with_constants) =
let end_gen_implementation0 ?toplevel ~ppf_dump make_cmm =
emit_begin_assembly ();
clambda
++ Profile.record "cmm" Cmmgen.compunit
make_cmm ()
++ Profile.record "compile_phrases" (List.iter (compile_phrase ~ppf_dump))
++ (fun () -> ());
(match toplevel with None -> () | Some f -> compile_genfuns ~ppf_dump f);
Expand All @@ -224,6 +222,10 @@ let end_gen_implementation ?toplevel ~ppf_dump
!Translmod.primitive_declarations));
emit_end_assembly ()

let end_gen_implementation ?toplevel ~ppf_dump clambda =
end_gen_implementation0 ?toplevel ~ppf_dump (fun () ->
Profile.record "cmm" Cmmgen.compunit clambda)

type middle_end =
backend:(module Backend_intf.S)
-> filename:string
Expand All @@ -249,6 +251,32 @@ let compile_implementation ?toplevel ~backend ~filename ~prefixname ~middle_end
in
end_gen_implementation ?toplevel ~ppf_dump clambda_with_constants)

type middle_end_flambda2 =
ppf_dump:Format.formatter
-> prefixname:string
-> backend:(module Flambda2__Flambda_backend_intf.S)
-> filename:string
-> module_ident:Ident.t
-> module_block_size_in_words:int
-> module_initializer:Lambda.lambda
-> Flambda2__Flambda_middle_end.middle_end_result

let compile_implementation_flambda2 ?toplevel ~backend ~filename ~prefixname
~size:module_block_size_in_words ~module_ident ~module_initializer
~(middle_end : middle_end_flambda2) ~flambda2_to_cmm ~ppf_dump
~required_globals () =
compile_unit ~output_prefix:prefixname
~asm_filename:(asm_filename prefixname) ~keep_asm:!keep_asm_file
~obj_filename:(prefixname ^ ext_obj)
(fun () ->
Ident.Set.iter Compilenv.require_global required_globals;
let middle_end_result =
middle_end ~backend ~module_block_size_in_words ~filename ~prefixname
~ppf_dump ~module_ident ~module_initializer
in
let cmm_phrases = flambda2_to_cmm middle_end_result in
end_gen_implementation0 ?toplevel ~ppf_dump (fun () -> cmm_phrases))

let linear_gen_implementation filename =
let open Linear_format in
let linear_unit_info, _ = restore filename in
Expand Down
31 changes: 31 additions & 0 deletions backend/asmgen.mli
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,37 @@ val compile_implementation
-> Lambda.program
-> unit

(** The type of converters from Lambda to Flambda 2 programs. *)
type middle_end_flambda2 =
ppf_dump:Format.formatter
-> prefixname:string
-> backend:(module Flambda2__Flambda_backend_intf.S)
-> filename:string
-> module_ident:Ident.t
-> module_block_size_in_words:int
-> module_initializer:Lambda.lambda
-> Flambda2__Flambda_middle_end.middle_end_result

(** Compile an implementation from Lambda using Flambda 2.
The Flambda 2 middle end does not use the Clambda language nor the
Cmmgen pass. Instead it emits Cmm directly. *)
val compile_implementation_flambda2
: ?toplevel:(string -> bool)
-> backend:(module Flambda2__Flambda_backend_intf.S)
-> filename:string
-> prefixname:string
-> size:int
-> module_ident:Ident.t
-> module_initializer:Lambda.lambda
-> middle_end:middle_end_flambda2
-> flambda2_to_cmm:(
Flambda2__Flambda_middle_end.middle_end_result
-> Cmm.phrase list)
-> ppf_dump:Format.formatter
-> required_globals:Ident.Set.t
-> unit
-> unit

val compile_implementation_linear :
string -> progname:string -> unit

Expand Down