(* Pasted from Pottier's PP compiler *) (* This module offers functions that count how many times each pseudo-register is used within a piece of [ERTL] code. This is used in [Coloring] to drive the spilling heuristics. *) open ERTL let lookup uses r = try Register.Map.find r uses with Not_found -> 0 let count r uses = Register.Map.add r (lookup uses r + 1) uses let examine_statement _ stmt uses = match stmt with | St_skip _ | St_comment _ | St_cost _ | St_hdw_to_hdw _ | St_newframe _ | St_delframe _ | St_clear_carry _ | St_set_carry _ | St_call_id _ | St_return _ -> uses | St_get_hdw (r, _, _) | St_set_hdw (_, r, _) | St_framesize (r, _) | St_pop (r, _) | St_push (r, _) | St_int (r, _, _) | St_addrH (r, _, _) | St_addrL (r, _, _) | St_cond (r, _, _) -> count r uses | St_move (r1, r2, _) | St_op1 (_, r1, r2, _) | St_call_ptr (r1, r2, _, _) -> count r1 (count r2 uses) | St_opaccsA (_, r1, r2, r3, _) | St_opaccsB (_, r1, r2, r3, _) | St_op2 (_, r1, r2, r3, _) | St_load (r1, r2, r3, _) | St_store (r1, r2, r3, _) -> count r1 (count r2 (count r3 uses)) let examine_internal int_fun = let uses = Label.Map.fold examine_statement int_fun.f_graph Register.Map.empty in lookup uses