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 count_arg = function |
---|
18 | | RTL.Reg r -> count r |
---|
19 | | RTL.Imm _ -> fun x -> x |
---|
20 | |
---|
21 | let examine_statement _ stmt uses = |
---|
22 | match stmt with |
---|
23 | | St_skip _ |
---|
24 | | St_comment _ |
---|
25 | | St_cost _ |
---|
26 | | St_ind_0 _ |
---|
27 | | St_ind_inc _ |
---|
28 | | St_hdw_to_hdw _ |
---|
29 | | St_newframe _ |
---|
30 | | St_delframe _ |
---|
31 | | St_clear_carry _ |
---|
32 | | St_set_carry _ |
---|
33 | | St_call_id _ |
---|
34 | | St_return _ -> |
---|
35 | uses |
---|
36 | | St_get_hdw (r, _, _) |
---|
37 | | St_framesize (r, _) |
---|
38 | | St_pop (r, _) |
---|
39 | | St_addrH (r, _, _) |
---|
40 | | St_addrL (r, _, _) |
---|
41 | | St_cond (r, _, _) -> |
---|
42 | count r uses |
---|
43 | | St_set_hdw (_, a, _) |
---|
44 | | St_push (a, _) -> |
---|
45 | count_arg a uses |
---|
46 | | St_move (r1, a2, _) -> |
---|
47 | count r1 (count_arg a2 uses) |
---|
48 | | St_call_ptr (r1, r2, _, _) |
---|
49 | | St_op1 (_, r1, r2, _) -> |
---|
50 | count r1 (count r2 uses) |
---|
51 | | St_opaccsA (_, r, a1, a2, _) |
---|
52 | | St_opaccsB (_, r, a1, a2, _) |
---|
53 | | St_load (r, a1, a2, _) |
---|
54 | | St_op2 (_, r, a1, a2, _) -> |
---|
55 | count r (count_arg a1 (count_arg a1 uses)) |
---|
56 | | St_store (a1, a2, a3, _) -> |
---|
57 | count_arg a1 (count_arg a2 (count_arg a3 uses)) |
---|
58 | |
---|
59 | let examine_internal int_fun = |
---|
60 | let uses = |
---|
61 | Label.Map.fold examine_statement int_fun.f_graph Register.Map.empty |
---|
62 | in |
---|
63 | lookup uses |
---|
64 | |
---|