1 IN: compiler.cfg.linear-scan.tests
2 USING: tools.test random sorting sequences sets hashtables assocs
3 kernel fry arrays splitting namespaces math accessors vectors
8 compiler.cfg.instructions
10 compiler.cfg.linear-scan
11 compiler.cfg.linear-scan.live-intervals
12 compiler.cfg.linear-scan.allocation
13 compiler.cfg.linear-scan.debugger ;
17 { vreg T{ vreg { reg-class int-regs } { n 2 } } }
20 { uses V{ 0 1 3 7 10 } }
27 { vreg T{ vreg { reg-class int-regs } { n 2 } } }
30 { uses V{ 0 1 3 4 10 } }
37 { vreg T{ vreg { reg-class int-regs } { n 2 } } }
40 { uses V{ 0 1 3 4 10 } }
42 100 [ >= ] find-use nip
47 { vreg T{ vreg { reg-class int-regs } { n 1 } } }
53 { vreg T{ vreg { reg-class int-regs } { n 1 } } }
60 { vreg T{ vreg { reg-class int-regs } { n 1 } } }
69 { vreg T{ vreg { reg-class int-regs } { n 1 } } }
75 { vreg T{ vreg { reg-class int-regs } { n 1 } } }
82 { vreg T{ vreg { reg-class int-regs } { n 1 } } }
91 { vreg T{ vreg { reg-class int-regs } { n 1 } } }
99 { vreg T{ vreg { reg-class int-regs } { n 1 } } }
102 { uses V{ 1 3 7 10 15 } }
105 { vreg T{ vreg { reg-class int-regs } { n 1 } } }
111 { vreg T{ vreg { reg-class int-regs } { n 1 } } }
118 { vreg T{ vreg { reg-class int-regs } { n 1 } } }
128 { vreg T{ vreg { reg-class int-regs } { n 1 } } }
131 { uses V{ 5 10 15 } }
134 { vreg T{ vreg { reg-class int-regs } { n 1 } } }
144 { vreg T{ vreg { reg-class int-regs } { n 1 } } }
147 { uses V{ 5 10 15 } }
150 { vreg T{ vreg { reg-class int-regs } { n 1 } } }
160 { vreg T{ vreg { reg-class int-regs } { n 1 } } }
166 { vreg T{ vreg { reg-class int-regs } { n 1 } } }
176 T{ live-interval { vreg T{ vreg { n 1 } { reg-class int-regs } } } { start 0 } { end 100 } { uses V{ 0 100 } } }
178 H{ { int-regs { "A" } } }
184 T{ live-interval { vreg T{ vreg { n 1 } { reg-class int-regs } } } { start 0 } { end 10 } { uses V{ 0 10 } } }
185 T{ live-interval { vreg T{ vreg { n 2 } { reg-class int-regs } } } { start 11 } { end 20 } { uses V{ 11 20 } } }
187 H{ { int-regs { "A" } } }
193 T{ live-interval { vreg T{ vreg { n 1 } { reg-class int-regs } } } { start 0 } { end 100 } { uses V{ 0 100 } } }
194 T{ live-interval { vreg T{ vreg { n 2 } { reg-class int-regs } } } { start 30 } { end 60 } { uses V{ 30 60 } } }
196 H{ { int-regs { "A" } } }
202 T{ live-interval { vreg T{ vreg { n 1 } { reg-class int-regs } } } { start 0 } { end 100 } { uses V{ 0 100 } } }
203 T{ live-interval { vreg T{ vreg { n 2 } { reg-class int-regs } } } { start 30 } { end 200 } { uses V{ 30 200 } } }
205 H{ { int-regs { "A" } } }
211 T{ live-interval { vreg T{ vreg { n 1 } { reg-class int-regs } } } { start 0 } { end 100 } { uses V{ 0 100 } } }
212 T{ live-interval { vreg T{ vreg { n 2 } { reg-class int-regs } } } { start 30 } { end 100 } { uses V{ 30 100 } } }
214 H{ { int-regs { "A" } } }
222 SYMBOL: max-registers
229 available get keys dup empty? [ "Oops" throw ] when
231 dup taken get nth 1 + max-registers get = [
232 dup available get delete-at
234 dup taken get [ 1 + ] change-nth
237 : random-live-intervals ( num-intervals max-uses max-registers max-insns -- seq )
242 max-insns get [ 0 ] replicate taken set
243 max-insns get [ dup ] H{ } map>assoc available set
246 swap int-regs swap vreg boa >>vreg
247 max-uses get random 2 max [ not-taken ] replicate natural-sort
248 [ >>uses ] [ first >>start ] bi
249 dup uses>> last >>end
253 : random-test ( num-intervals max-uses max-registers max-insns -- )
254 over [ random-live-intervals ] dip int-regs associate check-linear-scan ;
256 [ ] [ 30 2 1 60 random-test ] unit-test
257 [ ] [ 60 2 2 60 random-test ] unit-test
258 [ ] [ 80 2 3 200 random-test ] unit-test
259 [ ] [ 70 2 5 30 random-test ] unit-test
260 [ ] [ 60 2 6 30 random-test ] unit-test
261 [ ] [ 1 2 10 10 random-test ] unit-test
263 [ ] [ 10 4 2 60 random-test ] unit-test
264 [ ] [ 10 20 2 400 random-test ] unit-test
265 [ ] [ 10 20 4 300 random-test ] unit-test
267 USING: math.private compiler.cfg.debugger ;
270 [ float+ float>fixnum 3 fixnum*fast ]
271 test-cfg first optimize-cfg linear-scan drop
280 T{ vreg f int-regs 1 }
283 T{ vreg f int-regs 2 }
288 } clone [ [ clone ] map ] change-instructions
289 dup 1array (linear-scan) instructions>> first regs>> values all-equal?
295 { vreg T{ vreg { reg-class int-regs } { n 1 } } }
301 { vreg T{ vreg { reg-class int-regs } { n 2 } } }
307 { vreg T{ vreg { reg-class int-regs } { n 3 } } }
313 H{ { int-regs { "A" "B" } } }
315 first split-before>> [ start>> ] [ end>> ] bi
318 ! Coalescing interacted badly with splitting
322 { vreg V int-regs 70 }
325 { uses V{ 14 15 16 17 } }
326 { copy-from V int-regs 67 }
329 { vreg V int-regs 67 }
335 { vreg V int-regs 30 }
338 { uses V{ 4 12 16 17 18 } }
341 { vreg V int-regs 27 }
347 { vreg V int-regs 59 }
350 { uses V{ 10 11 12 18 } }
351 { copy-from V int-regs 56 }
354 { vreg V int-regs 60 }
360 { vreg V int-regs 56 }
366 { { int-regs { 0 1 2 3 } } }
367 allocate-registers drop
373 { vreg V int-regs 3687168 }
376 { uses V{ 106 112 } }
379 { vreg V int-regs 3687169 }
382 { uses V{ 107 113 } }
385 { vreg V int-regs 3687727 }
388 { uses V{ 190 195 198 } }
391 { vreg V int-regs 3686445 }
397 { vreg V int-regs 3686195 }
403 { vreg V int-regs 3686449 }
406 { uses V{ 44 45 45 46 56 } }
407 { copy-from V int-regs 3686445 }
410 { vreg V int-regs 3686198 }
416 { vreg V int-regs 3686454 }
419 { uses V{ 46 47 47 49 } }
420 { copy-from V int-regs 3686449 }
423 { vreg V int-regs 3686196 }
429 { vreg V int-regs 3686197 }
432 { uses V{ 7 13 14 } }
435 { vreg V int-regs 3686455 }
441 { vreg V int-regs 3686463 }
447 { vreg V int-regs 3686460 }
450 { uses V{ 49 50 50 52 } }
451 { copy-from V int-regs 3686454 }
454 { vreg V int-regs 3686461 }
457 { uses V{ 51 52 64 68 71 } }
460 { vreg V int-regs 3686464 }
466 { vreg V int-regs 3686465 }
469 { uses V{ 54 55 55 76 } }
470 { copy-from V int-regs 3686464 }
473 { vreg V int-regs 3686470 }
476 { uses V{ 58 59 59 60 } }
477 { copy-from V int-regs 3686469 }
480 { vreg V int-regs 3686469 }
483 { uses V{ 56 57 57 58 } }
484 { copy-from V int-regs 3686449 }
487 { vreg V int-regs 3686473 }
490 { uses V{ 60 61 61 62 } }
491 { copy-from V int-regs 3686470 }
494 { vreg V int-regs 3686479 }
497 { uses V{ 62 63 63 64 } }
498 { copy-from V int-regs 3686473 }
501 { vreg V int-regs 3686735 }
504 { uses V{ 78 79 79 96 } }
505 { copy-from V int-regs 3686372 }
508 { vreg V int-regs 3686482 }
514 { vreg V int-regs 3686483 }
520 { vreg V int-regs 3687510 }
523 { uses V{ 168 171 } }
526 { vreg V int-regs 3687511 }
529 { uses V{ 169 176 } }
532 { vreg V int-regs 3686484 }
535 { uses V{ 66 67 67 75 } }
536 { copy-from V int-regs 3686483 }
539 { vreg V int-regs 3687509 }
542 { uses V{ 162 163 } }
545 { vreg V int-regs 3686491 }
551 { vreg V int-regs 3687512 }
554 { uses V{ 170 177 178 } }
557 { vreg V int-regs 3687515 }
560 { uses V{ 172 173 } }
563 { vreg V int-regs 3686492 }
566 { uses V{ 69 70 70 74 } }
567 { copy-from V int-regs 3686491 }
570 { vreg V int-regs 3687778 }
573 { uses V{ 202 208 } }
576 { vreg V int-regs 3686499 }
582 { vreg V int-regs 3687520 }
585 { uses V{ 174 175 } }
588 { vreg V int-regs 3687779 }
591 { uses V{ 203 209 } }
594 { vreg V int-regs 3687782 }
597 { uses V{ 206 207 } }
600 { vreg V int-regs 3686503 }
606 { vreg V int-regs 3686500 }
609 { uses V{ 72 73 73 74 } }
610 { copy-from V int-regs 3686499 }
613 { vreg V int-regs 3687780 }
616 { uses V{ 204 210 } }
619 { vreg V int-regs 3686506 }
625 { vreg V int-regs 3687530 }
628 { uses V{ 185 192 } }
631 { vreg V int-regs 3687528 }
634 { uses V{ 183 198 } }
637 { vreg V int-regs 3687529 }
640 { uses V{ 184 197 } }
643 { vreg V int-regs 3687781 }
646 { uses V{ 205 211 } }
649 { vreg V int-regs 3687535 }
652 { uses V{ 187 194 } }
655 { vreg V int-regs 3686252 }
658 { uses V{ 9 15 17 } }
661 { vreg V int-regs 3686509 }
664 { uses V{ 76 87 90 } }
667 { vreg V int-regs 3687532 }
670 { uses V{ 186 196 } }
673 { vreg V int-regs 3687538 }
676 { uses V{ 188 193 } }
679 { vreg V int-regs 3687827 }
682 { uses V{ 217 219 } }
685 { vreg V int-regs 3687825 }
688 { uses V{ 215 216 218 } }
691 { vreg V int-regs 3687831 }
694 { uses V{ 218 219 } }
697 { vreg V int-regs 3686296 }
703 { vreg V int-regs 3686302 }
709 { vreg V int-regs 3687838 }
712 { uses V{ 231 232 } }
715 { vreg V int-regs 3686300 }
721 { vreg V int-regs 3686301 }
724 { uses V{ 27 28 28 30 } }
725 { copy-from V int-regs 3686300 }
728 { vreg V int-regs 3686306 }
731 { uses V{ 37 82 93 } }
734 { vreg V int-regs 3686307 }
737 { uses V{ 38 85 88 } }
740 { vreg V int-regs 3687837 }
743 { uses V{ 222 223 } }
746 { vreg V int-regs 3686305 }
749 { uses V{ 36 42 77 81 } }
752 { vreg V int-regs 3686310 }
755 { uses V{ 39 84 95 } }
758 { vreg V int-regs 3687836 }
761 { uses V{ 227 228 } }
764 { vreg V int-regs 3687839 }
767 { uses V{ 239 245 246 } }
770 { vreg V int-regs 3687841 }
773 { uses V{ 240 241 } }
776 { vreg V int-regs 3687845 }
779 { uses V{ 241 243 } }
782 { vreg V int-regs 3686315 }
785 { uses V{ 40 83 94 } }
788 { vreg V int-regs 3687846 }
791 { uses V{ 242 245 } }
794 { vreg V int-regs 3687849 }
797 { uses V{ 243 244 244 245 } }
798 { copy-from V int-regs 3687845 }
801 { vreg V int-regs 3687850 }
807 { vreg V int-regs 3687851 }
813 { vreg V int-regs 3687852 }
819 { vreg V int-regs 3687853 }
822 { uses V{ 247 248 } }
825 { vreg V int-regs 3687854 }
828 { uses V{ 249 250 } }
831 { vreg V int-regs 3687855 }
834 { uses V{ 258 259 } }
837 { vreg V int-regs 3687080 }
840 { uses V{ 280 285 } }
843 { vreg V int-regs 3687081 }
846 { uses V{ 281 286 } }
849 { vreg V int-regs 3687082 }
852 { uses V{ 282 287 } }
855 { vreg V int-regs 3687083 }
858 { uses V{ 283 288 } }
861 { vreg V int-regs 3687085 }
864 { uses V{ 284 285 286 287 288 296 299 } }
867 { vreg V int-regs 3687086 }
873 { vreg V int-regs 3687087 }
876 { uses V{ 289 293 } }
879 { vreg V int-regs 3687088 }
882 { uses V{ 290 294 } }
885 { vreg V int-regs 3687089 }
888 { uses V{ 291 297 } }
891 { vreg V int-regs 3687090 }
894 { uses V{ 292 298 } }
897 { vreg V int-regs 3687363 }
900 { uses V{ 118 119 } }
903 { vreg V int-regs 3686599 }
906 { uses V{ 77 86 89 } }
909 { vreg V int-regs 3687370 }
912 { uses V{ 131 132 } }
915 { vreg V int-regs 3687371 }
918 { uses V{ 138 143 } }
921 { vreg V int-regs 3687368 }
924 { uses V{ 127 128 } }
927 { vreg V int-regs 3687369 }
930 { uses V{ 122 123 } }
933 { vreg V int-regs 3687373 }
936 { uses V{ 139 140 } }
939 { vreg V int-regs 3686352 }
942 { uses V{ 41 43 79 91 } }
945 { vreg V int-regs 3687377 }
948 { uses V{ 140 141 } }
951 { vreg V int-regs 3687382 }
957 { vreg V int-regs 3687383 }
960 { uses V{ 144 159 161 } }
963 { vreg V int-regs 3687380 }
966 { uses V{ 141 142 142 143 } }
967 { copy-from V int-regs 3687377 }
970 { vreg V int-regs 3687381 }
973 { uses V{ 143 160 } }
976 { vreg V int-regs 3687384 }
979 { uses V{ 145 158 } }
982 { vreg V int-regs 3687385 }
985 { uses V{ 146 157 } }
988 { vreg V int-regs 3687640 }
991 { uses V{ 189 191 } }
994 { vreg V int-regs 3687388 }
997 { uses V{ 147 152 } }
1000 { vreg V int-regs 3687393 }
1003 { uses V{ 148 153 } }
1006 { vreg V int-regs 3687398 }
1009 { uses V{ 149 154 } }
1012 { vreg V int-regs 3686372 }
1015 { uses V{ 42 45 78 80 92 } }
1018 { vreg V int-regs 3687140 }
1021 { uses V{ 293 294 294 295 } }
1022 { copy-from V int-regs 3687087 }
1025 { vreg V int-regs 3687403 }
1028 { uses V{ 150 155 } }
1031 { vreg V int-regs 3687150 }
1034 { uses V{ 304 306 } }
1037 { vreg V int-regs 3687151 }
1040 { uses V{ 305 307 } }
1043 { vreg V int-regs 3687408 }
1046 { uses V{ 151 156 } }
1049 { vreg V int-regs 3687153 }
1052 { uses V{ 312 313 } }
1055 { vreg V int-regs 3686902 }
1058 { uses V{ 267 272 } }
1061 { vreg V int-regs 3686903 }
1064 { uses V{ 268 273 } }
1067 { vreg V int-regs 3686900 }
1070 { uses V{ 265 270 } }
1073 { vreg V int-regs 3686901 }
1076 { uses V{ 266 271 } }
1079 { vreg V int-regs 3687162 }
1082 { uses V{ 100 114 117 119 } }
1085 { vreg V int-regs 3687163 }
1088 { uses V{ 101 115 116 118 } }
1091 { vreg V int-regs 3686904 }
1094 { uses V{ 269 274 } }
1097 { vreg V int-regs 3687166 }
1100 { uses V{ 104 110 } }
1103 { vreg V int-regs 3687167 }
1106 { uses V{ 105 111 } }
1109 { vreg V int-regs 3687164 }
1112 { uses V{ 102 108 } }
1115 { vreg V int-regs 3687165 }
1118 { uses V{ 103 109 } }
1121 { { int-regs { 0 1 2 3 4 } } }
1122 allocate-registers drop
1125 ! A reduction of the above
1129 { vreg V int-regs 6449 }
1132 { uses V{ 44 45 46 56 } }
1135 { vreg V int-regs 6454 }
1138 { uses V{ 46 47 49 } }
1141 { vreg V int-regs 6455 }
1147 { vreg V int-regs 6460 }
1150 { uses V{ 49 50 52 } }
1153 { vreg V int-regs 6461 }
1156 { uses V{ 51 52 64 68 71 } }
1159 { vreg V int-regs 6464 }
1165 { vreg V int-regs 6470 }
1168 { uses V{ 58 59 60 } }
1171 { vreg V int-regs 6469 }
1174 { uses V{ 56 57 58 } }
1177 { vreg V int-regs 6473 }
1180 { uses V{ 60 61 62 } }
1183 { vreg V int-regs 6479 }
1186 { uses V{ 62 63 64 } }
1189 { vreg V int-regs 6735 }
1192 { uses V{ 78 79 96 } }
1193 { copy-from V int-regs 6372 }
1196 { vreg V int-regs 6483 }
1202 { vreg V int-regs 7845 }
1208 { vreg V int-regs 6372 }
1211 { uses V{ 42 45 78 80 92 } }
1214 { { int-regs { 0 1 2 3 } } }
1215 allocate-registers drop