Project

General

Profile

« Previous | Next » 

Revision 17d63fff

Added by LĂ©lio Brun 10 months ago

remove unused variables after tag elimination in machine code (-O >= 3)

View differences:

src/optimize_machine.ml
900 900

  
901 901
let rec instr_reduce branches instr1 cont =
902 902
  match get_instr_desc instr1 with
903
  | MLocalAssign (_, { value_desc = Cst (Const_tag c); _ }) ->
904
    instr1 :: (List.assoc c branches @ cont)
903
  | MLocalAssign (_, { value_desc = Cst (Const_tag c); _ })
905 904
  | MStateAssign (_, { value_desc = Cst (Const_tag c); _ }) ->
906 905
    instr1 :: (List.assoc c branches @ cont)
907 906
  | MBranch (g, hl) ->
......
938 937
let step_fusion step =
939 938
  { step with step_instrs = instrs_fusion step.step_instrs }
940 939

  
941
let machine_fusion m = { m with mstep = step_fusion m.mstep }
940
let machine_fusion m =
941
  let m = { m with mstep = step_fusion m.mstep } in
942
  let unused = Machine_code_dep.compute_unused_variables m in
943
  let is_used v = not (ISet.mem v.var_id unused) in
944
  let step_locals = List.filter is_used m.mstep.step_locals in
945
  let rec filter_instrs instrs =
946
    List.filter_map (fun instr -> match get_instr_desc instr with
947
        | MLocalAssign (v, _) ->
948
          if is_used v then Some instr else None
949
        | MBranch (e, hl) ->
950
          Some (update_instr_desc instr
951
                  (MBranch (e, List.map (fun (h, l) -> h, filter_instrs l) hl)))
952
        | _ -> Some instr) instrs
953
  in
954
  let step_instrs = filter_instrs m.mstep.step_instrs in
955
  { m with mstep = { m.mstep with step_locals; step_instrs }}
956
  (* List.iter (fun (g, u) -> Format.printf "%a@;%a@." pp_dep_graph g ISet.pp u) gs; *)
942 957

  
943 958
let machines_fusion prog = List.map machine_fusion prog
944 959

  
......
1100 1115
        Scheduling.remove_prog_inlined_locals removed_table node_schs
1101 1116
      in
1102 1117
      let reuse_tables = Scheduling.compute_prog_reuse_table node_schs in
1103
      machines_fusion (machines_reuse_variables reuse_tables machine_code))
1118
      let machine_code = machines_fusion (machines_reuse_variables reuse_tables machine_code) in
1119
      machine_code)
1104 1120
    else machine_code
1105 1121
  in
1106 1122

  

Also available in: Unified diff