aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJustus Fasse <justus.fasse@etu.univ-grenoble-alpes.fr>2021-08-02 15:15:27 +0200
committerJustus Fasse <justus.fasse@etu.univ-grenoble-alpes.fr>2021-08-02 15:15:27 +0200
commit5efd95e03b8a8101dd971a01543e23aefbb07eb3 (patch)
treedd7c49e7eae0967a204e7fc91a782ae50395551e
parent30a5d94a20a05d2f1a86f0cb66499e00a35073ea (diff)
downloadcompcert-kvx-5efd95e03b8a8101dd971a01543e23aefbb07eb3.tar.gz
compcert-kvx-5efd95e03b8a8101dd971a01543e23aefbb07eb3.zip
Alias less registers
-rw-r--r--scheduling/MyRTLpathScheduleraux.ml43
1 files changed, 38 insertions, 5 deletions
diff --git a/scheduling/MyRTLpathScheduleraux.ml b/scheduling/MyRTLpathScheduleraux.ml
index 2fb72d78..23d5d339 100644
--- a/scheduling/MyRTLpathScheduleraux.ml
+++ b/scheduling/MyRTLpathScheduleraux.ml
@@ -372,7 +372,11 @@ let restoration_instructions live_renames =
in
to_insert
-let restoration_instructions' live_renames ~next_free_reg =
+type restoration_actions =
+ | Just_restore of renamed
+ | Restore_and_alias of renamed
+
+let restoration_instructions' sb code live_renames ~next_free_reg =
let next_free_reg =
let next_free_reg = ref next_free_reg in
(fun () ->
@@ -381,9 +385,35 @@ let restoration_instructions' live_renames ~next_free_reg =
r )
in
+ let length = Array.length sb.instructions in
+ let pc_to_idx =
+ Duplicateaux.generate_fwmap
+ (Array.to_list sb.instructions)
+ (List.init length (fun i -> i))
+ PTree.empty
+ in
+
+ let live_renames = PTree.map
+ (fun pc renames ->
+ let offset = apply_map' pc_to_idx pc in
+ List.map
+ (fun rename ->
+ let {old_name; new_name} = rename in
+ if used_before_redefinition sb code ~offset ~reg:old_name then
+ Restore_and_alias rename
+ else
+ Just_restore rename)
+ renames)
+ live_renames
+ in
+
let to_rename = PTree.map1
(fun renames ->
- let old_names = List.map (fun {old_name; new_name} -> old_name) renames in
+ let old_names = List.filter_map (fun rename ->
+ match rename with
+ | Just_restore _ -> None
+ | Restore_and_alias {old_name; new_name} -> Some old_name) renames
+ in
let aliases = List.init (List.length old_names) (fun _ -> next_free_reg ()) in
let fwmap = Duplicateaux.generate_fwmap old_names aliases PTree.empty in
fwmap
@@ -396,9 +426,12 @@ let restoration_instructions' live_renames ~next_free_reg =
(fun to_insert side_exit_pc renames ->
let alias_map = get_some @@ PTree.get side_exit_pc to_rename in
let insts = ListLabels.map renames
- ~f:(fun {old_name; new_name} ->
- [ Iop (Op.Omove, [old_name], (apply_map' alias_map old_name), Camlcoq.P.one)
- ; Iop (Op.Omove, [new_name], old_name, Camlcoq.P.one)])
+ ~f:(fun rename ->
+ match rename with
+ | Just_restore {old_name; new_name} -> [Iop (Op.Omove, [new_name], old_name, Camlcoq.P.one)]
+ | Restore_and_alias {old_name; new_name} ->
+ [ Iop (Op.Omove, [old_name], apply_map' alias_map old_name, Camlcoq.P.one)
+ ; Iop (Op.Omove, [new_name], old_name, Camlcoq.P.one)] )
in
let insts = List.flatten insts in
InsertPositionMap.add (InsertPosition.Above side_exit_pc) insts to_insert)