]> gitweb.factorcode.org Git - factor.git/blob - extra/compiler/cfg/gvn/avail/avail.factor
compiler.cfg.gvn.avail: add a FROM: to clarify collision over change-at word
[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.rpo ;
11 FROM: assocs => change-at ;
12 FROM: namespaces => set ;
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-analysis transfer-set drop defined assoc-union ;
24
25 ! Strict idea of availability, for now.  Would like to see if
26 ! searching the VN congruence classes for the smallest
27 ! available vn would work at all / better.
28
29 : available? ( vn -- ? )
30     final-iteration? get [
31         basic-block get avail-in key?
32     ] [ drop t ] if ;
33
34 : available-uses? ( insn -- ? )
35     uses-vregs [ available? ] all? ;
36
37 : with-available-uses? ( quot -- ? )
38     keep swap [ available-uses? ] [ drop f ] if ; inline
39
40 : make-available ( vreg -- )
41     basic-block get avail-ins get [ dupd clone ?set-at ] change-at ;