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

67 lines
1.8 KiB
Factor
Raw Normal View History

! Copyright (C) 2008, 2009 Slava Pestov.
2008-09-10 23:11:03 -04:00
! 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
2008-11-02 02:49:57 -05:00
start end uses
copy-from ;
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
GENERIC: compute-live-intervals* ( insn -- )
2008-11-02 02:49:57 -05:00
M: insn compute-live-intervals* drop ;
2008-11-02 04:58:32 -05:00
M: vreg-insn compute-live-intervals*
dup insn#>>
2008-09-15 02:54:48 -04:00
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 ]
[ [ temp-vregs ] 2dip '[ _ swap _ new-live-interval ] each ]
3tri ;
2008-09-10 23:11:03 -04:00
2008-11-02 02:49:57 -05:00
: record-copy ( insn -- )
[ dst>> live-intervals get at ] [ src>> ] bi >>copy-from drop ;
M: ##copy compute-live-intervals*
[ call-next-method ] [ record-copy ] bi ;
2008-11-02 02:49:57 -05:00
M: ##copy-float compute-live-intervals*
[ call-next-method ] [ record-copy ] bi ;
2008-11-02 02:49:57 -05:00
: compute-live-intervals ( rpo -- live-intervals )
2008-09-15 05:22:12 -04:00
H{ } clone [
live-intervals set
[ instructions>> [ compute-live-intervals* ] each ] each
2008-10-19 02:10:21 -04:00
] keep values ;