Debian Codegraph @

lib/mlrisc-lib/MLRISC/ra/ra-graph.sig

raw
1 (* ra-graph.sig
2 *
3 * COPYRIGHT (c) 2002 Bell Labs, Lucent Technologies.
4 *
5 * This is the new interference graph used by the new register allocator.
6 *
7 * -- Allen
8 *)
9
10 signature RA_GRAPH =
11 sig
12
13 structure C : CELLS_BASIS
14 structure BM : RA_BITMATRIX (* = RaBitmatrix *)
15 where type bitMatrix = RaBitmatrix.bitMatrix
16 and type bucket = RaBitmatrix.bucket
17 and type hashTable = RaBitmatrix.hashTable
18 (*
19 * The following are the data structures used in the register allocator.
20 *)
21
22 exception Nodes
23
24 type priority = real
25 type cost = real
26
27 (*
28 * The following represent a program point in the program.
29 *
30 * The last instruction in the block is numbered 1, i.e. the instruction
31 * numbering is in reverse. The number 0 is reserved for "live-out".
32 *
33 *)
34 type programPoint = {block:int, insn:int}
35
36 (* Hash table indexed by program point *)
37 structure PPtHashTable : MONO_HASH_TABLE
38 where type Key.hash_key = programPoint
39
40 type frame_offset = int
41 type logical_spill_id = int
42
43 datatype spillLoc =
44 FRAME of logical_spill_id (* spill to a new frame location *)
45 | MEM_REG of C.cell (* spill to a memory register *)
46
47 (* Hash table indexed by spill location *)
48 structure SpillLocHashTable : MONO_HASH_TABLE
49 where type Key.hash_key = spillLoc
50
51 type mode = word
52
53 datatype interferenceGraph =
54 GRAPH of
55 { bitMatrix : BM.bitMatrix ref,
56 nodes : node IntHashTable.hash_table,
57 K : int,
58 firstPseudoR : int,
59 dedicated : int -> bool,
60 getreg : {pref:int list, stamp:int, proh:int Array.array} -> int,
61 getpair : {pref:int list, stamp:int, proh:int Array.array} -> int,
62 proh : int Array.array,
63 stamp : int ref,
64
65 (* Info to undo a spill when an optimistic spill has occurred *)
66 spillFlag : bool ref,
67
68 spilledRegs : bool IntHashTable.hash_table,
69 (*registers that have been spilled*)
70 trail : trailInfo ref,
71
72 (* how to pretty print a register *)
73 showReg : C.cell -> string,
74
75 (* how many registers there are? *)
76 numRegs : int,
77 maxRegs : unit -> int,
78
79 (* dead copies *)
80 deadCopies : C.cell list ref,
81 copyTmps : node list ref,
82 memMoves : move list ref,
83 memRegs : node list ref,
84
85 (* spill locations *)
86 spillLoc : int ref,
87
88 (* span indexed by node id *)
89 span : cost IntHashTable.hash_table option ref,
90
91 (* mode *)
92 mode : mode,
93
94 pseudoCount : int ref
95 }
96
97 and moveStatus = BRIGGS_MOVE (* not yet coalesceable *)
98 | GEORGE_MOVE (* not yet coalesceable *)
99 | COALESCED (* coalesced *)
100 | CONSTRAINED (* src and target intefere *)
101 | LOST (* frozen moves *)
102 | WORKLIST (* on the move worklist *)
103
104 and move =
105 MV of {src : node, (* source register of move *)
106 dst : node, (* destination register of move *)
107 (* kind : moveKind, (* kind of move *) *)
108 cost : cost, (* cost *)
109 status : moveStatus ref, (* coalesced? *)
110 hicount: int ref (* neighbors of high degree *)
111 }
112
113 and moveKind = REG_TO_REG (* register to register *)
114 | EVEN_TO_REG (* even register in pair to register *)
115 | ODD_TO_REG (* odd register in pair to register *)
116 | PAIR_TO_PAIR (* register pair to register pair *)
117 | REG_TO_EVEN (* register to even register in pair *)
118 | REG_TO_ODD (* register to odd register in pair *)
119 (* and moveKind = REGmvk (* register-register move *)
120 | MEMREGmvk (* move involving memReg *)
121
122 *)
123
124 and nodeStatus =
125 PSEUDO (* pseudo register *)
126 | REMOVED (* removed from the interference graph *)
127 | ALIASED of node (* coalesced *)
128 | COLORED of int (* colored *)
129 | MEMREG of int * C.cell(* register implemented in memory *)
130 | SPILLED (* spilled *)
131 | SPILL_LOC of int (* spilled at logical location *)
132
133 (* Note on SPILLED:
134 * SPILLED ~1 means that the spill location is still undetermined
135 * SPILLED c, c >= 0 means that c is a fixed "memory register"
136 * SPILLED c, c < ~1 means that c is a logical spill location
137 * assigned by the register allocator
138 *)
139
140 and node =
141 NODE of { number : int, (* node number *)
142 cell: C.cell,
143 movecnt: int ref, (* #moves this node is involved in *)
144 movelist: move list ref, (* moves associated with this node *)
145 degree : int ref, (* current degree *)
146 color : nodeStatus ref, (* status *)
147 adj : node list ref, (* adjacency list *)
148 pri : priority ref, (* priority *)
149 movecost : cost ref, (* move cost *)
150 (* pair : bool, *) (* register pair? *)
151 defs : programPoint list ref,
152 uses : programPoint list ref
153 }
154
155 and trailInfo = END | UNDO of node * moveStatus ref * trailInfo
156
157 (* Create a new bitMatrix *)
158 val newBitMatrix : {edges : int, maxRegs : int} -> BM.bitMatrix
159
160 (* Create a new interference graph *)
161 val newGraph : { nodes : node IntHashTable.hash_table,
162 numRegs : int,
163 maxRegs : unit -> int,
164 K : int,
165 firstPseudoR : int,
166 dedicated : int -> bool,
167 showReg : C.cell -> string,
168 getreg :
169 {pref:int list,stamp:int,proh:int Array.array} -> int,
170 getpair :
171 {pref:int list,stamp:int,proh:int Array.array} -> int,
172 proh : int Array.array,
173 mode : mode,
174 spillLoc : int ref,
175 memRegs : C.cell list
176 } -> interferenceGraph
177
178 end