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

Last change on this file since 1568 was 1568, checked in by tranquil, 8 years ago
  • Immediates introduced (but not fully used yet in RTLabs to RTL pass)
  • translation streamlined
  • BUGGY: interpretation fails in LTL, trying to fetch a function with incorrect address
File size: 1.4 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_ind_0 _
23  | St_ind_inc _
24  | St_hdw_to_hdw _
25  | St_set_hdw (_, RTL.Imm _, _)
26  | St_newframe _
27  | St_delframe _
28  | St_clear_carry _
29  | St_set_carry _
30  | St_call_id _
31  | St_return _ ->
32    uses
33  | St_get_hdw (r, _, _)
34  | St_set_hdw (_, RTL.Reg r, _)
35  | St_framesize (r, _)
36  | St_pop (r, _)
37  | St_push (r, _)
38  | St_move (r, RTL.Imm _, _)
39  | St_addrH (r, _, _)
40  | St_addrL (r, _, _)
41  | St_cond (r, _, _) ->
42    count r uses
43  | St_move (r1, RTL.Reg r2, _)
44  | St_op1 (_, r1, r2, _)
45  | St_op2 (_, r1, r2, RTL.Imm _, _)
46  | St_call_ptr (r1, r2, _, _) ->
47    count r1 (count r2 uses)
48  | St_opaccsA (_, r1, r2, r3, _)
49  | St_opaccsB (_, r1, r2, r3, _)
50  | St_op2 (_, r1, r2, RTL.Reg r3, _)
51  | St_load (r1, r2, r3, _)
52  | St_store (r1, r2, r3, _) ->
53    count r1 (count r2 (count r3 uses))
54
55let examine_internal int_fun =
56  let uses =
57    Label.Map.fold examine_statement int_fun.f_graph Register.Map.empty
58  in
59  lookup uses
60
Note: See TracBrowser for help on using the repository browser.