1 USING: accessors arrays assocs compiler.cfg.dominance
2 compiler.cfg.dominance.private compiler.cfg.utilities compiler.test
3 grouping kernel ranges namespaces sequences sets tools.test ;
4 IN: compiler.cfg.dominance.tests
6 : test-dominance ( -- )
7 0 get block>cfg needs-dominance ;
9 ! Example with no back edges
23 { } [ test-dominance ] unit-test
25 { t } [ 0 get dom-parent 0 get eq? ] unit-test
26 { t } [ 1 get dom-parent 0 get eq? ] unit-test
27 { t } [ 2 get dom-parent 0 get eq? ] unit-test
28 { t } [ 4 get dom-parent 0 get eq? ] unit-test
29 { t } [ 3 get dom-parent 1 get eq? ] unit-test
30 { t } [ 5 get dom-parent 4 get eq? ] unit-test
32 { t } [ 0 get dom-children 1 get 2 get 4 get 3array set= ] unit-test
34 { t } [ 0 get 3 get dominates? ] unit-test
35 { f } [ 3 get 4 get dominates? ] unit-test
36 { f } [ 1 get 4 get dominates? ] unit-test
37 { t } [ 4 get 5 get dominates? ] unit-test
38 { f } [ 1 get 5 get dominates? ] unit-test
40 ! Example from the paper
53 { } [ test-dominance ] unit-test
55 { t } [ 0 4 [a..b] [ get dom-parent 0 get eq? ] all? ] unit-test
57 ! The other example from the paper
72 { } [ test-dominance ] unit-test
74 { t } [ 0 5 [a..b] [ get dom-parent 0 get eq? ] all? ] unit-test
76 : non-det-test ( -- cfg )
77 9 <iota> [ V{ } clone over insns>block ] { } map>assoc dup
85 } make-edges 0 of block>cfg ;
87 : dom-childrens>numbers ( -- assoc )
89 [ [ number>> ] [ [ number>> ] map ] bi* ] assoc-map ;
91 ! It is essential that the same dominance map is created each time and
92 ! that it does not differ due to hashing irregularities.
95 non-det-test needs-dominance dom-childrens>numbers
96 ] replicate all-equal?