]> gitweb.factorcode.org Git - factor.git/blob - extra/compiler/cfg/gvn/avail/avail.factor
factor: trim using lists
[factor.git] / extra / compiler / cfg / gvn / avail / avail.factor
1 ! Copyright (C) 2011 Alex Vondrak.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors assocs compiler.cfg
4 compiler.cfg.dataflow-analysis compiler.cfg.def-use
5 compiler.cfg.gvn.graph compiler.cfg.renaming.functor
6 compiler.utilities hashtables kernel namespaces sequences ;
7 IN: compiler.cfg.gvn.avail
8
9 : defined ( bb -- vregs )
10     instructions>> [ defs-vregs ] map concat unique ;
11
12 ! This doesn't propagate across "kill blocks".  Not sure if
13 ! that's right, though I may as well assume as much.
14
15 FORWARD-ANALYSIS: avail
16
17 M: avail transfer-set drop defined assoc-union ;
18
19 : available? ( vn -- ? ) basic-block get avail-in key? ;
20
21 : best-vreg ( available-vregs -- vreg )
22     [ f ] [ infimum ] if-empty ;
23
24 : >avail-vreg ( vreg -- vreg/f )
25     final-iteration? get [
26         congruence-class [ available? ] filter best-vreg
27     ] when ;
28
29 : available-uses? ( insn -- ? )
30     uses-vregs [ >avail-vreg ] all? ;
31
32 : with-available-uses? ( quot -- ? )
33     keep swap [ available-uses? ] [ drop f ] if ; inline
34
35 : make-available ( vreg -- )
36     basic-block get avail-ins get [ dupd clone ?set-at ] assocs:change-at ;
37
38 RENAMING: >avail [ ] [ dup >avail-vreg swap or ] [ ]