]> gitweb.factorcode.org Git - factor.git/blob - extra/compiler/cfg/gvn/avail/avail.factor
factor: arch -> arch-name. fix breakage caused by other patch.
[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 hashtables kernel namespaces sequences
4 sets
5 compiler.cfg
6 compiler.cfg.dataflow-analysis
7 compiler.cfg.def-use
8 compiler.cfg.gvn.graph
9 compiler.cfg.predecessors
10 compiler.cfg.renaming.functor
11 compiler.cfg.rpo ;
12 FROM: namespaces => set ;
13 QUALIFIED: assocs
14 IN: compiler.cfg.gvn.avail
15
16 : defined ( bb -- vregs )
17     instructions>> [ defs-vregs ] map concat unique ;
18
19 ! This doesn't propagate across "kill blocks".  Not sure if
20 ! that's right, though I may as well assume as much.
21
22 FORWARD-ANALYSIS: avail
23
24 M: avail-analysis transfer-set drop defined assoc-union ;
25
26 : available? ( vn -- ? ) basic-block get avail-in key? ;
27
28 : best-vreg ( available-vregs -- vreg )
29     [ f ] [ infimum ] if-empty ;
30
31 : >avail-vreg ( vreg -- vreg/f )
32     final-iteration? get [
33         congruence-class [ available? ] filter best-vreg
34     ] when ;
35
36 : available-uses? ( insn -- ? )
37     uses-vregs [ >avail-vreg ] all? ;
38
39 : with-available-uses? ( quot -- ? )
40     keep swap [ available-uses? ] [ drop f ] if ; inline
41
42 : make-available ( vreg -- )
43     basic-block get avail-ins get [ dupd clone ?set-at ] assocs:change-at ;
44
45 RENAMING: >avail [ ] [ dup >avail-vreg swap or ] [ ]