source: Deliverables/D2.2/8051/src/ERTL/uses.ml @ 486

Last change on this file since 486 was 486, checked in by ayache, 8 years ago

Deliverable D2.2

File size: 1.2 KB
Line 
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
7open ERTL
8
9let lookup uses r =
10  try
11    Register.Map.find r uses
12  with Not_found ->
13    0
14
15let count r uses = Register.Map.add r (lookup uses r + 1) uses
16
17let 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_call_id _
27  | St_return _ ->
28    uses
29  | St_get_hdw (r, _, _)
30  | St_set_hdw (_, r, _)
31  | St_framesize (r, _)
32  | St_pop (r, _)
33  | St_push (r, _)
34  | St_int (r, _, _)
35  | St_addrH (r, _, _)
36  | St_addrL (r, _, _)
37  | St_condacc (r, _, _) ->
38    count r uses
39  | St_move (r1, r2, _)
40  | St_op1 (_, r1, r2, _) ->
41    count r1 (count r2 uses)
42  | St_opaccs (_, r1, r2, r3, _)
43  | St_op2 (_, r1, r2, r3, _)
44  | St_load (r1, r2, r3, _)
45  | St_store (r1, r2, r3, _) ->
46    count r1 (count r2 (count r3 uses))
47
48let examine_internal int_fun =
49  let uses =
50    Label.Map.fold examine_statement int_fun.f_graph Register.Map.empty
51  in
52  lookup uses
53
Note: See TracBrowser for help on using the repository browser.