]> gitweb.factorcode.org Git - factor.git/blob - basis/compiler/cfg/copy-prop/copy-prop-tests.factor
2e4fd73a4de7051be9aebd40e5379d55fc574c80
[factor.git] / basis / compiler / cfg / copy-prop / copy-prop-tests.factor
1 USING: accessors compiler.cfg  compiler.cfg.copy-prop compiler.cfg.debugger
2 compiler.cfg.instructions compiler.cfg.registers compiler.cfg.utilities
3 cpu.architecture kernel namespaces tools.test ;
4 IN: compiler.cfg.copy-prop.tests
5
6 : test-copy-propagation ( -- )
7     0 get block>cfg copy-propagation ;
8
9 ! Simple example
10 V{
11     T{ ##prologue }
12     T{ ##branch }
13 } 0 test-bb
14
15 V{
16     T{ ##peek f 0 D 0 }
17     T{ ##branch }
18 } 1 test-bb
19
20 V{
21     T{ ##peek f 1 D 1 }
22     T{ ##branch }
23 } 2 test-bb
24
25 V{
26     T{ ##copy f 2 0 any-rep }
27     T{ ##branch }
28 } 3 test-bb
29
30 V{
31     T{ ##phi f 3 H{ { 2 0 } { 3 2 } } }
32     T{ ##phi f 4 H{ { 2 1 } { 3 2 } } }
33     T{ ##phi f 5 H{ { 2 1 } { 3 0 } } }
34     T{ ##branch }
35 } 4 test-bb
36
37 V{
38     T{ ##copy f 6 4 any-rep }
39     T{ ##replace f 3 D 0 }
40     T{ ##replace f 5 D 1 }
41     T{ ##replace f 6 D 2 }
42     T{ ##branch }
43 } 5 test-bb
44
45 V{
46     T{ ##epilogue }
47     T{ ##return }
48 } 6 test-bb
49
50 0 1 edge
51 1 { 2 3 } edges
52 2 4 edge
53 3 4 edge
54 4 5 edge
55
56 [ ] [ test-copy-propagation ] unit-test
57
58 [
59     V{
60         T{ ##replace f 0 D 0 }
61         T{ ##replace f 4 D 1 }
62         T{ ##replace f 4 D 2 }
63         T{ ##branch }
64     }
65 ] [ 5 get instructions>> ] unit-test
66
67 ! Test optimistic assumption
68 V{
69     T{ ##prologue }
70     T{ ##branch }
71 } 0 test-bb
72
73 V{
74     T{ ##peek f 0 D 0 }
75     T{ ##branch }
76 } 1 test-bb
77
78 V{
79     T{ ##phi f 1 H{ { 1 0 } { 2 2 } } }
80     T{ ##copy f 2 1 any-rep }
81     T{ ##branch }
82 } 2 test-bb
83
84 V{
85     T{ ##replace f 2 D 1 }
86     T{ ##branch }
87 } 3 test-bb
88
89 V{
90     T{ ##epilogue }
91     T{ ##return }
92 } 4 test-bb
93
94 0 1 edge
95 1 2 edge
96 2 { 2 3 } edges
97 3 4 edge
98
99 [ ] [ test-copy-propagation ] unit-test
100
101 [
102     V{
103         T{ ##replace f 0 D 1 }
104         T{ ##branch }
105     }
106 ] [ 3 get instructions>> ] unit-test