1 ! Copyright (C) 2009, 2010 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: assocs compiler.cfg compiler.cfg.def-use
4 compiler.cfg.dominance compiler.cfg.instructions
5 compiler.cfg.liveness compiler.cfg.rpo kernel math namespaces
7 IN: compiler.cfg.ssa.interference.live-ranges
9 ! Live ranges for interference testing
13 SYMBOLS: local-def-indices local-kill-indices ;
15 : record-defs ( n insn -- )
16 defs-vregs [ local-def-indices get set-at ] with each ;
18 : record-uses ( n insn -- )
19 ! Record live intervals so that all but the first input interfere
20 ! with the output. This lets us coalesce the output with the
22 dup uses-vregs [ 2drop ] [
24 [ [ first local-kill-indices get set-at ] [ rest-slice ] 2bi ] unless
25 [ 1 + ] dip [ local-kill-indices get set-at ] with each
28 GENERIC: record-insn ( n insn -- )
33 M: ##parallel-copy record-insn
36 [ uses-vregs [ local-kill-indices get set-at ] with each ]
39 M: vreg-insn record-insn
40 [ 2 * ] dip [ record-defs ] [ record-uses ] 2bi ;
45 SYMBOLS: def-indices kill-indices ;
47 : compute-local-live-ranges ( insns -- )
48 H{ } clone local-def-indices set
49 H{ } clone local-kill-indices set
50 [ swap record-insn ] each-index
51 local-def-indices get basic-block get def-indices get set-at
52 local-kill-indices get basic-block get kill-indices get set-at ;
56 : compute-live-ranges ( cfg -- )
57 H{ } clone def-indices set
58 H{ } clone kill-indices set
60 [ [ compute-local-live-ranges ] simple-analysis ] bi ;
62 : def-index ( vreg bb -- n )
63 def-indices get at at ;
65 ERROR: bad-kill-index vreg bb ;
67 : kill-index ( vreg bb -- n )
68 2dup live-out? [ 2drop 1/0. ] [
69 2dup kill-indices get at at* [ 2nip ] [
71 [ bad-kill-index ] [ 2drop -1/0. ] if