2011-06-25 19:50:05 -04:00
|
|
|
! Copyright (C) 2011 Alex Vondrak.
|
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
2011-06-28 20:58:55 -04:00
|
|
|
USING: accessors assocs hashtables kernel namespaces sequences
|
2017-06-27 13:03:41 -04:00
|
|
|
sets
|
2011-06-28 20:58:55 -04:00
|
|
|
compiler.cfg
|
2011-06-27 18:12:07 -04:00
|
|
|
compiler.cfg.dataflow-analysis
|
|
|
|
compiler.cfg.def-use
|
2011-06-28 20:58:55 -04:00
|
|
|
compiler.cfg.gvn.graph
|
|
|
|
compiler.cfg.predecessors
|
2012-08-10 16:20:01 -04:00
|
|
|
compiler.cfg.renaming.functor
|
2017-02-08 12:30:31 -05:00
|
|
|
compiler.cfg.rpo
|
|
|
|
compiler.utilities ;
|
2011-06-25 19:50:05 -04:00
|
|
|
IN: compiler.cfg.gvn.avail
|
|
|
|
|
|
|
|
: defined ( bb -- vregs )
|
2011-06-27 18:12:07 -04:00
|
|
|
instructions>> [ defs-vregs ] map concat unique ;
|
|
|
|
|
|
|
|
! This doesn't propagate across "kill blocks". Not sure if
|
|
|
|
! that's right, though I may as well assume as much.
|
2011-06-25 19:50:05 -04:00
|
|
|
|
|
|
|
FORWARD-ANALYSIS: avail
|
|
|
|
|
2016-03-16 09:37:33 -04:00
|
|
|
M: avail transfer-set drop defined assoc-union ;
|
2011-06-25 19:50:05 -04:00
|
|
|
|
2012-08-10 16:20:01 -04:00
|
|
|
: available? ( vn -- ? ) basic-block get avail-in key? ;
|
2011-06-28 20:58:55 -04:00
|
|
|
|
2017-06-27 13:03:41 -04:00
|
|
|
: best-vreg ( available-vregs -- vreg )
|
|
|
|
[ f ] [ infimum ] if-empty ;
|
|
|
|
|
2012-08-10 16:20:01 -04:00
|
|
|
: >avail-vreg ( vreg -- vreg/f )
|
2011-06-28 20:58:55 -04:00
|
|
|
final-iteration? get [
|
2017-06-27 13:03:41 -04:00
|
|
|
congruence-class [ available? ] filter best-vreg
|
2012-08-10 16:20:01 -04:00
|
|
|
] when ;
|
2011-06-28 20:58:55 -04:00
|
|
|
|
|
|
|
: available-uses? ( insn -- ? )
|
2012-08-10 16:20:01 -04:00
|
|
|
uses-vregs [ >avail-vreg ] all? ;
|
2011-06-28 20:58:55 -04:00
|
|
|
|
|
|
|
: with-available-uses? ( quot -- ? )
|
2011-07-03 17:02:02 -04:00
|
|
|
keep swap [ available-uses? ] [ drop f ] if ; inline
|
2011-06-25 19:50:05 -04:00
|
|
|
|
2011-07-05 22:19:30 -04:00
|
|
|
: make-available ( vreg -- )
|
2015-08-12 12:08:24 -04:00
|
|
|
basic-block get avail-ins get [ dupd clone ?set-at ] assocs:change-at ;
|
2012-08-10 16:20:01 -04:00
|
|
|
|
|
|
|
RENAMING: >avail [ ] [ dup >avail-vreg swap or ] [ ]
|