Mercurial > repos > tabletprog
annotate modules/il.tp @ 189:a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Mon, 26 Aug 2013 18:23:05 -0700 |
parents | 181d8754a2ae |
children | 4293c725394c |
rev | line source |
---|---|
185 | 1 { |
2 //commutative ops | |
3 _add <- 0 | |
4 _and <- 1 | |
5 _or <- 2 | |
6 _xor <- 3 | |
7 //non-commutative ops | |
8 _sub <- 4 | |
9 _cmp <- 5 | |
10 _not <- 6 | |
11 _sl <- 7 | |
12 _asr <- 8 | |
13 _lsr <- 9 | |
14 _rol <- 10 | |
15 _ror <- 11 | |
16 _mov <- 12 | |
17 _call <- 13 | |
18 _ret <- 14 | |
19 _skipif <- 15 | |
20 | |
21 _names <- #[ | |
22 "add" | |
23 "and" | |
24 "or" | |
25 "xor" | |
26 "sub" | |
27 "cmp" | |
28 "not" | |
29 "sl" | |
30 "asr" | |
31 "lsr" | |
32 "rol" | |
33 "ror" | |
34 "mov" | |
35 "call" | |
36 "ret" | |
37 "skipIf" | |
38 ] | |
39 | |
40 op3:a:b:out:size <- :_opcode :_ina :_inb :_out :_size { | |
41 #{ | |
42 opcode <- { _opcode } | |
43 ina <- { _ina } | |
44 inb <- { _inb } | |
45 commutative? <- { _opcode < _sub } | |
46 out <- { _out } | |
47 size <- { _size } | |
48 numops <- { 3 } | |
49 name <- { _names get: _opcode } | |
50 string <- { name . " " . (string: _ina) . " " . (string: _inb) . " " . (string: _out) . " " . (string: _size) } | |
189
a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
51 recordUsage:at <- :tracker :address { |
a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
52 if: (not: (_ina isInteger?)) { |
a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
53 _ina recordUsage: tracker at: 0 | address withSize: _size |
a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
54 } |
a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
55 _inb recordUsage: tracker at: 0 | address withSize: _size |
a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
56 _out recordUsage: tracker at: 1 | address withSize: _size |
a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
57 } |
185 | 58 } |
59 } | |
60 op2:in:out:size <- :_opcode :_in :_out :_size { | |
61 #{ | |
62 opcode <- { _opcode } | |
63 in <- { _in } | |
64 out <- { _out } | |
65 size <- { _size } | |
66 numops <- { 2 } | |
67 name <- { _names get: _opcode } | |
68 string <- { name . " " . (string: _in) . " " . (string: _out) . " " . (string: _size) } | |
189
a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
69 recordUsage:at <- :tracker :address { |
a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
70 if: (not: (_in isInteger?)) { |
a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
71 _in recordUsage: tracker at: 0 | address withSize: _size |
a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
72 } |
a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
73 _out recordUsage: tracker at: 1 | address withSize: _size |
a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
74 } |
185 | 75 } |
76 } | |
77 op1:arg:size <- :_opcode :_arg :_size { | |
78 #{ | |
79 opcode <- { _opcode } | |
80 arg <- { _arg } | |
81 size <- { _size } | |
82 numops <- { 1 } | |
83 name <- { _names get: _opcode } | |
84 string <- { name . " " . (string: _arg) . " " . (string: _size) } | |
189
a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
85 recordUsage:at <- :tracker :address { |
a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
86 if: (not: (_arg isInteger?)) { |
a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
87 _arg recordUsage: tracker at: address withSize: _size |
a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
88 } |
a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
89 } |
185 | 90 } |
91 } | |
92 | |
93 _sizenames <- #["b" "w" "l" "q"] | |
94 _size <- :_num { | |
95 #{ | |
96 num <- { _num } | |
97 string <- { _sizenames get: _num } | |
98 = <- :other { | |
99 _num = (other num) | |
100 } | |
101 <= <- :other { | |
102 _num <= (other num) | |
103 } | |
104 >= <- :other { | |
105 _num >= (other num) | |
106 } | |
107 > <- :other { | |
108 _num > (other num) | |
109 } | |
110 < <- :other { | |
111 _num < (other num) | |
112 } | |
113 } | |
114 } | |
115 byte <- _size: 0 | |
116 word <- _size: 1 | |
117 long <- _size: 2 | |
118 quad <- _size: 3 | |
119 | |
120 _retr <- #{ | |
121 isInteger? <- { false } | |
122 register? <- { true } | |
123 argument? <- { false } | |
124 return? <- { true } | |
125 string <- { "retr" } | |
126 = <- :other { | |
127 (not: (other isInteger?)) && (other register?) && (other return?) | |
128 } | |
189
a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
129 != <- :other { |
a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
130 not: self = other |
a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
131 } |
a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
132 recordUsage:at:withSize <- :tracker :address :size { |
a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
133 //TODO: Figure out what tracking is necessary here |
a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
134 } |
185 | 135 } |
136 | |
137 _condnames <- #[ | |
138 "eq" | |
139 "neq" | |
140 "ge" | |
141 "le" | |
142 "gr" | |
143 "ls" | |
144 "uge" | |
145 "ule" | |
146 "ugr" | |
147 "uls" | |
148 ] | |
149 condition <- :num { | |
150 #{ | |
151 cc <- { num } | |
152 string <- { _condnames get: num } | |
153 = <- :other { num = (other cc) } | |
154 } | |
155 } | |
156 _eq <- condition: 0 | |
157 _neq <- condition: 1 | |
158 _ge <- condition: 2 | |
159 _le <- condition: 3 | |
160 _gr <- condition: 4 | |
161 _ls <- condition: 5 | |
162 _uge <- condition: 6 | |
163 _ule <- condition: 7 | |
164 _ugr <- condition: 8 | |
165 _uls <- condition: 9 | |
166 | |
167 #{ | |
168 b <- { byte } | |
169 w <- { word } | |
170 l <- { long } | |
171 q <- { quad } | |
172 | |
173 eq <- { _eq } | |
174 neq <- { _neq } | |
175 | |
176 //signed conditions | |
177 ge <- { _ge } | |
178 le <- { _le } | |
179 gr <- { _gr } | |
180 ls <- { _ls } | |
181 | |
182 //unsigned conditions | |
183 uge <- { _uge } | |
184 ule <- { _ule } | |
185 ugr <- { _ugr } | |
186 uls <- { _uls } | |
187 | |
188 | |
189 reg <- :num { | |
190 #{ | |
191 isInteger? <- { false } | |
192 register? <- { true } | |
193 argument? <- { false } | |
194 return? <- { false } | |
195 regnum <- { num } | |
196 string <- { "r" . (string: num) } | |
197 = <- :other { | |
198 (not: (other isInteger?)) && (other register?) && (not: (other argument?)) && (not: (other return?)) && num = (other regnum) | |
199 } | |
189
a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
200 != <- :other { |
a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
201 not: self = other |
a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
202 } |
a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
203 recordUsage:at:withSize <- :tracker :address :size { |
a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
204 tracker reg: self usedAt: address withSize: size |
a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
205 } |
185 | 206 } |
207 } | |
208 arg <- :num { | |
209 #{ | |
210 isInteger? <- { false } | |
211 register? <- { true } | |
212 argument? <- { true } | |
213 return? <- { false } | |
214 argnum <- { num } | |
215 string <- { "a" . (string: num) } | |
216 = <- :other { | |
217 (not: (other isInteger?)) && (other register?) && (other argument?) && num = (other regnum) | |
218 } | |
189
a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
219 != <- :other { |
a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
220 not: self = other |
a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
221 } |
a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
222 recordUsage:at:withSize <- :tracker :address :size { |
a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
223 tracker arg: self usedAt: address withSize: size |
a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
224 } |
185 | 225 } |
226 } | |
227 retr <- { _retr } | |
228 | |
189
a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
229 base:offset <- :_base :_offset { |
a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
230 #{ |
a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
231 base <- { _base } |
a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
232 offset <- { _offset } |
a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
233 string <- { |
a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
234 start <- if: _offset = 0 { "" } else: { (string: _offset) } |
a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
235 start . "[" . (string: _base) . "]" |
a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
236 } |
a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
237 recordUsage:at:withSize <- :tracker :address :size { |
a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
238 _base recordUsage: tracker at: address withSize: size |
a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
239 } |
a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
240 } |
a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
241 } |
a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
242 |
185 | 243 add <- :ina inb out size { |
244 op3: _add a: ina b: inb out: out size: size | |
245 } | |
246 | |
247 sub <- :ina inb out size { | |
248 op3: _sub a: ina b: inb out: out size: size | |
249 } | |
250 | |
251 cmp <- :ina inb out size { | |
252 op3: _cmp a: ina b: inb out: out size: size | |
253 } | |
254 | |
255 and <- :ina inb out size { | |
256 op3: _and a: ina b: inb out: out size: size | |
257 } | |
258 | |
259 or <- :ina inb out size { | |
260 op3: _or a: ina b: inb out: out size: size | |
261 } | |
262 | |
263 xor <- :ina inb out size { | |
264 op3: _xor a: ina b: inb out: out size: size | |
265 } | |
266 | |
267 bnot <- :in out size { | |
268 op2: _not in: in out: out size: size | |
269 } | |
270 | |
271 sl <- :shift in out size { | |
272 op3: _sl a: shift b: in out: out size: size | |
273 } | |
274 | |
275 asr <- :shift in out size { | |
276 op3: _asr a: shift b: in out: out size: size | |
277 } | |
278 | |
279 lsr <- :shift in out size { | |
280 op3: _lsr a: shift b: in out: out size: size | |
281 } | |
282 | |
283 rol <- :rot in out size { | |
284 op3: _rol a: rot b: in out: out size: size | |
285 } | |
286 | |
287 ror <- :rot in out size { | |
288 op3: _ror a: rot b: in out: out size: size | |
289 } | |
290 | |
291 mov <- :in out size { | |
292 op2: _mov in: in out: out size: size | |
293 } | |
294 | |
295 call:withArgs <- :_target :_args { | |
296 #{ | |
297 opcode <- { _call } | |
298 target <- { _target } | |
299 args <- { _args } | |
300 numops <- { 0 } | |
301 name <- { _names get: _call } | |
302 string <- { | |
303 argstr <- _args map: :el { | |
304 string: el | |
305 } | |
306 name . " " . (string: _target) . " " . (argstr join: " ") | |
307 } | |
189
a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
308 recordUsage:at <- :tracker :address { |
a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
309 if: (not: (_target isString?)) { |
a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
310 //TODO: use size l for 32-bit targets or an abstract pointer size |
a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
311 _target recordUsage: tracker at: address withSize: q |
a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
312 } |
a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
313 foreach: _args :_ arg { |
a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
314 //TODO: have some mechanism for properly expressing sizes of arguments |
a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
315 arg recordUsage: tracker at: address withSize: q |
a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
316 } |
a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
317 } |
185 | 318 } |
319 } | |
320 | |
321 return <- :val size { | |
322 op1: _ret arg: val size: size | |
323 } | |
324 skipIf <- :_cond _toskip { | |
325 #{ | |
326 opcode <- { _skipif } | |
327 toskip <- { _toskip } | |
328 cond <- { _cond } | |
329 numops <- { 0 } | |
330 name <- { _names get: _skipif } | |
331 string <- { | |
332 block <- (_toskip map: :el { string: el }) join: "\n\t" | |
333 if: (_toskip length) > 0 { | |
334 block <- "\n\t" . block . "\n" | |
335 } | |
336 name . " " . (string: _cond) . " {" . block . "}" | |
337 } | |
189
a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
338 recordUsage:at <- :tracker :address { |
a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
339 foreach: _toskip :idx inst { |
a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
340 inst recordUsage: tracker at: idx | address |
a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
341 } |
a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
342 } |
185 | 343 } |
344 } | |
345 | |
189
a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
346 allocRegs:withSource <- :instarr:regSrc { |
a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
347 _regMap <- dict linear |
a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
348 _argMap <- dict linear |
a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
349 |
a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
350 _usageTracker <- :_firstUsage { |
a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
351 #{ |
a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
352 firstUsage <- _firstUsage |
a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
353 lastUsage <- _firstUsage |
a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
354 useCount <- 0 |
a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
355 maxSize <- byte |
a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
356 usedAt:withSize <- :address :size { |
a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
357 useCount <- useCount + 1 |
a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
358 lastUsage <- address |
a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
359 if: size > maxSize { |
a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
360 maxSize <- size |
a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
361 } |
a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
362 } |
a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
363 string <- { |
a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
364 "Uses: " . useCount . ", FirstUse: " . (firstUsage join: ":") . ", Last Use: " . (lastUsage join: ":") . ", Max Size: " . maxSize |
a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
365 } |
a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
366 } |
a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
367 } |
a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
368 |
a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
369 _maxUses <- 0 |
a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
370 _maxUseReg <- false |
a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
371 regUsage <- #{ |
a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
372 reg:usedAt:withSize <- :reg :address :size { |
a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
373 usage <- _regMap get: reg elseSet: { |
a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
374 _usageTracker: address |
a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
375 } |
a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
376 usage usedAt: address withSize: size |
a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
377 if: (usage useCount) > _maxUses { |
a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
378 _maxUses <- usage useCount |
a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
379 _maxUseReg <- reg |
a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
380 } |
a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
381 } |
a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
382 arg:usedAt:withSize <- :arg :address :size { |
a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
383 usage <- _argMap get: arg elseSet: { |
a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
384 _usageTracker: [0 0] |
a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
385 } |
a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
386 usage usedAt: address withSize: size |
a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
387 } |
a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
388 print <- { |
a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
389 foreach: _regMap :reg usage { |
a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
390 print: (string: reg) . " | " . (string: usage) . "\n" |
a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
391 } |
a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
392 foreach: _argMap :arg usage { |
a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
393 print: (string: arg) . " | " . (string: usage) . "\n" |
a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
394 } |
a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
395 } |
a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
396 } |
a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
397 foreach: instarr :idx inst { |
a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
398 inst recordUsage: regUsage at: [idx] |
a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
399 } |
a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
400 print: regUsage |
a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
401 } |
a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
402 |
185 | 403 //used to convert IL to a format suitable for a 2-operand architecture |
404 //should be run after register allocation (I think....) | |
405 to2Op <- :instarr { | |
406 instarr fold: #[] with: :newarr inst { | |
407 if: (inst numops) = 3 { | |
408 if: (inst inb) = (inst out) { | |
409 newarr append: (op2: (inst opcode) in: (inst ina) out: (inst out) size: (inst size)) | |
410 } else: { | |
411 if: (inst commutative?) && (inst ina) = (inst out) { | |
412 newarr append: (op2: (inst opcode) in: (inst inb) out: (inst out) size: (inst size)) | |
413 } else: { | |
414 newarr append: (mov: (inst inb) (inst out) (inst size)) | |
415 newarr append: (op2: (inst opcode) in: (inst ina) out: (inst out) size: (inst size)) | |
416 } | |
417 } | |
418 } else: { | |
419 if: (inst numops) = 2 && (inst opcode) != _mov { | |
420 if: (inst in) != (inst out) { | |
421 newarr append: (mov: (inst in) (inst out) (inst size)) | |
422 } | |
423 newarr append: (op1: (inst opcode) val: (inst out) size: (inst size)) | |
424 } else: { | |
425 newarr append: inst | |
426 } | |
427 } | |
428 } | |
429 } | |
430 | |
431 main <- { | |
432 fib <- #[ | |
433 sub: 2 (arg: 0) (reg: 0) q | |
434 skipIf: ge #[ | |
435 return: 1 q | |
436 ] | |
437 call: "fib" withArgs: #[reg: 0] | |
438 mov: retr (reg: 1) q | |
439 add: 1 (reg: 0) (reg: 2) q | |
440 call: "fib" withArgs: #[reg: 2] | |
441 add: retr (reg: 1) (reg: 3) q | |
442 return: (reg: 3) q | |
443 ] | |
444 print: "Original:\n\n" | |
445 foreach: fib :idx inst { | |
446 print: (string: inst) . "\n" | |
447 } | |
189
a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
448 print: "\n\nUsage:\n\n" |
a45e535f7742
Determine live ranges for logical registers as part of initial work on register allocator
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
449 allocRegs: fib withSource: false |
185 | 450 fib2 <- to2Op: fib |
451 print: "\n\n2-Operand:\n\n" | |
452 foreach: fib2 :idx inst { | |
453 print: (string: inst) . "\n" | |
454 } | |
455 } | |
456 } | |
457 } |