diff options
author | Cyril SIX <cyril.six@kalray.eu> | 2020-10-09 15:51:33 +0200 |
---|---|---|
committer | Cyril SIX <cyril.six@kalray.eu> | 2020-10-09 15:51:33 +0200 |
commit | b22f1165b23be33da6cb7f6ac681c14abec37c23 (patch) | |
tree | 284967da076b559ff63b39423672b591783792c9 | |
parent | 3009ec015ab7261323c9e318cb703eaabca07d47 (diff) | |
download | compcert-kvx-b22f1165b23be33da6cb7f6ac681c14abec37c23.tar.gz compcert-kvx-b22f1165b23be33da6cb7f6ac681c14abec37c23.zip |
new flags: -fpredict, -ftailduplicate n, -funrollsingle n instead of just -fduplicate n
-rw-r--r-- | backend/Duplicateaux.ml | 77 | ||||
-rw-r--r-- | driver/Clflags.ml | 10 | ||||
-rw-r--r-- | driver/Driver.ml | 5 |
3 files changed, 53 insertions, 39 deletions
diff --git a/backend/Duplicateaux.ml b/backend/Duplicateaux.ml index 4eeb22cf..833bc803 100644 --- a/backend/Duplicateaux.ml +++ b/backend/Duplicateaux.ml @@ -584,7 +584,7 @@ let tail_duplicate code preds ptree trace = in (new_code, new_ptree, !nb_duplicated) let superblockify_traces code preds traces ptree = - let max_nb_duplicated = !Clflags.option_fduplicate (* FIXME - should be architecture dependent *) + let max_nb_duplicated = !Clflags.option_ftailduplicate (* FIXME - should be architecture dependent *) in let rec f code ptree = function | [] -> (code, ptree, 0) | trace :: traces -> @@ -595,25 +595,16 @@ let superblockify_traces code preds traces ptree = in let new_code, new_ptree, _ = f code ptree traces in (new_code, new_ptree) -let rec invert_iconds_trace code = function - | [] -> code - | n :: ln -> - let code' = match ptree_get_some n code with - | Icond (c, lr, ifso, ifnot, info) -> (match info with - | Some true -> begin - (* debug "Reversing ifso/ifnot for node %d\n" (P.to_int n); *) - PTree.set n (Icond (Op.negate_condition c, lr, ifnot, ifso, Some false)) code - end - | _ -> code) - | _ -> code - in invert_iconds_trace code' ln - -let rec invert_iconds code = function - | [] -> code - | t :: ts -> - let code' = if !Clflags.option_finvertcond then invert_iconds_trace code t - else code - in invert_iconds code' ts +let invert_iconds code = + PTree.map1 (fun i -> match i with + | Icond (c, lr, ifso, ifnot, info) -> (match info with + | Some true -> begin + (* debug "Reversing ifso/ifnot for node %d\n" (P.to_int n); *) + Icond (Op.negate_condition c, lr, ifnot, ifso, Some false) + end + | _ -> i) + | _ -> i + ) code (** Partial loop unrolling * @@ -775,7 +766,7 @@ let unroll_inner_loop_single code revmap iloop = (* code' := PTree.set last_n' (change_single_next first_n @@ ptree_get_some last_n' !code') !code' *) (!code', revmap2) end - + let unroll_inner_loops_single f code revmap = let is_loop_header = get_loop_headers code (f.fn_entrypoint) in let inner_loops = get_inner_loops f code is_loop_header in @@ -791,17 +782,35 @@ let unroll_inner_loops_single f code revmap = end let duplicate_aux f = + (* initializing *) let entrypoint = f.fn_entrypoint in - if !Clflags.option_fduplicate < 0 then - ((f.fn_code, entrypoint), make_identity_ptree f.fn_code) - else - let code = update_directions f.fn_code entrypoint in - let (code', revmap) = unroll_inner_loops_single f code (make_identity_ptree code) in - let traces = select_traces code' entrypoint in - let icond_code = invert_iconds code' traces in - let preds = get_predecessors_rtl icond_code in - if !Clflags.option_fduplicate >= 1 then - let (new_code, pTreeId) = superblockify_traces icond_code preds traces revmap in - ((new_code, entrypoint), pTreeId) - else - ((icond_code, entrypoint), revmap) + let code = f.fn_code in + let revmap = make_identity_ptree code in + + (* static prediction *) + let code = + if !Clflags.option_fpredict then + update_directions code entrypoint + else code in + + (* unroll single *) + let (code, revmap) = + if !Clflags.option_funrollsingle > 0 then + unroll_inner_loops_single f code revmap + else (code, revmap) in + + (* static prediction bis *) + let code = + if !Clflags.option_fpredict then + invert_iconds code + else code in + + (* tail duplication *) + let (code, revmap) = + if !Clflags.option_ftailduplicate > 0 then + let traces = select_traces code entrypoint in + let preds = get_predecessors_rtl code in + superblockify_traces code preds traces revmap + else (code, revmap) in + + ((code, entrypoint), revmap) diff --git a/driver/Clflags.ml b/driver/Clflags.ml index eb21b3f8..8bc7a938 100644 --- a/driver/Clflags.ml +++ b/driver/Clflags.ml @@ -33,9 +33,13 @@ let option_fcse3_across_calls = ref false let option_fcse3_across_merges = ref true let option_fcse3_glb = ref true let option_fredundancy = ref true -let option_fduplicate = ref (-1) -let option_finvertcond = ref true -let option_ftracelinearize = ref false + +(** Options relative to superblock scheduling *) +let option_fpredict = ref true (* insert static branch prediction information, and swaps ifso/ifnot branches accordingly *) +let option_ftailduplicate = ref 0 (* perform tail duplication for blocks of size n *) +let option_ftracelinearize = ref true (* uses branch prediction information to improve the linearization *) +let option_funrollsingle = ref 0 (* unroll a single iteration of innermost loops of size n *) + let option_fpostpass = ref true let option_fpostpass_sched = ref "list" let option_fifconversion = ref true diff --git a/driver/Driver.ml b/driver/Driver.ml index 90afb812..b0b1cdea 100644 --- a/driver/Driver.ml +++ b/driver/Driver.ml @@ -420,8 +420,9 @@ let cmdline_actions = @ f_opt "move-loop-invariants" option_fmove_loop_invariants @ f_opt "redundancy" option_fredundancy @ f_opt "postpass" option_fpostpass - @ [ Exact "-fduplicate", Integer (fun n -> option_fduplicate := n) ] - @ f_opt "invertcond" option_finvertcond + @ [ Exact "-ftailduplicate", Integer (fun n -> option_ftailduplicate := n) ] + @ f_opt "predict" option_fpredict + @ [ Exact "-funrollsingle", Integer (fun n -> option_funrollsingle := n) ] @ f_opt "tracelinearize" option_ftracelinearize @ f_opt_str "postpass" option_fpostpass option_fpostpass_sched @ f_opt "inline" option_finline |