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