1 ! Copyright (C) 2010 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors assocs compiler.cfg.def-use
4 compiler.cfg.instructions compiler.cfg.rpo disjoint-sets fry
5 kernel namespaces sequences ;
6 IN: compiler.cfg.representations.coalescing
8 ! Find all strongly connected components in the graph where the
9 ! edges are ##phi or ##copy vreg uses
12 : init-components ( cfg components -- )
15 defs-vregs [ _ add-atom ] each
19 GENERIC# visit-insn 1 ( insn disjoint-set -- )
22 [ [ dst>> ] [ src>> ] bi ] dip equate ;
25 [ [ inputs>> values ] [ dst>> ] bi ] dip equate-all-with ;
27 M: insn visit-insn 2drop ;
29 : merge-components ( cfg components -- )
36 : compute-components ( cfg -- )
40 [ components set drop ] 2tri ;
42 : vreg>scc ( vreg -- scc )
43 components get representative ;