text stringlengths 12 786k |
|---|
module Threshold = struct type t = | Never_inline | Can_inline_if_no_larger_than of int let add t1 t2 = match t1 , t2 with | Never_inline , t -> t | t , Never_inline -> t | Can_inline_if_no_larger_than i1 , Can_inline_if_no_larger_than i2 -> Can_inline_if_no_larger_than ( i1 + i2 ) let sub t1 t2... |
let can_try_inlining lam inlining_threshold ~ number_of_arguments ~ size_from_approximation = match inlining_threshold with | Threshold . Never_inline -> Threshold . Never_inline | Threshold . Can_inline_if_no_larger_than inlining_threshold -> let bonus = number_of_arguments in let size = let than = inl... |
let lambda_smaller lam ~ than = match lambda_smaller ' lam ~ than with | Some _ -> true | None -> false |
let can_inline lam inlining_threshold ~ bonus = match inlining_threshold with | Threshold . Never_inline -> false | Threshold . Can_inline_if_no_larger_than inlining_threshold -> lambda_smaller lam ~ than ( : inlining_threshold + bonus ) |
let cost ( flag : Clflags . Int_arg_helper . parsed ) ~ round = Clflags . Int_arg_helper . get ~ key : round flag |
module Benefit = struct type t = { remove_call : int ; remove_alloc : int ; remove_prim : int ; remove_branch : int ; direct_call_of_indirect : int ; requested_inline : int ; } let zero = { remove_call = 0 ; remove_alloc = 0 ; remove_prim = 0 ; remove_branch = 0 ; direct_call_... |
module Whether_sufficient_benefit = struct type t = { round : int ; benefit : Benefit . t ; toplevel : bool ; branch_depth : int ; lifting : bool ; original_size : int ; new_size : int ; evaluated_benefit : int ; estimate : bool ; } let create ~ original ~ toplevel ~ branch_depth l... |
let maximum_interesting_size_of_function_body_base = lazy begin let max_cost = ref 0 in for round = 0 to ( Clflags . rounds ( ) ) - 1 do let max_size = let inline_call_cost = cost ! Clflags . inline_call_cost ~ round in direct_call_size + ( inline_call_cost * benefit_factor ) in max_cost :... |
let maximum_interesting_size_of_function_body_multiplier = lazy begin let max_cost = ref 0 in for round = 0 to ( Clflags . rounds ( ) ) - 1 do let max_size = let inline_prim_cost = cost ! Clflags . inline_prim_cost ~ round in inline_prim_cost * benefit_factor in max_cost := max ! max_cost max_... |
let maximum_interesting_size_of_function_body num_free_variables = let base = Lazy . force maximum_interesting_size_of_function_body_base in let multiplier = Lazy . force maximum_interesting_size_of_function_body_multiplier in base + ( num_free_variables * multiplier ) |
let get_function_body ( function_decl : A . function_declaration ) = match function_decl . function_body with | None -> assert false | Some function_body -> function_body |
type ( ' a , ' b ) inlining_result = | Changed of ( Flambda . t * R . t ) * ' a | Original of ' b |
type ' b good_idea = | Try_it | Don ' t_try_it of ' b |
let inline env r ~ lhs_of_application ~ closure_id_being_applied ( ~ function_decl : A . function_declaration ) ( ~ function_body : A . function_body ) ~ value_set_of_closures ~ only_use_of_function ~ original ~ recursive ( ~ args : Variable . t list ) ~ size_from_approximation ~ dbg ~ ... |
let specialise env r ~ lhs_of_application ( ~ function_decls : A . function_declarations ) ( ~ function_decl : A . function_declaration ) ~ closure_id_being_applied ( ~ value_set_of_closures : A . value_set_of_closures ) ~ args ~ args_approxs ~ dbg ~ reg_close ~ mode ~ simplify ~ origin... |
let for_call_site ~ env ~ r ( ~ function_decls : A . function_declarations ) ~ lhs_of_application ~ closure_id_being_applied ( ~ function_decl : A . function_declaration ) ( ~ value_set_of_closures : A . value_set_of_closures ) ~ args ~ args_approxs ~ dbg ~ reg_close ~ mode ~ simplify ... |
let should_inline_inside_declaration ( decl : Flambda . function_declaration ) = not decl . stub |
let make_inlined_body ~ callee ~ params ~ args ~ my_closure ~ my_depth ~ rec_info ~ body ~ exn_continuation ~ return_continuation ~ apply_exn_continuation ~ apply_return_continuation ~ bind_params ~ bind_depth ~ apply_renaming = let perm = Renaming . empty in let perm = match ( apply_return_continu... |
let wrap_inlined_body_for_exn_support acc ~ extra_args ~ apply_exn_continuation ~ apply_return_continuation ~ result_arity ~ make_inlined_body ~ apply_cont_create ~ let_cont_create = let wrapper = Continuation . create ( ) in let body_with_pop acc = match ( apply_return_continuation : Flambda . App... |
module Absolute = struct type t = Compilation_unit . t * path and path = | Empty | Unknown of { prev : path } | Function of { dbg : Debuginfo . t ; name : string ; prev : path } | Module of { name : string ; prev : path } | Class of { name : string ; prev : path } | Call of... |
module Relative = struct type t = Absolute . path let print = Absolute . print_path let empty = Absolute . Empty let compare = Absolute . compare_path let rec concat ( ~ earlier : t ) ( ~ later : t ) : t = match later with | Absolute . Empty -> earlier | Unknown { prev } -> Unknown ... |
let extend_absolute ( compilation_unit , absolute ) relative = let rec aux ( r : Relative . t ) : Absolute . path = match r with | Absolute . Empty -> absolute | Unknown { prev } -> Unknown { prev = aux prev } | Class { name ; prev } -> Class { name ; prev = aux prev } |... |
module Tracker = struct type t = { absolute : Absolute . t ; relative : Relative . t } let empty compilation_unit = { absolute = Absolute . empty compilation_unit ; relative = Relative . empty } let inside_function absolute = { absolute ; relative = Relative . empty } let absolute {... |
type t = { arguments : Inlining_arguments . t ; depth : int } |
let increment_depth t = { t with depth = t . depth + 1 } |
let default ~ round = { arguments = Inlining_arguments . create ~ round ; depth = 0 } |
let create ~ arguments ~ depth = if depth < 0 then Misc . fatal_errorf " depth must be >= 0 : % d " depth ; { arguments ; depth } |
let [ @ ocamlformat " disable " ] print ppf t = Format . fprintf ppf " [ @< hov 1 ( > depth @ % d , arguments @ % a ) ] " @ t . depth Inlining_arguments . print t . arguments |
let depth t = t . depth |
let is_depth_exceeded t = t . depth >= Inlining_arguments . max_inlining_depth t . arguments |
let meet t1 t2 = { depth = t1 . depth + t2 . depth ; arguments = Inlining_arguments . meet t1 . arguments t2 . arguments } |
let equal t1 t2 = t1 . depth = t2 . depth && Inlining_arguments . equal t1 . arguments t2 . arguments |
let with_arguments arguments t = { t with arguments } |
let arguments t = t . arguments |
module Closure_stack = struct type t = node list and node = | Closure of Closure_id . t * Debuginfo . t | Call of Closure_id . t * Debuginfo . t | Inlined | Specialised of Closure_id . Set . t let create ( ) = [ ] let note_entering_closure t ~ closure_id ~ dbg = if not ! Clflags . in... |
let log : ( Closure_stack . t * Inlining_stats_types . Decision . t ) list ref = ref [ ] |
let record_decision decision ~ closure_stack = if ! Clflags . inlining_report then begin match closure_stack with | [ ] | Closure_stack . Closure _ :: _ | Closure_stack . Inlined :: _ | Closure_stack . Specialised _ :: _ -> Misc . fatal_errorf " record_decision : missing Call node " ... |
module Inlining_report = struct module Place = struct type kind = | Closure | Call type t = Debuginfo . t * Closure_id . t * kind let compare ( ( d1 , cl1 , k1 ) : t ) ( ( d2 , cl2 , k2 ) : t ) = let c = Debuginfo . compare d1 d2 in if c <> 0 then c else let c = Closure_id .... |
let really_save_then_forget_decisions ~ output_prefix = let report = Inlining_report . build ! log in let out_channel = open_out ( output_prefix ^ " . inlining . org " ) in let ppf = Format . formatter_of_out_channel out_channel in Inlining_report . print ppf report ; close_out out_channel ; ... |
let save_then_forget_decisions ~ output_prefix = if ! Clflags . inlining_report then begin really_save_then_forget_decisions ~ output_prefix end |
let print_stars ppf n = let s = String . make n ' ' * in Format . fprintf ppf " % s " s |
let print_calculation ~ depth ~ title ~ subfunctions ppf wsb = Format . pp_open_vbox ppf ( depth + 2 ) ; Format . fprintf ppf " [ @< h >% a % s ] ; ; [ @@@@% a ] " @ print_stars ( depth + 1 ) title ( Wsb . print_description ~ subfunctions ) wsb ; Format . pp_close_b... |
module Inlined = struct type t = | Classic_mode | Annotation | Decl_local_to_application | Without_subfunctions of Wsb . t | With_subfunctions of Wsb . t * Wsb . t let summary ppf = function | Classic_mode -> Format . pp_print_text ppf " This function was inlined because it was small enough \ to b... |
module Not_inlined = struct type t = | Classic_mode | Above_threshold of int | Annotation | No_useful_approximations | Unrolling_depth_exceeded | Self_call | Without_subfunctions of Wsb . t | With_subfunctions of Wsb . t * Wsb . t let summary ppf = function | Classic_mode -> Format . pp_print_text... |
module Specialised = struct type t = | Annotation | Without_subfunctions of Wsb . t | With_subfunctions of Wsb . t * Wsb . t let summary ppf = function | Annotation -> Format . pp_print_text ppf " This function was specialised because of an annotation . " | Without_subfunctions _ -> Format . ... |
module Not_specialised = struct type t = | Classic_mode | Above_threshold of int | Annotation | Not_recursive | Not_closed | No_invariant_parameters | No_useful_approximations | Self_call | Not_beneficial of Wsb . t * Wsb . t let summary ppf = function | Classic_mode -> Format . pp_print_text ppf "... |
module Prevented = struct type t = | Function_prevented_from_inlining | Level_exceeded let summary ppf = function | Function_prevented_from_inlining -> Format . pp_print_text ppf " This function was prevented from inlining or specialising . " | Level_exceeded -> Format . pp_print_text ppf " This fu... |
module Decision = struct type t = | Prevented of Prevented . t | Specialised of Specialised . t | Inlined of Not_specialised . t * Inlined . t | Unchanged of Not_specialised . t * Not_inlined . t let summary ppf = function | Prevented p -> Prevented . summary ppf p | Specialised s -> Speciali... |
let new_var name = Variable . create name ~ current_compilation_unit ( : Compilation_unit . get_current_exn ( ) ) |
let fold_over_projections_of_vars_bound_by_closure ~ closure_id_being_applied ~ lhs_of_application ~ bound_variables ~ init ~ f = Variable . Set . fold ( fun var acc -> let expr : Flambda . named = Project_var { closure = lhs_of_application ; closure_id = closure_id_being_applied ; var = Var_w... |
let set_inlined_attribute_on_all_apply body inlined specialise probe = Flambda_iterators . map_toplevel_expr ( function | Apply apply -> Apply { apply with inlined ; specialise ; probe } | expr -> expr ) body |
let copy_of_function ' s_body_with_freshened_params env ( ~ function_decl : A . function_declaration ) ( ~ function_body : A . function_body ) = let params = function_decl . params in let param_vars = Parameter . List . vars params in if E . does_not_bind env param_vars && E . does_not_f... |
let inline_by_copying_function_body ~ env ~ r ~ lhs_of_application ( ~ inlined_requested : Lambda . inlined_attribute ) ( ~ specialise_requested : Lambda . specialise_attribute ) ( ~ probe_requested : Lambda . probe ) ~ closure_id_being_applied ( ~ function_decl : A . function_declarat... |
type state = { old_inside_to_new_inside : Variable . t Variable . Map . t ; old_outside_to_new_outside : Variable . t Variable . Map . t ; old_params_to_new_outside : Variable . t Variable . Map . t ; old_fun_var_to_new_fun_var : Variable . t Variable . Map . t ; let_bindings : (... |
let empty_state = { to_copy = [ ] ; old_inside_to_new_inside = Variable . Map . empty ; old_outside_to_new_outside = Variable . Map . empty ; old_params_to_new_outside = Variable . Map . empty ; old_fun_var_to_new_fun_var = Variable . Map . empty ; let_bindings = [ ] ; new_f... |
let bind_free_vars ~ lhs_of_application ~ closure_id_being_applied ~ state ~ free_vars = Variable . Map . fold ( fun free_var ( spec : Flambda . specialised_to ) state -> let var_clos = new_var Internal_variable_names . from_closure in let expr : Flambda . named = Project_var { closure = lh... |
let register_arguments ~ specialised_args ~ invariant_params ~ state ~ params ~ args ~ args_approxs = let rec loop ~ state ~ params ~ args ~ args_approxs = match params , args , args_approxs with | [ ] , [ ] , [ ] -> state | param :: params , arg :: args , arg_approx :: args_ap... |
let add_param ~ specialised_args ~ state ~ param = let alloc_mode = Parameter . alloc_mode param in let param = Parameter . var param in let new_param = Variable . rename param in let old_inside_to_new_inside = Variable . Map . add param new_param state . old_inside_to_new_inside in let new_speciali... |
let add_fun_var ~ lhs_of_application ~ closure_id_being_applied ~ state ~ fun_var = if Variable . Map . mem fun_var state . old_inside_to_new_inside then state else begin let inside_var = Variable . rename fun_var in let outside_var = Variable . create Internal_variable_names . closure in let expr =... |
let add_free_var ~ free_vars ~ state ~ free_var = if Variable . Map . mem free_var state . old_inside_to_new_inside then state else begin let spec : Flambda . specialised_to = Variable . Map . find free_var free_vars in let outside_var = spec . var in let new_outside_var = Variable . Map . fin... |
let add_function ~ specialised_args ~ state ~ fun_var ~ function_decl = match function_decl . A . function_body with | None -> None | Some _ -> begin let rec loop worth_specialising = function | [ ] -> worth_specialising | param :: params -> begin let param = Parameter . var param in match Va... |
let lookup_function ~ specialised_args ~ state ~ fun_var ~ function_decl = match Variable . Map . find_opt fun_var state . old_fun_var_to_new_fun_var with | Some new_fun_var -> Some ( state , new_fun_var ) | None -> add_function ~ specialised_args ~ state ~ fun_var ~ function_decl |
let specialisable_call ~ specialised_args ~ state ~ args ~ params = List . for_all2 ( fun arg param -> let param = Parameter . var param in if Variable . Map . mem param specialised_args then true else begin let old_params_to_new_outside = state . old_params_to_new_outside in match Variable . Map ... |
let rec rewrite_direct_call ~ specialised_args ~ funs ~ direct_call_surrogates ~ state ~ closure_id ( ~ apply : Flambda . apply ) = match Closure_id . Map . find_opt closure_id direct_call_surrogates with | Some closure_id -> rewrite_direct_call ~ specialised_args ~ funs ~ direct_call_surrogates ... |
let rewrite_function ~ lhs_of_application ~ closure_id_being_applied ~ direct_call_surrogates ~ specialised_args ~ free_vars ~ funs ~ state fun_var = let function_decl : A . function_declaration = Variable . Map . find fun_var funs in let function_body = match function_decl . function_body with | No... |
let update_projections ~ state projections = let old_to_new = state . old_inside_to_new_inside in Variable . Map . map ( fun ( spec_to : Flambda . specialised_to ) -> let projection : Projection . t option = match spec_to . projection with | None -> None | Some ( Project_var proj ) -> b... |
let inline_by_copying_function_declaration ( ~ env : Inline_and_simplify_aux . Env . t ) ( ~ r : Inline_and_simplify_aux . Result . t ) ( ~ function_decls : A . function_declarations ) ( ~ lhs_of_application : Variable . t ) ( ~ inlined_requested : Lambda . inlined_attribute ) ... |
type ' a t = ' a Lwt . t |
type fd = { fd : Lwt_unix . file_descr ; mutable offset : int64 ; } |
let of_fd fd = let offset = 0L in { fd ; offset } |
let complete name offset op fd buffer = if false then Printf . fprintf stderr " % s offset =% s length =% d \ n " %! name ( match offset with Some x -> Int64 . to_string x | None -> " None " ) ( Cstruct . len buffer ) ; let open Lwt in let ofs = buffer . Cstruct . off in let len =... |
let read fd buf = complete " read " ( Some fd . offset ) Lwt_bytes . read fd . fd buf >>= fun ( ) -> fd . offset <- Int64 . ( add fd . offset ( of_int ( Cstruct . len buf ) ) ) ; Lwt . return_unit |
let skip_to fd n = let buf = Io_page . ( to_cstruct ( get 1 ) ) in let rec loop remaining = if remaining = 0L then Lwt . return_unit else let this = Int64 . ( to_int ( min remaining ( of_int ( Cstruct . len buf ) ) ) ) in let frag = Cstruct . sub buf 0 this in complete " ski... |
let active_files = ref ( [ ] : ( file_descr * ( ( io_channel -> unit ) * io_channel ) ) list ) |
let add_file file controller = active_files := ( file . io_fd , ( controller , file ) ) ::! active_files |
let remove_file file = active_files := List . remove_assoc file . io_fd ! active_files |
let change_controller file controller = remove_file file ; add_file file controller |
let current_controller file = fst ( List . assoc file . io_fd ! active_files ) |
let execute_with_other_controller controller file funct = let old_controller = current_controller file in change_controller file controller ; let finally ( ) = change_controller file old_controller in Fun . protect ~ finally funct |
let continue_main_loop = ref true |
let exit_main_loop _ = continue_main_loop := false |
let main_loop ( ) = let finally = let old_state = ! continue_main_loop in fun ( ) -> continue_main_loop := old_state in Fun . protect ~ finally @@ fun ( ) -> continue_main_loop := true ; while ! continue_main_loop do try let ( input , _ , _ ) = select ( List . map fst ! active... |
let interactif = ref true |
let current_prompt = ref " " |
let user_channel = ref std_io |
let read_user_input buffer length = main_loop ( ) ; input ! user_channel . io_in buffer 0 length |
let stop_user_input ( ) = remove_file ! user_channel |
let resume_user_input ( ) = if not ( List . mem_assoc ! user_channel . io_fd ! active_files ) then begin if ! interactif && ! Parameters . prompt then begin print_string ! current_prompt ; flush Stdlib . stdout end ; add_file ! user_channel exit_main_loop end |
module Make ( Structure : Structure . S ) = struct module Tools = Tools . Make Structure ; module Parser = Parser . Make Structure ; open Structure ; open Format ; open Sig . Grammar ; value is_before s1 s2 = match ( s1 , s2 ) with [ ( Skeyword _ | Stoken _ , Skeyword _ | Sto... |
let list_target_files_pred target pred = let build_dir = Dist . get_build_exn ( Dist . Target target . Target . target_name ) in Build . sanity_check build_dir target ; let matches = Ext . Filesystem . list_dir_pred pred build_dir in ( build_dir , matches ) |
let list_lib_files lib build_dir = list_target_files_pred lib ( fun f -> if ( fn_to_string f ) = " META " then true else match Filetype . of_filepath ( build_dir </> f ) with | Filetype . FileCMX | Filetype . FileCMI | Filetype . FileA | Filetype . FileCMXS | Filetype . FileCMXA | Fi... |
let list_exe_files lib build_dir = list_target_files_pred lib ( fun f -> match Filetype . of_filepath ( build_dir </> f ) with | Filetype . FileEXE -> true | _ -> false ) |
let opam_install_file proj_file flags = let install_path = fp ( proj_file . name ^ " . install " ) in Utils . generateFile install_path ( fun add -> let all_targets = Project . get_all_installable_targets proj_file flags in let print_target_files target list_files_fun = let build_dir = Dist . ... |
let lib_to_meta proj_file lib = let requires_of_lib lib = let deps = lib . Library . target . target_obits . target_builddeps in [ ( [ ] , List . map ( fun d -> fst d ) deps ) ] in let set_meta_field_from_lib pkg lib = { pkg with Meta . Pkg . requires = requires_of_lib lib ; Me... |
let write_lib_meta projFile lib = let dir = Dist . get_build_exn ( Dist . Target lib . Library . target . target_name ) in let metadir_path = dir </> fn " META " in let pkg = lib_to_meta projFile lib in Meta . Pkg . write metadir_path pkg |
let copy_files files dest_dir dir_name = List . iter ( fun ( build_dir , build_files ) -> List . iter ( fun build_file -> Ext . Filesystem . copy_file ( build_dir </> build_file ) ( ( dest_dir </> dir_name ) </> build_file ) ) build_files ; ) files |
let install_lib proj_file lib dest_dir = write_lib_meta proj_file lib ; let all_files = List . map ( fun target -> let build_dir = Dist . get_build_exn ( Dist . Target target . Target . target_name ) in Build . sanity_check build_dir target ; list_lib_files target build_dir ) ( Project . ... |
let install_libs proj_file destdir opam = if not opam then List . iter ( fun lib -> install_lib proj_file lib destdir ) proj_file . Project . libs else List . iter ( fun lib -> write_lib_meta proj_file lib ) proj_file . Project . libs ; |
let create ( ? lib = " work " ) ( ? arch = " rtl " ) ? instance ( ? parameters = [ ] ) ( ? attributes = [ ] ) ( ) ~ name ~ inputs ~ outputs = let width = List . fold outputs ~ init : 0 ~ f ( : fun a ( _ , i ) -> a + i ) in let deps = List . map in... |
module With_interface ( I : Interface . S_Of_signal ) ( O : Interface . S_Of_signal ) = struct let create ? lib ? arch ? instance ? parameters ? attributes ~ name inputs = I . Of_signal . validate inputs ; let inputs = List . map2_exn I . Names_and_widths . t ( I . to_list inputs ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.