]> gitweb.factorcode.org Git - factor.git/blob - unfinished/compiler/cfg.bluesky/vn/liveness/liveness.factor
Merge branch 'master' of git://factorcode.org/git/factor
[factor.git] / unfinished / compiler / cfg.bluesky / vn / liveness / liveness.factor
1 ! Copyright (C) 2008 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: namespaces kernel assocs sets accessors compiler.vops
4 compiler.cfg.vn.graph compiler.cfg.vn.expressions ;
5 IN: compiler.cfg.vn.liveness
6
7 ! A set of VNs which are (transitively) used by effect-ops. This
8 ! is precisely the set of VNs whose value is needed outside of
9 ! the basic block.
10 SYMBOL: live-vns
11
12 GENERIC: live-expr ( expr -- )
13
14 : live-vn ( vn -- )
15     #! Mark a VN and all VNs used in its computation as live.
16     dup live-vns get key? [ drop ] [
17         [ live-vns get conjoin ] [ vn>expr live-expr ] bi
18     ] if ;
19
20 : live-vreg ( vreg -- ) vreg>vn live-vn ;
21
22 M: expr live-expr drop ;
23 M: literal-expr live-expr in>> live-vn ;
24 M: unary-expr live-expr in>> live-vn ;
25 M: binary-expr live-expr [ in1>> live-vn ] [ in2>> live-vn ] bi ;
26
27 : live? ( vreg -- ? )
28     dup vreg>vn tuck vn>vreg =
29     [ live-vns get key? ] [ drop f ] if ;
30
31 : init-liveness ( -- )
32     H{ } clone live-vns set ;
33
34 GENERIC: eliminate ( insn -- insn' )
35
36 M: flushable-op eliminate dup out>> live? ?nop ;
37 M: vop eliminate ;