Project

General

Profile

Revision 01d48bb0 src/optimize_machine.ml

View differences:

src/optimize_machine.ml
14 14
open Corelang
15 15
open Causality
16 16
open Machine_code 
17
open Dimension
17 18

  
18 19
let pp_elim fmt elim =
19 20
  begin
......
47 48
  | Power(v1, v2) -> Power(eliminate_expr elim v1, eliminate_expr elim v2)
48 49
  | Cst _ | StateVar _ -> expr
49 50

  
51
let eliminate_dim elim dim =
52
  Dimension.expr_replace_expr (fun v -> try dimension_of_value (IMap.find v elim) with Not_found -> mkdim_ident dim.dim_loc v) dim
53

  
50 54
let is_scalar_const c =
51 55
  match c with
52 56
  | Const_int _
......
116 120
    2. local assigns then rewrite occurrences of the lhs in the computed accumulator
117 121
*)
118 122

  
123
let static_call_unfold elim (inst, (n, args)) =
124
  let replace v =
125
    try
126
      Machine_code.dimension_of_value (IMap.find v elim)
127
    with Not_found -> Dimension.mkdim_ident Location.dummy_loc v
128
  in (inst, (n, List.map (Dimension.expr_replace_expr replace) args))
129

  
119 130
(** Perform optimization on machine code:
120 131
    - iterate through step instructions and remove simple local assigns
121 132
    
122 133
*)
123 134
let machine_unfold fanin elim machine =
124 135
  (*Log.report ~level:1 (fun fmt -> Format.fprintf fmt "machine_unfold %a@." pp_elim elim);*)
125
  let eliminated_vars, new_instrs = instrs_unfold fanin elim machine.mstep.step_instrs in
126
  let new_locals = List.filter (fun v -> not (IMap.mem v.var_id eliminated_vars)) machine.mstep.step_locals 
136
  let elim_consts, mconst = instrs_unfold fanin elim machine.mconst in
137
  let elim_vars, instrs = instrs_unfold fanin elim_consts machine.mstep.step_instrs in
138
  let locals = List.filter (fun v -> not (IMap.mem v.var_id elim_vars)) machine.mstep.step_locals in
139
  let minstances = List.map (static_call_unfold elim_consts) machine.minstances in
140
  let mcalls = List.map (static_call_unfold elim_consts) machine.mcalls
127 141
  in
128 142
  {
129 143
    machine with
130 144
      mstep = { 
131 145
	machine.mstep with 
132
	  step_locals = new_locals;
133
	  step_instrs = new_instrs
134
      }
146
	  step_locals = locals;
147
	  step_instrs = instrs
148
      };
149
      mconst = mconst;
150
      minstances = minstances;
151
      mcalls = mcalls;
135 152
  }
136 153

  
137 154
let instr_of_const top_const =
138 155
  let const = const_of_top top_const in
139
  let vdecl = mkvar_decl Location.dummy_loc (const.const_id, mktyp Location.dummy_loc Tydec_any, mkclock Location.dummy_loc Ckdec_any, true) in
156
  let vdecl = mkvar_decl Location.dummy_loc (const.const_id, mktyp Location.dummy_loc Tydec_any, mkclock Location.dummy_loc Ckdec_any, true, None) in
140 157
  let vdecl = { vdecl with var_type = const.const_type }
141 158
  in MLocalAssign (vdecl, Cst const.const_value)
142 159

  

Also available in: Unified diff