]> gitweb.factorcode.org Git - factor.git/blob - unfinished/compiler/machine/linear-scan/live-intervals/live-intervals.factor
Merge branch 'master' of git://factorcode.org/git/factor
[factor.git] / unfinished / compiler / machine / linear-scan / live-intervals / live-intervals.factor
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
6
7 TUPLE: live-interval < identity-tuple vreg start end ;
8
9 M: live-interval hashcode* nip [ start>> ] [ end>> 1000 * ] bi + ;
10
11 ! Mapping from vreg to live-interval
12 SYMBOL: live-intervals
13
14 : update-live-interval ( n vreg -- )
15     >vreg
16     live-intervals get
17     [ over f live-interval boa ] cache
18     (>>end) ;
19
20 : compute-live-intervals* ( n insn -- )
21     uses-vregs [ update-live-interval ] with each ;
22
23 : sort-live-intervals ( assoc -- seq' )
24     #! Sort by increasing start location.
25     values [ [ start>> ] compare ] sort ;
26
27 : compute-live-intervals ( instructions -- live-intervals )
28     H{ } clone [
29         live-intervals [
30             [ swap compute-live-intervals* ] each-index
31         ] with-variable
32     ] keep sort-live-intervals ;