Project

General

Profile

Revision e8c0f452 src/liveness.ml

View differences:

src/liveness.ml
114 114
    Format.fprintf fmt "}@."
115 115
  end
116 116

  
117

  
118
(* Reuse policy:
119
   - could reuse variables with the same type exactly only (simple).
120
   - reusing variables with different types would involve:
121
     - either dirty castings
122
     - or complex inclusion expression (for instance: array <-> array cell, struct <-> struct field) to be able to reuse only some parts of structured data.
123
     ... it seems too complex and potentially unsafe
124
   - for node instance calls: output variables could NOT reuse input variables, 
125
     even if inputs become dead, because the correctness would depend on the scheduling
126
     of the callee (so, the compiling strategy could NOT be modular anymore).
127
   - once a policy is set, we need to:
128
     - replace each variable by its reuse alias.
129
     - simplify resulting equations, as we may now have:
130
        x = x;                     --> ;           for scalar vars
131
       or:
132
        x = &{ f1 = x->f1; f2 = t; } --> x->f2 = t;   for struct vars
133
     - such simplifications are, until now, only expressible at the C source level...
134
 *)
135

  
117 136
(* Replaces [v] by [v'] in set [s] *)
118 137
let replace_in_set s v v' =
119 138
  if ISet.mem v s then ISet.add v' (ISet.remove v s) else s
......
123 142
 Hashtbl.iter (fun k dead -> Hashtbl.replace death k (replace_in_set dead v v')) death
124 143

  
125 144
let find_compatible_local node var dead =
126
 Format.eprintf "find_compatible_local %s %s@." node.node_id var;
145
 (*Format.eprintf "find_compatible_local %s %s@." node.node_id var;*)
127 146
  let typ = (Corelang.node_var var node).var_type in
147
  let eq_var = node_eq var node in
148
  let inputs =
149
    match NodeDep.get_callee eq_var.eq_rhs with
150
    | None           -> []
151
    | Some (_, args) -> List.fold_right (fun e r -> match e.expr_desc with Expr_ident id -> id::r | _ -> r) args [] in
152
  let filter v =
153
       ISet.mem v.var_id dead
154
    && Typing.eq_ground typ v.var_type
155
    && not (List.mem v.var_id inputs) in
128 156
  try
129
    Some ((List.find (fun v -> ISet.mem v.var_id dead && Typing.eq_ground typ v.var_type) node.node_locals).var_id)
157
    Some ((List.find filter node.node_locals).var_id)
130 158
  with Not_found -> None
131 159

  
132 160
let reuse_policy node sort death =

Also available in: Unified diff