]> gitweb.factorcode.org Git - factor.git/blob - basis/compiler/cfg/ssa/construction/construction-tests.factor
028b9a695598442111de2cb7db7e50a5b457c028
[factor.git] / basis / compiler / cfg / ssa / construction / construction-tests.factor
1 USING: accessors compiler.cfg compiler.cfg.debugger
2 compiler.cfg.dominance compiler.cfg.instructions
3 compiler.cfg.predecessors compiler.cfg.ssa.construction assocs
4 compiler.cfg.registers compiler.cfg.ssa.construction.private
5 compiler.cfg.utilities cpu.architecture kernel namespaces sequences tools.test
6 vectors ;
7 IN: compiler.cfg.ssa.construction.tests
8
9 ! insert-phi-later
10 {
11     { V{ T{ ##phi { dst 789 } { inputs H{ } } } } }
12 } [
13     H{ } clone inserting-phis set
14     789 { } 0 insns>block insert-phi-later
15     inserting-phis get values
16 ] unit-test
17
18 { 99 55 } [
19     H{ } clone inserting-phis set
20     { } 55 insns>block { } 1 insns>block [ connect-bbs ] keep
21     99 swap insert-phi-later
22     inserting-phis get values first first
23     [ dst>> ] [ inputs>> keys first number>> ] bi
24 ] unit-test
25
26 ! live-phi?
27 { f t } [
28     HS{ 68 } live-phis set
29     T{ ##phi } live-phi?
30     T{ ##phi { dst 68 } }  live-phi?
31 ] unit-test
32
33
34 : reset-counters ( -- )
35     ! Reset counters so that results are deterministic w.r.t. hash order
36     reset-vreg-counter 0 basic-block set-global ;
37
38 : test-ssa ( -- )
39     0 get block>cfg
40     dup cfg set
41     construct-ssa ;
42
43 : clean-up-phis ( insns -- insns' )
44     [ dup ##phi? [ [ [ [ number>> ] dip ] assoc-map ] change-inputs ] when ] map ;
45
46 ! Test 1
47 reset-counters
48
49 V{
50     T{ ##load-integer f 1 100 }
51     T{ ##add-imm f 2 1 50 }
52     T{ ##add-imm f 2 2 10 }
53     T{ ##branch }
54 } 0 test-bb
55
56 V{
57     T{ ##load-integer f 3 3 }
58     T{ ##branch }
59 } 1 test-bb
60
61 V{
62     T{ ##load-integer f 3 4 }
63     T{ ##branch }
64 } 2 test-bb
65
66 V{
67     T{ ##replace f 3 D 0 }
68     T{ ##return }
69 } 3 test-bb
70
71 0 { 1 2 } edges
72 1 3 edge
73 2 3 edge
74
75 [ ] [ test-ssa ] unit-test
76
77 [
78     V{
79         T{ ##load-integer f 1 100 }
80         T{ ##add-imm f 2 1 50 }
81         T{ ##add-imm f 3 2 10 }
82         T{ ##branch }
83     }
84 ] [ 0 get instructions>> ] unit-test
85
86 [
87     V{
88         T{ ##load-integer f 4 3 }
89         T{ ##branch }
90     }
91 ] [ 1 get instructions>> ] unit-test
92
93 [
94     V{
95         T{ ##load-integer f 5 4 }
96         T{ ##branch }
97     }
98 ] [ 2 get instructions>> ] unit-test
99
100 [
101     V{
102         T{ ##phi f 6 H{ { 1 4 } { 2 5 } } }
103         T{ ##replace f 6 D 0 }
104         T{ ##return }
105     }
106 ] [
107     3 get instructions>>
108     clean-up-phis
109 ] unit-test
110
111 ! Test 2
112 reset-counters
113
114 V{ } 0 test-bb
115 V{ } 1 test-bb
116 V{ T{ ##peek f 0 D 0 } } 2 test-bb
117 V{ T{ ##peek f 0 D 0 } } 3 test-bb
118 V{ T{ ##replace f 0 D 0 } } 4 test-bb
119 V{ } 5 test-bb
120 V{ } 6 test-bb
121
122 0 { 1 5 } edges
123 1 { 2 3 } edges
124 2 4 edge
125 3 4 edge
126 4 6 edge
127 5 6 edge
128
129 [ ] [ test-ssa ] unit-test
130
131 [
132     V{
133         T{ ##phi f 3 H{ { 2 1 } { 3 2 } } }
134         T{ ##replace f 3 D 0 }
135     }
136 ] [
137     4 get instructions>>
138     clean-up-phis
139 ] unit-test
140
141 ! Test 3
142 reset-counters
143
144 V{
145     T{ ##branch }
146 } 0 test-bb
147
148 V{
149     T{ ##load-integer f 3 3 }
150     T{ ##branch }
151 } 1 test-bb
152
153 V{
154     T{ ##load-integer f 3 4 }
155     T{ ##branch }
156 } 2 test-bb
157
158 V{
159     T{ ##branch }
160 } 3 test-bb
161
162 V{
163     T{ ##return }
164 } 4 test-bb
165
166 0 { 1 2 3 } edges
167 1 4 edge
168 2 4 edge
169 3 4 edge
170
171 [ ] [ test-ssa ] unit-test
172
173 [ V{ } ] [ 4 get instructions>> [ ##phi? ] filter ] unit-test
174
175 ! Test 4
176 reset-counters
177
178 V{
179     T{ ##branch }
180 } 0 test-bb
181
182 V{
183     T{ ##branch }
184 } 1 test-bb
185
186 V{
187     T{ ##load-integer f 0 4 }
188     T{ ##branch }
189 } 2 test-bb
190
191 V{
192     T{ ##load-integer f 0 4 }
193     T{ ##branch }
194 } 3 test-bb
195
196 V{
197     T{ ##branch }
198 } 4 test-bb
199
200 V{
201     T{ ##branch }
202 } 5 test-bb
203
204 V{
205     T{ ##branch }
206 } 6 test-bb
207
208 V{
209     T{ ##return }
210 } 7 test-bb
211
212 0 { 1 6 } edges
213 1 { 2 3 4 } edges
214 2 5 edge
215 3 5 edge
216 4 5 edge
217 5 7 edge
218 6 7 edge
219
220 [ ] [ test-ssa ] unit-test
221
222 [ V{ } ] [ 5 get instructions>> [ ##phi? ] filter ] unit-test
223
224 [ V{ } ] [ 7 get instructions>> [ ##phi? ] filter ] unit-test