text stringlengths 12 786k |
|---|
let resolve_variable ( aliases : Alias_analysis . allocation_point Variable . Map . t ) ( var_to_symbol_tbl : Symbol . t Variable . Tbl . t ) ( var_to_definition_tbl : Alias_analysis . constant_defining_value Variable . Tbl . t ) ( var : Variable . t ) : Flambda . constant_def... |
let translate_set_of_closures ( inconstants : Inconstant_idents . result ) ( aliases : Alias_analysis . allocation_point Variable . Map . t ) ( var_to_symbol_tbl : Symbol . t Variable . Tbl . t ) ( var_to_definition_tbl : Alias_analysis . constant_defining_value Variable . Tbl . t ... |
let translate_constant_set_of_closures ( inconstants : Inconstant_idents . result ) ( aliases : Alias_analysis . allocation_point Variable . Map . t ) ( var_to_symbol_tbl : Symbol . t Variable . Tbl . t ) ( var_to_definition_tbl : Alias_analysis . constant_defining_value Variable . T... |
let find_original_set_of_closure ( aliases : Alias_analysis . allocation_point Variable . Map . t ) ( var_to_symbol_tbl : Symbol . t Variable . Tbl . t ) ( var_to_definition_tbl : Alias_analysis . constant_defining_value Variable . Tbl . t ) project_closure_map var = let rec loop var ... |
let translate_definition_and_resolve_alias inconstants ( aliases : Alias_analysis . allocation_point Variable . Map . t ) ( var_to_symbol_tbl : Symbol . t Variable . Tbl . t ) ( var_to_definition_tbl : Alias_analysis . constant_defining_value Variable . Tbl . t ) ( symbol_definition_m... |
let translate_definitions_and_resolve_alias inconstants ( aliases : Alias_analysis . allocation_point Variable . Map . t ) ( var_to_symbol_tbl : Symbol . t Variable . Tbl . t ) ( var_to_definition_tbl : Alias_analysis . constant_defining_value Variable . Tbl . t ) symbol_definition_map ... |
let constant_dependencies ~ backend : _ ( const : Flambda . constant_defining_value ) = match const with | Allocated_const _ -> Symbol . Set . empty | Block ( _ , fields ) -> let symbol_fields = List . filter_map ( function | ( Symbol s : Flambda . constant_defining_value_block_fie... |
module Symbol_SCC = Strongly_connected_components . Make ( Symbol ) |
let program_graph ~ backend imported_symbols symbol_to_constant ( initialize_symbol_tbl : ( Tag . t * Flambda . t list * Symbol . t option ) Symbol . Tbl . t ) ( effect_tbl : ( Flambda . t * Symbol . t option ) Symbol . Tbl . t ) = let expression_symbol_dependencies expr = Flam... |
let add_definition_of_symbol constant_definitions ( initialize_symbol_tbl : ( Tag . t * Flambda . t list * Symbol . t option ) Symbol . Tbl . t ) ( effect_tbl : ( Flambda . t * Symbol . t option ) Symbol . Tbl . t ) ( program : Flambda . program_body ) component : Flambda ... |
let add_definitions_of_symbols constant_definitions initialize_symbol_tbl effect_tbl program components = Array . fold_left ( add_definition_of_symbol constant_definitions initialize_symbol_tbl effect_tbl ) program components |
let introduce_free_variables_in_set_of_closures ( var_to_block_field_tbl : Flambda . constant_defining_value_block_field Variable . Tbl . t ) ( { Flambda . function_decls ; free_vars ; specialised_args ; direct_call_surrogates ; } as set_of_closures ) = let add_definition_and_make_substitu... |
let rewrite_project_var ( var_to_block_field_tbl : Flambda . constant_defining_value_block_field Variable . Tbl . t ) ( project_var : Flambda . project_var ) ~ original : Flambda . named = let var = Var_within_closure . unwrap project_var . var in match Variable . Tbl . find var_to_block... |
let introduce_free_variables_in_sets_of_closures ( var_to_block_field_tbl : Flambda . constant_defining_value_block_field Variable . Tbl . t ) ( translate_definition : Flambda . constant_defining_value Symbol . Map . t ) = Symbol . Map . map ( fun ( def : Flambda . constant_defining_va... |
let var_to_block_field ( aliases : Alias_analysis . allocation_point Variable . Map . t ) ( var_to_symbol_tbl : Symbol . t Variable . Tbl . t ) ( var_to_definition_tbl : Alias_analysis . constant_defining_value Variable . Tbl . t ) = let var_to_block_field_tbl = Variable . Tbl . c... |
let program_symbols ~ backend ( program : Flambda . program ) = let new_fake_symbol ( ) = let var = Variable . create Internal_variable_names . fake_effect_symbol in Symbol . of_variable var in let initialize_symbol_tbl = Symbol . Tbl . create 42 in let effect_tbl = Symbol . Tbl . create... |
let replace_definitions_in_initialize_symbol_and_effects ( inconstants : Inconstant_idents . result ) ( aliases : Alias_analysis . allocation_point Variable . Map . t ) ( var_to_symbol_tbl : Symbol . t Variable . Tbl . t ) ( var_to_definition_tbl : Alias_analysis . constant_defining_va... |
let project_closure_map symbol_definition_map = Symbol . Map . fold ( fun sym ( const : Flambda . constant_defining_value ) acc -> match const with | Project_closure ( set_of_closures , _ ) -> Symbol . Map . add sym set_of_closures acc | Set_of_closures _ -> Symbol . Map . add sym sym... |
let lift_constants ( program : Flambda . program ) ~ backend = let the_dead_constant = let var = Variable . create Internal_variable_names . the_dead_constant in Symbol . of_variable var in let program_body : Flambda . program_body = Let_symbol ( the_dead_constant , Allocated_const ( Nativein... |
type ( ' a , ' b ) kind = | Initialisation of ( Symbol . t * Tag . t * Flambda . t list ) | Effect of ' b |
let should_copy ( named : Flambda . named ) = match named with | Symbol _ | Read_symbol_field _ | Const _ -> true | _ -> false |
type extracted = | Expr of Variable . t * Flambda . t | Exprs of Variable . t list * Flambda . t | Block of Variable . t * Tag . t * Variable . t list |
type accumulated = { copied_lets : ( Variable . t * Flambda . named ) list ; extracted_lets : extracted list ; terminator : Flambda . expr ; } |
let rec accumulate ~ substitution ~ copied_lets ~ extracted_lets ( expr : Flambda . t ) = match expr with | Let { var ; body = Var var ' ; _ } | Let_rec ( [ var , _ ] , Var var ' ) when Variable . equal var var ' -> { copied_lets ; extracted_lets ; terminator = Flambd... |
let rebuild_expr ( ~ extracted_definitions : ( Symbol . t * int list ) Variable . Map . t ) ( ~ copied_definitions : Flambda . named Variable . Map . t ) ( ~ substitute : bool ) ( expr : Flambda . t ) = let expr_with_read_symbols = Flambda_utils . substitute_read_symbol_fie... |
let rebuild ( used_variables : Variable . Set . t ) ( accumulated : accumulated ) = let copied_definitions = Variable . Map . of_list accumulated . copied_lets in let accumulated_extracted_lets = List . map ( fun decl -> match decl with | Block ( var , _ , _ ) | Expr ( var , ... |
let introduce_symbols expr = let accumulated = accumulate expr ~ substitution : Variable . Map . empty ~ copied_lets [ ] : ~ extracted_lets [ ] : in let used_variables = Flambda . used_variables expr in let extracted , terminator = rebuild used_variables accumulated in extracted , terminator |
let add_extracted introduced program = List . fold_right ( fun extracted program -> match extracted with | Initialisation ( symbol , tag , def ) -> Flambda . Initialize_symbol ( symbol , tag , def , program ) | Effect effect -> Flambda . Effect ( effect , program ) ) introduced p... |
let rec split_program ( program : Flambda . program_body ) : Flambda . program_body = match program with | End s -> End s | Let_symbol ( s , def , program ) -> Let_symbol ( s , def , split_program program ) | Let_rec_symbol ( defs , program ) -> Let_rec_symbol ( defs , split_p... |
let lift ~ backend : _ ( program : Flambda . program ) = { program with program_body = split_program program . program_body ; } |
type instruction = { mutable desc : instruction_desc ; mutable next : instruction ; arg : Reg . t array ; res : Reg . t array ; dbg : Debuginfo . t ; live : Reg . Set . t } | Lprologue | Lend | Lop of Mach . operation | Lreloadretaddr | Lreturn | Llabel of label | Lbranch of labe... |
let has_fallthrough = function | Lreturn | Lbranch _ | Lswitch _ | Lraise _ | Lop Itailcall_ind | Lop ( Itailcall_imm _ ) -> false | _ -> true |
type fundecl = { fun_name : string ; fun_body : instruction ; fun_fast : bool ; fun_dbg : Debuginfo . t ; fun_tailrec_entry_point_label : label ; fun_contains_calls : bool ; fun_num_stack_slots : int array ; fun_frame_required : bool ; fun_prologue_required : bool ; } |
let invert_integer_test = function Isigned cmp -> Isigned ( Cmm . negate_integer_comparison cmp ) | Iunsigned cmp -> Iunsigned ( Cmm . negate_integer_comparison cmp ) |
let invert_test = function Itruetest -> Ifalsetest | Ifalsetest -> Itruetest | Iinttest ( cmp ) -> Iinttest ( invert_integer_test cmp ) | Iinttest_imm ( cmp , n ) -> Iinttest_imm ( invert_integer_test cmp , n ) | Ifloattest ( cmp ) -> Ifloattest ( Cmm . negate_float_comparison cmp ... |
let rec end_instr = { desc = Lend ; next = end_instr ; arg = [ ] ; || res = [ ] ; || dbg = Debuginfo . none ; live = Reg . Set . empty } |
let instr_cons d a r n = { desc = d ; next = n ; arg = a ; res = r ; dbg = Debuginfo . none ; live = Reg . Set . empty } |
let cons_instr d n = { desc = d ; next = n ; arg = [ ] ; || res = [ ] ; || dbg = Debuginfo . none ; live = Reg . Set . empty } |
let copy_instr d i n = { desc = d ; next = n ; arg = i . Mach . arg ; res = i . Mach . res ; dbg = i . Mach . dbg ; live = i . Mach . live } |
let get_label n = match n . desc with Lbranch lbl -> ( lbl , n ) | Llabel lbl -> ( lbl , n ) | Lend -> ( - 1 , n ) | _ -> let lbl = Cmm . new_label ( ) in ( lbl , cons_instr ( Llabel lbl ) n ) |
let check_label n = match n . desc with | Lbranch lbl -> lbl | Llabel lbl -> lbl | _ -> - 1 |
let rec adjust_trap_depth delta_traps next = match next . desc with | Ladjust_trap_depth { delta_traps = k } -> adjust_trap_depth ( delta_traps + k ) next . next | _ -> if delta_traps = 0 then next else cons_instr ( Ladjust_trap_depth { delta_traps } ) next |
let rec discard_dead_code n = let adjust trap_depth = adjust_trap_depth trap_depth ( discard_dead_code n . next ) in match n . desc with Lend -> n | Llabel _ -> n | Lpoptrap -> adjust ( - 1 ) | Lpushtrap _ -> adjust ( + 1 ) | Ladjust_trap_depth { delta_traps } -> adjust delta_traps ... |
let add_branch lbl n = if lbl >= 0 then let n1 = discard_dead_code n in match n1 . desc with | Llabel lbl1 when lbl1 = lbl -> n1 | _ -> cons_instr ( Lbranch lbl ) n1 else discard_dead_code n |
let try_depth = ref 0 |
let exit_label = ref [ ] |
let find_exit_label_try_depth k = try List . assoc k ! exit_label with | Not_found -> Misc . fatal_error " Linearize . find_exit_label " |
let find_exit_label k = let ( label , t ) = find_exit_label_try_depth k in assert ( t = ! try_depth ) ; label |
let is_next_catch n = match ! exit_label with |
let local_exit k = snd ( find_exit_label_try_depth k ) = ! try_depth |
let linear i n contains_calls = let rec linear i n = match i . Mach . desc with Iend -> n | Iop ( Itailcall_ind | Itailcall_imm _ as op ) -> copy_instr ( Lop op ) i ( discard_dead_code n ) | Iop ( Imove | Ireload | Ispill ) when i . Mach . arg . ( 0 ) . loc = i . Mach . r... |
let add_prologue first_insn prologue_required = let rec skip_naming_ops ( insn : instruction ) : label * instruction = match insn . desc with | Lop ( Iname_for_debugger _ ) -> let tailrec_entry_point_label , next = skip_naming_ops insn . next in tailrec_entry_point_label , { insn with next ; ... |
let fundecl f = let fun_prologue_required = Proc . prologue_required f in let contains_calls = f . Mach . fun_contains_calls in let fun_tailrec_entry_point_label , fun_body = add_prologue ( linear f . Mach . fun_body end_instr contains_calls ) fun_prologue_required in { fun_name = f . Mach . ... |
type linear_item_info = | Func of Linear . fundecl | Data of Cmm . data_item list |
type linear_unit_info = { mutable unit_name : string ; mutable items : linear_item_info list ; mutable for_pack : string option } |
type error = | Wrong_format of string | Wrong_version of string | Corrupted of string | Marshal_failed of string |
let save filename linear_unit_info = let ch = open_out_bin filename in Misc . try_finally ( fun ( ) -> output_string ch Config . linear_magic_number ; output_value ch linear_unit_info ; output_value ch ( Cmm . cur_label ( ) ) ; flush ch ; let crc = Digest . file filename in output_valu... |
let restore filename = let ic = open_in_bin filename in Misc . try_finally ( fun ( ) -> let magic = Config . linear_magic_number in let buffer = really_input_string ic ( String . length magic ) in if String . equal buffer magic then begin try let linear_unit_info = ( input_value ic : linear_u... |
let report_error ppf = function | Wrong_format filename -> fprintf ppf " Expected Linear format . Incompatible file % a " Location . print_filename filename | Wrong_version filename -> fprintf ppf " % a @ is not compatible with this version of OCaml " Location . print_filename filename | Corrupte... |
let ( ) = Location . register_error_of_exn ( function | Error err -> Some ( Location . error_of_printer_file report_error err ) | _ -> None ) |
module T = Trap_stack . Make ( Label ) |
type t = { cfg : Cfg . t ; mutable layout : Label . t list ; mutable new_labels : Label . Set . t ; mutable trap_handlers : Label . Set . t ; trap_stacks : T . t Label . Tbl . t ; exns : T . t Label . Tbl . t ; interproc_handler : Label . t ; mutable unresolved_traps_to... |
let create cfg ~ tailrec_label = { cfg ; layout = [ ] ; new_labels = Label . Set . empty ; trap_handlers = Label . Set . empty ; trap_stacks = Label . Tbl . create 31 ; exns = Label . Tbl . create 31 ; interproc_handler = - 1 ; unresolved_traps_to_pop = [ ] ; next_... |
let get_new_linear_id t = let id = t . next_linear_id in t . next_linear_id <- id + 1 ; id |
let create_instruction t desc ~ stack_offset ( i : Linear . instruction ) : _ C . instruction = { desc ; arg = i . arg ; res = i . res ; dbg = i . dbg ; fdo = i . fdo ; live = i . live ; stack_offset ; id = get_new_linear_id t } |
let record_traps t label traps = match Label . Tbl . find_opt t . trap_stacks label with | None -> Label . Tbl . add t . trap_stacks label traps | Some existing_traps -> if ! C . verbose then T . print_pair ( Printf . sprintf " Unify at % d " label ) traps existing_traps ; T . unify... |
let resolve_traps_to_pop t ls = let rec loop prev = let progress = ref false in let curr = List . fold_left ( fun acc traps -> match T . top_exn traps with | None -> Misc . fatal_errorf " resolve_traps_to_pop : Illegal trap stack " | Some top -> progress := true ; record_traps t top ( T . p... |
let record_exn t ( block : C . basic_block ) traps = block . can_raise <- true ; match Label . Tbl . find_opt t . exns block . start with | None -> Label . Tbl . add t . exns block . start traps | Some _ -> Misc . fatal_errorf " Cannot record another exception for % d " block . ... |
let create_empty_block t start ~ stack_offset ~ traps = let terminator : C . terminator C . instruction = { desc = C . Never ; arg = [ ] ; || res = [ ] ; || dbg = Debuginfo . none ; fdo = Fdo_info . none ; live = Reg . Set . empty ; stack_offset ; id = get_new_linear_... |
let register_block t ( block : C . basic_block ) traps = if Label . Tbl . mem t . cfg . blocks block . start then Misc . fatal_errorf " A block with starting label % d is already registered " block . start ; if ! C . verbose then Printf . printf " registering block % d \ n " bloc... |
let check_traps t label ( block : C . basic_block ) = match Label . Tbl . find_opt t . trap_stacks label with | None -> ( ) | Some trap_stack_at_start -> ( if ! C . verbose then ( Printf . printf " % s : check_trap at % d : " t . cfg . fun_name label ; T . print trap_stack... |
let register_exns t label ( block : C . basic_block ) = match Label . Tbl . find_opt t . exns label with | None -> ( ) | Some trap_stack -> assert ( Option . is_none block . exn ) ; ( match T . top_exn trap_stack with | None -> Misc . fatal_errorf " register_exns : empty trap ... |
let check_and_register_traps t = Label . Set . iter ( fun label -> let trap_block = C . get_block_exn t . cfg label in if not trap_block . is_trap_handler then Misc . fatal_errorf " Label % d used as a handler in Lpushtrap , but the block at % d does \ not start \ n \ \ with an Lentertrap ins... |
let get_or_make_label t ( insn : Linear . instruction ) : Linear_utils . labelled_insn = match insn . desc with | Llabel label -> { label ; insn } | Lend -> Misc . fatal_error " Unexpected end of function instead of label " | Lprologue | Lop _ | Lreloadretaddr | Lreturn | Lbranch _ ... |
let of_cmm_float_test ~ lbl ~ inv ( cmp : Cmm . float_comparison ) : C . float_test = match cmp with | CFeq -> { eq = lbl ; lt = inv ; gt = inv ; uo = inv } | CFlt -> { eq = inv ; lt = lbl ; gt = inv ; uo = inv } | CFgt -> { eq = inv ; lt = inv ; gt = lbl ; uo ... |
let of_cmm_int_test ~ lbl ~ inv ~ is_signed ~ imm ( cmp : Cmm . integer_comparison ) : C . int_test = match cmp with | Ceq -> { eq = lbl ; lt = inv ; gt = inv ; is_signed ; imm } | Clt -> { eq = inv ; lt = lbl ; gt = inv ; is_signed ; imm } | Cgt -> { eq = inv ; l... |
let mk_int_test ~ lbl ~ inv ~ imm ( cmp : Mach . integer_comparison ) : C . int_test = match cmp with | Isigned cmp -> of_cmm_int_test ~ lbl ~ inv cmp ~ is_signed : true ~ imm | Iunsigned cmp -> of_cmm_int_test ~ lbl ~ inv cmp ~ is_signed : false ~ imm |
let block_is_registered t ( block : C . basic_block ) = Label . Tbl . mem t . cfg . blocks block . start |
let add_terminator t ( block : C . basic_block ) ( i : L . instruction ) ( desc : C . terminator ) ~ stack_offset ~ traps = ( match desc with | Never -> Misc . fatal_error " Cannot add terminator : Never " | Always _ | Parity_test _ | Truth_test _ | Float_test _ | Int_test _ ... |
let to_basic ( mop : Mach . operation ) : C . basic = match mop with | Icall_ind -> Call ( F Indirect ) | Icall_imm { func } -> Call ( F ( Direct { func_symbol = func } ) ) | Iextcall { func ; alloc ; ty_args ; ty_res ; returns = true } -> Call ( P ( External { f... |
let rec adjust_traps ( i : L . instruction ) ~ stack_offset ~ traps = match i . desc with | Ladjust_stack_offset { delta_bytes } -> let stack_offset = stack_offset + delta_bytes in if stack_offset < 0 then Misc . fatal_errorf " Ladjust_stack_offset % d moves the trap depth below zero : % d ... |
let rec create_blocks ( t : t ) ( i : L . instruction ) ( block : C . basic_block ) ~ stack_offset ~ traps = let stack_offset , traps , i = adjust_traps i ~ stack_offset ~ traps in match i . desc with | Ladjust_stack_offset _ -> assert false | Lend -> if not ( block_is_registered t... |
let run ( f : Linear . fundecl ) ~ preserve_orig_labels = let t = let cfg = Cfg . create ~ fun_name : f . fun_name ~ fun_args [ ] :|| ~ fun_dbg : f . fun_dbg ~ fun_fast : f . fun_fast ~ fun_contains_calls : f . fun_contains_calls ~ fun_num_stack_slots : f . fun_num_stack_slots in ... |
type t = { mutable buffer : bytes ; mutable position : int ; mutable length : int ; mutable last : string ; mutable last_len : int ; ppf : Format . formatter Lazy . t } |
let resize t more = let old_pos = t . position and old_len = t . length in let new_len = let res = ref old_len in while old_pos + more > ! res do res := 2 * ! res done ; ! res in let new_buffer = Bytes . create new_len in Bytes . blit ~ src : t . buffer ~ src_pos : 0 ~ dst : new_buffer ... |
let advance t len = let new_position = t . position + len in if new_position > t . length then resize t len ; t . position <- new_position |
let lift_write ~ len ~ write = Staged . inj ( fun t x -> let position = t . position in advance t len ; write x ~ into : t . buffer ~ pos : position ) |
let add_char b c = let pos = b . position in if pos >= b . length then resize b 1 ; Bytes . unsafe_set b . buffer pos c ; b . position <- pos + 1 |
let add_substring t s ~ off ~ len = if off < 0 || len < 0 || off > String . length s - len then invalid_arg " Line_buffer . add_substring " ; let position = t . position in advance t len ; unsafe_blit_string s off t . buffer position len |
let add_string b s = let len = String . length s in let new_position = b . position + len in if new_position > b . length then resize b len ; unsafe_blit_string s 0 b . buffer b . position len ; b . position <- new_position |
let add_line_buffer ~ dst ~ src = let position = dst . position in let len = src . position in advance dst len ; Bytes . unsafe_blit ~ src : src . buffer ~ src_pos : 0 ~ dst : dst . buffer ~ dst_pos : position ~ len |
let create ~ size = let buffer = Bytes . create size in let rec ppf = lazy ( let ppf = Format . make_formatter ( fun s off len -> add_substring t s ~ off ~ len ) ( fun ( ) -> ( ) ) in Fmt . set_style_renderer ppf ` Ansi_tty ; ppf ) and t = { buffer ; position = 0 ; length... |
let with_ppf t f = let ppf = Lazy . force t . ppf in let a = f ppf in Format . pp_print_flush ppf ( ) ; a |
let reset t = t . position <- 0 |
let contents t = let last = t . last in let last_len = t . last_len in let current_len = t . position in let current = Bytes . sub_string t . buffer ~ pos : 0 ~ len : current_len in reset t ; match Int . equal last_len current_len && String . equal last current with | true -> ` Clean t . ... |
let current_position t = t . position |
module Span = struct type t = { pos : int ; len : int } let pp ppf t = Fmt . pf ppf " { pos = % d ; len = % d } " t . pos t . len let empty = { pos = 0 ; len = 0 } let between_marks a b = { pos = a ; len = b - a } end |
let skip t ( span : Span . t ) = advance t span . len |
module type Integer_dependent = sig type integer type color type duration type ' a printer type bar_style type ' a t val sum : ? pp : integer printer -> width : int -> unit -> integer t val count_to : ? pp : integer printer -> ? sep : unit t -> integer -> integer t val bytes : integer t val bytes_p... |
module type DSL = sig type integer type color type duration type ' a printer type ' a t val const : string -> _ t val constf : ( ' a , Format . formatter , unit , _ t ) format4 -> ' a val string : string t val lpad : int -> ' a t -> ' a t val rpad : int -> ' a t -> ' a t val of... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.