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