Revision a77bd1e3
Added by Pierre-Loïc Garoche over 10 years ago
src/optimize_machine.ml | ||
---|---|---|
30 | 30 |
(* see if elim has to take in account the provided instr: |
31 | 31 |
if so, upodate elim and return the remove flag, |
32 | 32 |
otherwise, the expression should be kept and elim is left untouched *) |
33 |
let update_elim elim instr = |
|
33 |
let update_elim outputs elim instr =
|
|
34 | 34 |
(* Format.eprintf "SHOULD WE STORE THE EXPRESSION IN INSTR %a TO ELIMINATE IT@." pp_instr instr;*) |
35 | 35 |
|
36 | 36 |
let apply elim v new_e = |
... | ... | |
40 | 40 |
(* Simple cases*) |
41 | 41 |
| MLocalAssign (v, (Cst _ as e)) |
42 | 42 |
| MLocalAssign (v, (LocalVar _ as e)) |
43 |
| MLocalAssign (v, (StateVar _ as e)) -> true, apply elim v e |
|
43 |
| MLocalAssign (v, (StateVar _ as e)) -> |
|
44 |
if not (List.mem v outputs) then true, apply elim v e else false, elim |
|
44 | 45 |
(* When optimization >= 3, we also inline any basic operator call. |
45 | 46 |
All those are returning a single ouput *) |
46 | 47 |
| MStep([v], id, vl) when |
... | ... | |
51 | 52 |
|
52 | 53 |
|
53 | 54 |
| MLocalAssign (v, ((Fun (id, il)) as e)) when |
54 |
List.mem id Basic_library.internal_funs (* this will avoid inlining ite *) |
|
55 |
not (List.mem v outputs) |
|
56 |
&& List.mem id Basic_library.internal_funs (* this will avoid inlining ite *) |
|
55 | 57 |
&& !Options.optimization >= 3 |
56 | 58 |
-> ( |
57 | 59 |
(* Format.eprintf "WE STORE THE EXPRESSION DEFINING %s TO ELIMINATE IT@." v.var_id; *) |
... | ... | |
66 | 68 |
1. each expression is rewritten according to the accumulator |
67 | 69 |
2. local assigns then rewrite occurrences of the lhs in the computed accumulator |
68 | 70 |
*) |
69 |
let optimize_minstrs instrs = |
|
71 |
let optimize_minstrs outputs instrs =
|
|
70 | 72 |
let rev_instrs, eliminate = |
71 | 73 |
List.fold_left (fun (rinstrs, elim) instr -> |
72 | 74 |
(* each subexpression in instr that could be rewritten by the elim set is |
... | ... | |
74 | 76 |
let instr = eliminate elim instr in |
75 | 77 |
(* if instr is a simple local assign, then (a) elim is simplified with it (b) it |
76 | 78 |
is stored as the elim set *) |
77 |
let remove, elim = update_elim elim instr in |
|
79 |
let remove, elim = update_elim outputs elim instr in
|
|
78 | 80 |
(if remove then rinstrs else instr::rinstrs), elim |
79 | 81 |
) ([],[]) instrs |
80 | 82 |
in |
... | ... | |
86 | 88 |
|
87 | 89 |
*) |
88 | 90 |
let optimize_machine machine = |
89 |
let eliminated_vars, new_instrs = optimize_minstrs machine.mstep.step_instrs in |
|
91 |
let eliminated_vars, new_instrs = optimize_minstrs machine.mstep.step_outputs machine.mstep.step_instrs in
|
|
90 | 92 |
let new_locals = |
91 | 93 |
List.filter (fun v -> not (List.mem v eliminated_vars)) machine.mstep.step_locals |
92 | 94 |
in |
Also available in: Unified diff
Solved bug in optimization of machine code: output variable def should not be eliminated