]> gitweb.factorcode.org Git - factor.git/blob - basis/compiler/cfg/ssa/interference/interference-tests.factor
0a1da4ddb35b17fc99462c75c75905cfa5b2ba13
[factor.git] / basis / compiler / cfg / ssa / interference / interference-tests.factor
1 USING: accessors compiler.cfg compiler.cfg.debugger
2 compiler.cfg.def-use compiler.cfg.dominance
3 compiler.cfg.instructions compiler.cfg.liveness
4 compiler.cfg.registers compiler.cfg.predecessors
5 compiler.cfg.comparisons compiler.cfg.ssa.interference
6 compiler.cfg.ssa.interference.private
7 compiler.cfg.ssa.interference.live-ranges
8 compiler.cfg.utilities
9 cpu.architecture kernel namespaces tools.test alien.c-types
10 arrays sequences slots ;
11 IN: compiler.cfg.ssa.interference.tests
12
13 : test-interference ( -- )
14     0 get block>cfg
15     dup compute-live-sets
16     dup compute-defs
17     dup compute-insns
18     compute-live-ranges ;
19
20 : <test-vreg-info> ( vreg -- info )
21     [ ] [ insn-of dup ##tagged>integer? [ src>> ] [ dst>> ] if ] [ def-of ] tri
22     <vreg-info> ;
23
24 : test-vregs-intersect? ( vreg1 vreg2 -- ? )
25     [ <test-vreg-info> ] bi@ vregs-intersect? ;
26
27 : test-vregs-interfere? ( vreg1 vreg2 -- ? )
28     [ <test-vreg-info> ] bi@
29     [ blue >>color ] [ red >>color ] bi*
30     vregs-interfere? ;
31
32 : test-sets-interfere? ( seq1 seq2 -- merged ? )
33     [ [ <test-vreg-info> ] map ] bi@ sets-interfere? ;
34
35 V{
36     T{ ##peek f 0 D 0 }
37     T{ ##peek f 2 D 0 }
38     T{ ##copy f 1 0 }
39     T{ ##copy f 3 2 }
40     T{ ##branch }
41 } 0 test-bb
42
43 V{
44     T{ ##peek f 4 D 0 }
45     T{ ##peek f 5 D 0 }
46     T{ ##replace f 3 D 0 }
47     T{ ##peek f 6 D 0 }
48     T{ ##replace f 5 D 0 }
49     T{ ##return }
50 } 1 test-bb
51
52 0 1 edge
53
54 { } [ test-interference ] unit-test
55
56 { f } [ 0 1 test-vregs-intersect? ] unit-test
57 { f } [ 1 0 test-vregs-intersect? ] unit-test
58 { f } [ 2 3 test-vregs-intersect? ] unit-test
59 { f } [ 3 2 test-vregs-intersect? ] unit-test
60 { t } [ 0 2 test-vregs-intersect? ] unit-test
61 { t } [ 2 0 test-vregs-intersect? ] unit-test
62 { f } [ 1 3 test-vregs-intersect? ] unit-test
63 { f } [ 3 1 test-vregs-intersect? ] unit-test
64 { t } [ 3 4 test-vregs-intersect? ] unit-test
65 { t } [ 4 3 test-vregs-intersect? ] unit-test
66 { t } [ 3 5 test-vregs-intersect? ] unit-test
67 { t } [ 5 3 test-vregs-intersect? ] unit-test
68 { f } [ 3 6 test-vregs-intersect? ] unit-test
69 { f } [ 6 3 test-vregs-intersect? ] unit-test
70
71 V{
72     T{ ##prologue }
73     T{ ##branch }
74 } 0 test-bb
75
76
77 V{
78     T{ ##inc f D -3 }
79     T{ ##peek f 12 D -2 }
80     T{ ##peek f 23 D -1 }
81     T{ ##sar-imm f 13 23 4 }
82     T{ ##peek f 24 D -3 }
83     T{ ##sar-imm f 14 24 4 }
84     T{ ##mul f 15 13 13 }
85     T{ ##mul f 16 15 15 }
86     T{ ##tagged>integer f 17 12 }
87     T{ ##store-memory f 16 17 14 0 7 int-rep uchar }
88     T{ ##branch }
89 } 1 test-bb
90
91 V{
92     T{ ##epilogue }
93     T{ ##return }
94 } 2 test-bb
95
96 0 1 edge
97 1 2 edge
98
99 { } [ test-interference ] unit-test
100
101 { t } [ { 15 } { 23 13 } test-sets-interfere? nip ] unit-test
102
103 V{
104     T{ ##prologue f }
105     T{ ##branch f }
106 } 0 test-bb
107
108 V{
109     T{ ##inc f D 2 }
110     T{ ##peek f 32 D 2 }
111     T{ ##load-reference f 33 ##check-nursery-branch }
112     T{ ##load-integer f 34 11 }
113     T{ ##tagged>integer f 35 32 }
114     T{ ##and-imm f 36 35 15 }
115     T{ ##compare-integer-imm-branch f 36 7 cc= }
116 } 1 test-bb
117
118 V{
119     T{ ##slot-imm f 48 32 1 7 }
120     T{ ##slot-imm f 50 48 1 2 }
121     T{ ##sar-imm f 65 50 4 }
122     T{ ##compare-integer-branch f 34 65 cc<= }
123 } 2 test-bb
124
125 V{
126     T{ ##inc f D -2 }
127     T{ ##slot-imm f 57 48 11 2 }
128     T{ ##compare f 58 33 57 cc= 20 }
129     T{ ##replace f 58 D 0 }
130     T{ ##branch f }
131 } 3 test-bb
132
133 V{
134     T{ ##epilogue f }
135     T{ ##return f }
136 } 4 test-bb
137
138 V{
139     T{ ##inc f D -2 }
140     T{ ##replace-imm f f D 0 }
141     T{ ##branch f }
142 } 5 test-bb
143
144 V{
145     T{ ##epilogue f }
146     T{ ##return f }
147 } 6 test-bb
148
149 V{
150     T{ ##inc f D -2 }
151     T{ ##replace-imm f f D 0 }
152     T{ ##branch f }
153 } 7 test-bb
154
155 V{
156     T{ ##epilogue f }
157     T{ ##return f }
158 } 8 test-bb
159
160 0 1 edge
161 1 { 2 7 } edges
162 2 { 3 5 } edges
163 3 4 edge
164 5 6 edge
165 7 8 edge
166
167 { } [ test-interference ] unit-test
168
169 { f } [ { 48 } { 32 35 } test-sets-interfere? nip ] unit-test
170
171 TUPLE: bab ;
172 TUPLE: gfg { x bab } ;
173 : bah ( -- x ) f ;
174
175 V{
176     T{ ##prologue }
177     T{ ##branch }
178 } 0 test-bb
179
180 V{
181     T{ ##check-nursery-branch f 16 cc<= 75 76 }
182 } 1 test-bb
183
184 V{
185     T{ ##save-context f 77 78 }
186     T{ ##call-gc f T{ gc-map } }
187     T{ ##branch }
188 } 2 test-bb
189
190 V{
191     T{ ##inc f D 1 }
192     T{ ##load-reference f 37 T{ bab } }
193     T{ ##load-reference f 38 { gfg 1 1 tuple 57438726 gfg 7785907 } }
194     T{ ##allot f 40 12 tuple 4 }
195     T{ ##set-slot-imm f 38 40 1 7 }
196     T{ ##set-slot-imm f 37 40 2 7 }
197     T{ ##replace f 40 D 0 }
198     T{ ##branch }
199 } 3 test-bb
200
201 V{
202     T{ ##call f bah }
203     T{ ##branch }
204 } 4 test-bb
205
206 V{
207     T{ ##inc f R 1 }
208     T{ ##inc f D 1 }
209     T{ ##peek f 43 D 1 }
210     T{ ##peek f 44 D 2 }
211     T{ ##tagged>integer f 45 43 }
212     T{ ##and-imm f 46 45 15 }
213     T{ ##compare-integer-imm-branch f 46 7 cc= }
214 } 5 test-bb
215
216 V{
217     T{ ##inc f D 1 }
218     T{ ##slot-imm f 58 43 1 7 }
219     T{ ##slot-imm f 60 58 7 2 }
220     T{ ##compare-imm-branch f 60 bab cc= }
221 } 6 test-bb
222
223 V{
224     T{ ##branch }
225 } 7 test-bb
226
227 V{
228     T{ ##inc f R -1 }
229     T{ ##inc f D -1 }
230     T{ ##set-slot-imm f 43 44 2 7 }
231     T{ ##write-barrier-imm f 44 2 7 34 35 }
232     T{ ##branch }
233 } 8 test-bb
234
235 V{
236     T{ ##epilogue }
237     T{ ##return }
238 } 9 test-bb
239
240 V{
241     T{ ##inc f D 1 }
242     T{ ##replace f 44 R 0 }
243     T{ ##replace-imm f bab D 0 }
244     T{ ##branch }
245 } 10 test-bb
246
247 V{
248     T{ ##call f bad-slot-value }
249     T{ ##branch }
250 } 11 test-bb
251
252 V{
253     T{ ##no-tco }
254 } 12 test-bb
255
256 V{
257     T{ ##inc f D -1 }
258     T{ ##branch }
259 } 13 test-bb
260
261 V{
262     T{ ##inc f D 1 }
263     T{ ##replace f 44 R 0 }
264     T{ ##replace-imm f bab D 0 }
265     T{ ##branch }
266 } 14 test-bb
267
268 V{
269     T{ ##call f bad-slot-value }
270     T{ ##branch }
271 } 15 test-bb
272
273 V{
274     T{ ##no-tco }
275 } 16 test-bb
276
277 0 1 edge
278 1 { 3 2 } edges
279 2 3 edge
280 3 4 edge
281 4 5 edge
282 5 { 6 13 } edges
283 6 { 7 10 } edges
284 7 8 edge
285 8 9 edge
286 10 11 edge
287 11 12 edge
288 13 14 edge
289 14 15 edge
290 15 16 edge
291
292 { } [ test-interference ] unit-test
293
294 { t } [ 43 45 test-vregs-intersect? ] unit-test
295 { f } [ 43 45 test-vregs-interfere? ] unit-test
296
297 { t } [ 43 46 test-vregs-intersect? ] unit-test
298 { t } [ 43 46 test-vregs-interfere? ] unit-test
299
300 { f } [ 45 46 test-vregs-intersect? ] unit-test
301 { f } [ 45 46 test-vregs-interfere? ] unit-test
302
303 { f } [ { 43 } { 45 } test-sets-interfere? nip ] unit-test
304
305 { t f } [
306     { 46 } { 43 } { 45 }
307     [ [ <test-vreg-info> ] map ] tri@
308     sets-interfere? [ sets-interfere? nip ] dip
309 ] unit-test
310
311 V{
312     T{ ##prologue f }
313     T{ ##branch f }
314 } 0 test-bb
315
316 V{
317
318     T{ ##inc f D 1 }
319     T{ ##peek f 31 D 1 }
320     T{ ##sar-imm f 16 31 4 }
321     T{ ##load-integer f 17 0 }
322     T{ ##copy f 33 17 int-rep }
323     T{ ##branch f }
324 } 1 test-bb
325
326 V{
327     T{ ##phi f 21 H{ { 1 33 } { 3 32 } } }
328     T{ ##compare-integer-branch f 21 16 cc< }
329 } 2 test-bb
330
331 V{
332     T{ ##add-imm f 27 21 1 }
333     T{ ##copy f 32 27 int-rep }
334     T{ ##branch f }
335 } 3 test-bb
336
337 V{
338     T{ ##inc f D -2 }
339     T{ ##branch f }
340 } 4 test-bb
341
342 V{
343     T{ ##epilogue f }
344     T{ ##return f }
345 } 5 test-bb
346
347 0 1 edge
348 1 2 edge
349 2 { 3 4 } edges
350 3 2 edge
351 4 5 edge
352
353 { } [ test-interference ] unit-test
354
355 { f f } [
356     { 33 } { 21 } { 32 }
357     [ [ <test-vreg-info> ] map ] tri@
358     sets-interfere? [ sets-interfere? nip ] dip
359 ] unit-test
360
361 { f } [ 33 21 test-vregs-intersect? ] unit-test
362 { f } [ 32 21 test-vregs-intersect? ] unit-test
363 { f } [ 32 33 test-vregs-intersect? ] unit-test