1 ! Copyright (C) 2008 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: namespaces kernel assocs accessors sequences math
4 math.order sorting compiler.instructions compiler.registers ;
5 IN: compiler.machine.linear-scan.live-intervals
7 TUPLE: live-interval < identity-tuple vreg start end ;
9 M: live-interval hashcode* nip [ start>> ] [ end>> 1000 * ] bi + ;
11 ! Mapping from vreg to live-interval
12 SYMBOL: live-intervals
14 : update-live-interval ( n vreg -- )
17 [ over f live-interval boa ] cache
20 : compute-live-intervals* ( n insn -- )
21 uses-vregs [ update-live-interval ] with each ;
23 : sort-live-intervals ( assoc -- seq' )
24 #! Sort by increasing start location.
25 values [ [ start>> ] compare ] sort ;
27 : compute-live-intervals ( instructions -- live-intervals )
30 [ swap compute-live-intervals* ] each-index
32 ] keep sort-live-intervals ;