diff options
-rw-r--r-- | scheduling/MyRTLpathScheduleraux.ml | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/scheduling/MyRTLpathScheduleraux.ml b/scheduling/MyRTLpathScheduleraux.ml index 212867f4..547019a9 100644 --- a/scheduling/MyRTLpathScheduleraux.ml +++ b/scheduling/MyRTLpathScheduleraux.ml @@ -392,19 +392,25 @@ let restoration_instructions sb code live_renames = | Icond _ -> false | _ -> true in + let open Either in let to_insert = PTree.fold (fun to_insert side_exit_pc renames -> - let insts = ListLabels.map renames - ~f:(fun {old_name; new_name} -> - Iop (Op.Omove, [new_name], old_name, Camlcoq.P.one)) - in - let pos = if last_inst_is_basic - then InsertPosition.Below side_exit_pc - else InsertPosition.Above side_exit_pc - in - - InsertPositionMap.add pos insts to_insert) + let live_regs_opt = PTree.get side_exit_pc sb.liveins in + let (above, below) = + ListLabels.partition_map renames + ~f:(fun {old_name; new_name} -> + let inst = Iop (Op.Omove, [new_name], old_name, Camlcoq.P.one) in + match last_inst_is_basic, live_regs_opt with + | true, _ -> Right inst + | false, None -> Left inst + | false, Some live_regs -> + if Regset.mem old_name live_regs then + Left inst + else Right inst) + in + InsertPositionMap.add (InsertPosition.Above side_exit_pc) above to_insert + |> InsertPositionMap.add (InsertPosition.Below side_exit_pc) below) live_renames InsertPositionMap.empty in |