factor/basis/compiler/cfg/linear-scan/live-intervals/live-intervals.factor

51 lines
1.3 KiB
Factor
Raw Normal View History

2008-09-10 23:11:03 -04:00
! Copyright (C) 2008 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
2008-09-15 02:54:48 -04:00
USING: namespaces kernel assocs accessors sequences math fry
2008-10-20 02:56:28 -04:00
compiler.cfg.instructions compiler.cfg.registers
compiler.cfg.def-use ;
2008-09-11 03:05:22 -04:00
IN: compiler.cfg.linear-scan.live-intervals
2008-09-10 23:11:03 -04:00
2008-10-19 02:10:21 -04:00
TUPLE: live-interval
2008-09-15 02:54:48 -04:00
vreg
reg spill-to reload-from split-before split-after
start end uses ;
2008-09-10 23:11:03 -04:00
2008-10-19 02:10:21 -04:00
: add-use ( n live-interval -- )
2008-10-22 22:58:37 -04:00
dup live-interval? [ "No def" throw ] unless
2008-10-19 02:10:21 -04:00
[ (>>end) ] [ uses>> push ] 2bi ;
2008-09-15 02:54:48 -04:00
: <live-interval> ( start vreg -- live-interval )
live-interval new
2008-10-19 02:10:21 -04:00
V{ } clone >>uses
2008-09-15 02:54:48 -04:00
swap >>vreg
2008-10-19 02:10:21 -04:00
over >>start
[ add-use ] keep ;
2008-09-15 02:54:48 -04:00
M: live-interval hashcode*
nip [ start>> ] [ end>> 1000 * ] bi + ;
M: live-interval clone
call-next-method [ clone ] change-uses ;
2008-09-10 23:11:03 -04:00
! Mapping from vreg to live-interval
SYMBOL: live-intervals
2008-09-15 02:54:48 -04:00
: new-live-interval ( n vreg live-intervals -- )
2008-10-28 05:38:37 -04:00
2dup key? [
at add-use
] [
[ [ <live-interval> ] keep ] dip set-at
] if ;
2008-09-15 02:54:48 -04:00
: compute-live-intervals* ( insn n -- )
live-intervals get
2008-10-19 02:10:21 -04:00
[ [ uses-vregs ] 2dip '[ _ swap _ at add-use ] each ]
2008-09-15 05:22:12 -04:00
[ [ defs-vregs ] 2dip '[ _ swap _ new-live-interval ] each ]
2008-09-15 02:54:48 -04:00
3bi ;
2008-09-10 23:11:03 -04:00
2008-09-15 05:22:12 -04:00
: compute-live-intervals ( instructions -- live-intervals )
H{ } clone [
live-intervals set
[ compute-live-intervals* ] each-index
2008-10-19 02:10:21 -04:00
] keep values ;