2009-07-24 20:46:33 -04:00
|
|
|
! Copyright (C) 2009 Slava Pestov.
|
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
2014-12-13 19:10:21 -05:00
|
|
|
USING: assocs compiler.cfg.instructions compiler.cfg.registers
|
|
|
|
compiler.cfg.ssa.destruction.leaders cpu.architecture deques
|
2014-12-21 23:57:53 -05:00
|
|
|
dlists fry kernel locals make namespaces sequences ;
|
2015-08-12 09:49:02 -04:00
|
|
|
QUALIFIED: sets
|
2009-07-24 20:46:33 -04:00
|
|
|
IN: compiler.cfg.parallel-copy
|
|
|
|
|
2009-07-27 17:54:47 -04:00
|
|
|
<PRIVATE
|
2009-07-24 20:46:33 -04:00
|
|
|
|
2011-01-17 18:16:17 -05:00
|
|
|
SYMBOLS: locs preds to-do ready ;
|
2009-07-24 20:46:33 -04:00
|
|
|
|
2009-07-27 17:54:47 -04:00
|
|
|
: init-to-do ( bs -- )
|
|
|
|
to-do get push-all-back ;
|
2009-07-24 20:46:33 -04:00
|
|
|
|
2009-07-27 17:54:47 -04:00
|
|
|
: init-ready ( bs -- )
|
2015-05-12 21:50:34 -04:00
|
|
|
locs get '[ _ key? ] reject ready get push-all-front ;
|
2009-07-24 20:46:33 -04:00
|
|
|
|
2011-01-17 18:16:17 -05:00
|
|
|
: init ( mapping -- )
|
2009-07-27 17:54:47 -04:00
|
|
|
<dlist> to-do set
|
|
|
|
<dlist> ready set
|
2009-07-28 09:47:35 -04:00
|
|
|
[ preds set ]
|
2009-07-27 17:54:47 -04:00
|
|
|
[ [ nip dup ] H{ } assoc-map-as locs set ]
|
|
|
|
[ keys [ init-to-do ] [ init-ready ] bi ] tri ;
|
2009-07-24 20:46:33 -04:00
|
|
|
|
2011-01-17 18:16:17 -05:00
|
|
|
:: process-ready ( b quot: ( dst src -- ) -- )
|
2009-07-27 17:54:47 -04:00
|
|
|
b preds get at :> a
|
|
|
|
a locs get at :> c
|
|
|
|
b c quot call
|
|
|
|
b a locs get set-at
|
|
|
|
a c = a preds get at and [ a ready get push-front ] when ; inline
|
2009-07-24 20:46:33 -04:00
|
|
|
|
2011-01-17 18:16:17 -05:00
|
|
|
:: process-to-do ( b temp: ( src -- dst ) quot: ( dst src -- ) -- )
|
2009-07-27 17:54:47 -04:00
|
|
|
b locs get at b = [
|
2011-01-17 18:16:17 -05:00
|
|
|
b temp call :> temp
|
|
|
|
temp b quot call
|
|
|
|
temp b locs get set-at
|
2009-07-27 17:54:47 -04:00
|
|
|
b ready get push-front
|
|
|
|
] when ; inline
|
2009-07-24 20:46:33 -04:00
|
|
|
|
2009-07-27 17:54:47 -04:00
|
|
|
PRIVATE>
|
|
|
|
|
2011-01-17 18:16:17 -05:00
|
|
|
:: parallel-mapping ( mapping temp: ( src -- dst ) quot: ( dst src -- ) -- )
|
2009-07-24 20:46:33 -04:00
|
|
|
[
|
2011-01-17 18:16:17 -05:00
|
|
|
mapping init
|
2009-07-27 17:54:47 -04:00
|
|
|
to-do get [
|
|
|
|
ready get [
|
|
|
|
quot process-ready
|
|
|
|
] slurp-deque
|
2011-01-17 18:16:17 -05:00
|
|
|
temp quot process-to-do
|
2009-07-27 17:54:47 -04:00
|
|
|
] slurp-deque
|
|
|
|
] with-scope ; inline
|
|
|
|
|
2014-12-21 23:57:53 -05:00
|
|
|
: parallel-copy ( mapping -- insns )
|
|
|
|
[ next-vreg '[ drop _ ] [ any-rep ##copy, ] parallel-mapping ] { } make ;
|
2011-01-17 18:16:17 -05:00
|
|
|
|
|
|
|
<PRIVATE
|
|
|
|
|
|
|
|
SYMBOL: temp-vregs
|
|
|
|
|
|
|
|
: temp-vreg ( rep -- vreg )
|
2012-12-28 11:51:16 -05:00
|
|
|
temp-vregs get [ next-vreg-rep ] cache
|
2015-08-12 09:49:02 -04:00
|
|
|
[ leader-map get sets:conjoin ] keep ;
|
2011-01-17 18:16:17 -05:00
|
|
|
|
|
|
|
PRIVATE>
|
|
|
|
|
2014-12-21 23:57:53 -05:00
|
|
|
: parallel-copy-rep ( mapping -- insns )
|
|
|
|
[
|
|
|
|
H{ } clone temp-vregs set
|
|
|
|
[ rep-of temp-vreg ] [ dup rep-of ##copy, ] parallel-mapping
|
|
|
|
] { } make ;
|