1 ! Copyright (C) 2009 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors assocs fry kernel namespaces sequences math
4 arrays compiler.cfg.def-use compiler.cfg.instructions
5 compiler.cfg.liveness.ssa compiler.cfg.rpo compiler.cfg.dominance ;
6 IN: compiler.cfg.ssa.interference.live-ranges
8 ! Live ranges for interference testing
12 SYMBOLS: local-def-indices local-kill-indices ;
14 : record-def ( n insn -- )
15 ! We allow multiple defs of a vreg as long as they're
16 ! all in the same basic block
18 local-def-indices get 2dup key?
19 [ 3drop ] [ set-at ] if
22 : record-uses ( n insn -- )
23 ! Record live intervals so that all but the first input interfere
24 ! with the output. This lets us coalesce the output with the
26 [ uses-vregs ] [ def-is-use-insn? ] bi over empty? [ 3drop ] [
27 [ [ first local-kill-indices get set-at ] [ rest-slice ] 2bi ] unless
28 [ 1 + ] dip [ local-kill-indices get set-at ] with each
31 : visit-insn ( insn n -- )
32 2 * swap [ record-def ] [ record-uses ] 2bi ;
34 SYMBOLS: def-indices kill-indices ;
36 : compute-local-live-ranges ( bb -- )
37 H{ } clone local-def-indices set
38 H{ } clone local-kill-indices set
39 [ instructions>> [ visit-insn ] each-index ]
40 [ [ local-def-indices get ] dip def-indices get set-at ]
41 [ [ local-kill-indices get ] dip kill-indices get set-at ]
46 : compute-live-ranges ( cfg -- )
49 H{ } clone def-indices set
50 H{ } clone kill-indices set
51 [ compute-local-live-ranges ] each-basic-block ;
53 : def-index ( vreg bb -- n )
54 def-indices get at at ;
56 ERROR: bad-kill-index vreg bb ;
58 : kill-index ( vreg bb -- n )
59 2dup live-out? [ 2drop 1/0. ] [
60 2dup kill-indices get at at* [ 2nip ] [
62 [ bad-kill-index ] [ 2drop -1/0. ] if