! Copyright (C) 2008, 2010 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
-USING: namespaces kernel assocs accessors locals sequences math
-math.order fry combinators binary-search
-compiler.cfg.instructions
-compiler.cfg.registers
-compiler.cfg.def-use
-compiler.cfg.liveness
-compiler.cfg.linearization
-compiler.cfg.ssa.destruction.leaders
-compiler.cfg
-cpu.architecture ;
+USING: accessors assocs binary-search combinators
+compiler.cfg.def-use compiler.cfg.instructions
+compiler.cfg.linearization compiler.cfg.liveness
+compiler.cfg.registers compiler.cfg.ssa.destruction.leaders cpu.architecture
+fry kernel locals math math.intervals math.order namespaces sequences ;
IN: compiler.cfg.linear-scan.live-intervals
TUPLE: live-range from to ;
SYMBOLS: from to ;
-! Mapping from vreg to live-interval
SYMBOL: live-intervals
: live-interval ( vreg -- live-interval )
[ live-interval add-range ] 2with each
] if ;
-! A location where all registers have to be spilled
TUPLE: sync-point n keep-dst? ;
C: <sync-point> sync-point
-! Sequence of sync points
SYMBOL: sync-points
GENERIC: compute-sync-points* ( insn -- )
M: insn compute-sync-points* drop ;
: compute-live-intervals-step ( bb -- )
- dup kill-block?>> [ drop ] [
- {
- [ block-from from set ]
- [ block-to to set ]
- [ handle-live-out ]
- [
- instructions>> <reversed> [
- [ compute-live-intervals* ]
- [ compute-sync-points* ]
- bi
- ] each
- ]
- } cleave
- ] if ;
+ {
+ [ block-from from set ]
+ [ block-to to set ]
+ [ handle-live-out ]
+ [
+ instructions>> <reversed> [
+ [ compute-live-intervals* ]
+ [ compute-sync-points* ]
+ bi
+ ] each
+ ]
+ } cleave ;
: init-live-intervals ( -- )
H{ } clone live-intervals set
dup start>> -1 = [ bad-live-interval ] [ drop ] if ;
: finish-live-intervals ( live-intervals -- seq )
- ! Since live intervals are computed in a backward order, we have
- ! to reverse some sequences, and compute the start and end.
values dup [
{
[ [ { } like reverse! ] change-ranges drop ]
: compute-live-intervals ( cfg -- live-intervals sync-points )
init-live-intervals
- linearization-order <reversed> [ compute-live-intervals-step ] each
+ linearization-order <reversed> [ kill-block?>> ] reject
+ [ compute-live-intervals-step ] each
live-intervals get finish-live-intervals
sync-points get ;