]> matita.cs.unibo.it Git - pkg-cerco/acc.git/blob - src/ERTL/uses.ml
Imported Upstream version 0.2
[pkg-cerco/acc.git] / src / ERTL / uses.ml
1 (* Pasted from Pottier's PP compiler *)
2
3 (* This module offers functions that count how many times each
4    pseudo-register is used within a piece of [ERTL] code. This
5    is used in [Coloring] to drive the spilling heuristics. *)
6
7 open ERTL
8
9 let lookup uses r =
10   try
11     Register.Map.find r uses
12   with Not_found ->
13     0
14
15 let count r uses = Register.Map.add r (lookup uses r + 1) uses
16
17 let examine_statement _ stmt uses =
18   match stmt with
19   | St_skip _
20   | St_comment _
21   | St_cost _
22   | St_hdw_to_hdw _
23   | St_newframe _
24   | St_delframe _
25   | St_clear_carry _
26   | St_set_carry _
27   | St_call_id _
28   | St_return _ ->
29     uses
30   | St_get_hdw (r, _, _)
31   | St_set_hdw (_, r, _)
32   | St_framesize (r, _)
33   | St_pop (r, _)
34   | St_push (r, _)
35   | St_int (r, _, _)
36   | St_addrH (r, _, _)
37   | St_addrL (r, _, _)
38   | St_cond (r, _, _) ->
39     count r uses
40   | St_move (r1, r2, _)
41   | St_op1 (_, r1, r2, _)
42   | St_call_ptr (r1, r2, _, _) ->
43     count r1 (count r2 uses)
44   | St_opaccsA (_, r1, r2, r3, _)
45   | St_opaccsB (_, r1, r2, r3, _)
46   | St_op2 (_, r1, r2, r3, _)
47   | St_load (r1, r2, r3, _)
48   | St_store (r1, r2, r3, _) ->
49     count r1 (count r2 (count r3 uses))
50
51 let examine_internal int_fun =
52   let uses =
53     Label.Map.fold examine_statement int_fun.f_graph Register.Map.empty
54   in
55   lookup uses
56