]> gitweb.factorcode.org Git - factor.git/blob - extra/compiler/cfg/gvn/avail/avail.factor
768850df8b3c5470f3b320ba9b30e776bb471078
[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 compiler.utilities ;
13 IN: compiler.cfg.gvn.avail
14
15 : defined ( bb -- vregs )
16     instructions>> [ defs-vregs ] map concat unique ;
17
18 ! This doesn't propagate across "kill blocks".  Not sure if
19 ! that's right, though I may as well assume as much.
20
21 FORWARD-ANALYSIS: avail
22
23 M: avail transfer-set drop defined assoc-union ;
24
25 : available? ( vn -- ? ) basic-block get avail-in key? ;
26
27 : best-vreg ( available-vregs -- vreg )
28     [ f ] [ infimum ] if-empty ;
29
30 : >avail-vreg ( vreg -- vreg/f )
31     final-iteration? get [
32         congruence-class [ available? ] filter best-vreg
33     ] when ;
34
35 : available-uses? ( insn -- ? )
36     uses-vregs [ >avail-vreg ] all? ;
37
38 : with-available-uses? ( quot -- ? )
39     keep swap [ available-uses? ] [ drop f ] if ; inline
40
41 : make-available ( vreg -- )
42     basic-block get avail-ins get [ dupd clone ?set-at ] assocs:change-at ;
43
44 RENAMING: >avail [ ] [ dup >avail-vreg swap or ] [ ]