]> gitweb.factorcode.org Git - factor.git/blob - basis/compiler/cfg/ssa/destruction/coalescing/coalescing-tests.factor
core: Rename iota to <iota> so we can have TUPLE: iota ... ; instead of TUPLE: iota...
[factor.git] / basis / compiler / cfg / ssa / destruction / coalescing / coalescing-tests.factor
1 USING: assocs compiler.cfg.def-use compiler.cfg.instructions
2 compiler.cfg.registers compiler.cfg.ssa.destruction.coalescing
3 compiler.cfg.ssa.destruction.leaders
4 compiler.cfg.ssa.interference compiler.cfg.utilities
5 compiler.utilities cpu.architecture grouping kernel make
6 namespaces random sequences tools.test ;
7 IN: compiler.cfg.ssa.destruction.coalescing.tests
8
9 ! eliminatable-copy?
10 { { f t t f } } [
11     H{
12         { 45 double-2-rep }
13         { 46 double-rep }
14         { 47 double-rep }
15         { 100 double-rep }
16         { 20 tagged-rep }
17         { 30 int-rep }
18     } representations set
19     { { 45 46 } { 47 100 } { 20 30 } { 30 100 } }
20     [ first2 eliminatable-copy? ] map
21 ] unit-test
22
23 ! initial-class-elements
24 {
25     H{
26         {
27             77
28             { T{ vreg-info { vreg 77 } { value 77 } { bb "bb2" } } }
29         }
30         {
31             123
32             {
33                 T{ vreg-info
34                    { vreg 123 }
35                    { value 123 }
36                    { bb "bb1" }
37                 }
38             }
39         }
40     }
41 } [
42     H{ { 123 "bb1" } { 77 "bb2" } } defs set
43     initial-class-elements
44 ] unit-test
45
46 ! initial-leaders
47 {
48     H{ { 65 65 } { 99 99 } { 62 62 } { 303 303 } }
49 } [
50     {
51         T{ ##load-vector
52            { dst 62 }
53            { val B{ 0 0 0 0 0 0 0 64 0 0 0 0 0 0 52 64 } }
54            { rep double-2-rep }
55         }
56         T{ ##add-vector
57            { dst 65 }
58            { src1 62 }
59            { src2 63 }
60            { rep double-2-rep }
61         }
62         T{ ##allot
63            { dst 99 }
64            { size 24 }
65            { temp 303 }
66         }
67     } initial-leaders
68 ] unit-test
69
70 ! init-coalescing
71 {
72     H{ { 118 118 } }
73 } [
74     { T{ ##phi { dst 118 } { inputs H{ { 4 120 } { 2 119 } } } } }
75     [ insns>cfg compute-defs ] [ init-coalescing ] bi
76     leader-map get
77 ] unit-test
78
79 ! try-eliminate-copy
80 { } [
81     10 10 f try-eliminate-copy
82 ] unit-test
83
84 ! coalesce-later
85 { V{ { 2 1 } } } [
86     [
87         T{ ##copy { src 1 } { dst 2 } { rep int-rep } } coalesce-later
88     ] V{ } make
89 ] unit-test
90
91 { V{ { 3 4 } { 7 8 } } } [
92     [
93         T{ ##parallel-copy { values V{ { 3 4 } { 7 8 } } } } coalesce-later
94     ] V{ } make
95 ] unit-test
96
97 ! All this work to make the 'values' order non-deterministic.
98 : make-phi-inputs ( -- assoc )
99     H{ } clone [
100         { 2287 2288 } [
101             10 <iota> 1 sample first rot set-at
102         ] with each
103     ] keep ;
104
105 { t } [
106     10 [
107         { 2286 2287 2288 } unique leader-map set
108         2286 make-phi-inputs ##phi new-insn
109         coalesce-now
110         2286 leader
111     ] replicate all-equal?
112 ] unit-test