Project

General

Profile

Download (1.72 KB) Statistics
| Branch: | Tag: | Revision:
1
open Lustre_types
2
open Machine_code_types
3
open Corelang
4
open Utils
5

    
6
let rec add_expr_dependencies inputs g x e = match e.value_desc with
7
  | Var y ->
8
    let y' = y.var_id in
9
    IdentDepGraph.add_edge g x.var_id
10
      (if List.exists (fun z -> z.var_id = y') inputs
11
       then Causality.ExprDep.mk_read_var y' else y')
12
  | Fun (_, es)
13
  | Array es ->
14
    List.iter (add_expr_dependencies inputs g x) es
15
  | Access (e1, e2)
16
  | Power (e1, e2) ->
17
    add_expr_dependencies inputs g x e1;
18
    add_expr_dependencies inputs g x e2
19
  | _ -> ()
20

    
21
let rec add_instr_dependencies inputs g deps instr = match get_instr_desc instr with
22
  | MLocalAssign (x, e)
23
  | MStateAssign (x, e) ->
24
    add_expr_dependencies inputs g x e;
25
    List.iter (add_expr_dependencies inputs g x) deps
26
  | MStep (xs, _, es) ->
27
    List.iter (fun x ->
28
        List.iter (add_expr_dependencies inputs g x) es;
29
        List.iter (add_expr_dependencies inputs g x) deps) xs
30
  | MBranch (e, hl) ->
31
    List.iter (fun (_, l) -> List.iter (add_instr_dependencies inputs g (e :: deps)) l) hl
32
  | _ -> ()
33

    
34
let dep_graph m =
35
  let g = IdentDepGraph.create () in
36
  List.iter (add_instr_dependencies m.mstep.step_inputs g []) m.mstep.step_instrs;
37
  List.iter (fun x -> IdentDepGraph.add_edge g Causality.world x.var_id) m.mstep.step_outputs;
38
  g
39

    
40
let compute_unused_variables m =
41
  let g = dep_graph m in
42
  List.fold_left
43
    (fun unused x ->
44
       (* let coi = Liveness.cone_of_influence g x.var_id in *)
45
       (* Format.printf "unused: %a@;coi of %s: %a@." ISet.pp unused x.var_id ISet.pp coi; *)
46
       ISet.diff unused (Liveness.cone_of_influence g x.var_id))
47
    (List.fold_left (fun s v -> ISet.add v.var_id s) ISet.empty (m.mstep.step_locals @ m.mstep.step_inputs))
48
    m.mstep.step_outputs
(50-50/101)