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