Revision 9aaee7f9
Added by Xavier Thirioux almost 9 years ago
src/scheduling.ml | ||
---|---|---|
29 | 29 |
open Graph |
30 | 30 |
open Causality |
31 | 31 |
|
32 |
type schedule_report = |
|
33 |
{ |
|
34 |
schedule : ident list; |
|
35 |
unused_vars : ISet.t; |
|
36 |
death_table : (ident, ISet.t) Hashtbl.t |
|
37 |
} |
|
32 | 38 |
|
33 | 39 |
(* Topological sort with a priority for variables belonging in the same equation lhs. |
34 | 40 |
For variables still unrelated, standard compare is used to choose the minimal element. |
... | ... | |
72 | 78 |
pending := p; |
73 | 79 |
frontier := f; |
74 | 80 |
add_successors eq_equiv g choice pending frontier; |
75 |
if not (ExprDep.is_instance_var choice) then sort := choice :: !sort
|
|
81 |
if not (ExprDep.is_ghost_var choice) then sort := choice :: !sort
|
|
76 | 82 |
end |
77 | 83 |
else |
78 | 84 |
begin |
... | ... | |
80 | 86 |
(*Format.eprintf "-2-> %s@." choice;*) |
81 | 87 |
pending := ISet.remove choice !pending; |
82 | 88 |
add_successors eq_equiv g choice pending frontier; |
83 |
if not (ExprDep.is_instance_var choice) then sort := choice :: !sort
|
|
89 |
if not (ExprDep.is_ghost_var choice) then sort := choice :: !sort
|
|
84 | 90 |
end |
85 | 91 |
end |
86 | 92 |
|
... | ... | |
129 | 135 |
|
130 | 136 |
let gg = IdentDepGraph.copy g in |
131 | 137 |
let sort = topological_sort eq_equiv g in |
132 |
|
|
138 |
let unused = Liveness.compute_unused n gg in |
|
133 | 139 |
let death = Liveness.death_table n gg sort in |
134 | 140 |
Log.report ~level:5 |
135 | 141 |
(fun fmt -> |
... | ... | |
158 | 164 |
Liveness.pp_reuse_policy reuse |
159 | 165 |
); |
160 | 166 |
|
161 |
n', sort, (death, disjoint, reuse (* ??? *) ) |
|
162 |
(* let sorted = TopologicalDepGraph.fold (fun x res -> if ExprDep.is_instance_var x then res else x::res) g []*) |
|
167 |
n', { schedule = sort; unused_vars = unused; death_table = death } |
|
163 | 168 |
with (Causality.Cycle v) as exc -> |
164 | 169 |
pp_error Format.err_formatter v; |
165 | 170 |
raise exc |
166 | 171 |
|
167 | 172 |
let schedule_prog prog = |
168 | 173 |
List.fold_right ( |
169 |
fun top_decl (accu_prog, sch_map, death_map) ->
|
|
174 |
fun top_decl (accu_prog, sch_map) -> |
|
170 | 175 |
match top_decl.top_decl_desc with |
171 | 176 |
| Node nd -> |
172 |
let nd', sch, death_tbls = schedule_node nd in
|
|
177 |
let nd', report = schedule_node nd in
|
|
173 | 178 |
{top_decl with top_decl_desc = Node nd'}::accu_prog, |
174 |
(nd.node_id, sch)::sch_map, |
|
175 |
(nd.node_id, death_tbls)::death_map |
|
176 |
| _ -> top_decl::accu_prog, sch_map, death_map |
|
179 |
IMap.add nd.node_id report sch_map |
|
180 |
| _ -> top_decl::accu_prog, sch_map |
|
177 | 181 |
) |
178 | 182 |
prog |
179 |
([],[],[]) |
|
180 |
|
|
183 |
([],IMap.empty) |
|
184 |
|
|
185 |
let pp_warning_unused fmt node_schs = |
|
186 |
IMap.iter |
|
187 |
(fun nd report -> |
|
188 |
let unused = report.unused_vars in |
|
189 |
if not (ISet.is_empty unused) |
|
190 |
then |
|
191 |
let nd = match (Corelang.node_from_name nd).top_decl_desc with Node nd -> nd | _ -> assert false in |
|
192 |
ISet.iter |
|
193 |
(fun u -> |
|
194 |
Format.fprintf fmt "Warning: variable '%s' seems unused@.%a@." |
|
195 |
u |
|
196 |
Location.pp_loc (node_var u nd).var_loc) |
|
197 |
unused |
|
198 |
) |
|
199 |
node_schs |
|
181 | 200 |
|
182 | 201 |
(* Local Variables: *) |
183 | 202 |
(* compile-command:"make -C .." *) |
Also available in: Unified diff
added warnings for useless variables (at verbose level 1)
- exact definition of 'useless' may be further refined
- display could certainly be improved