1 ! Copyright (C) 2009 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: assocs compiler.cfg.instructions compiler.cfg.registers
4 compiler.cfg.ssa.destruction.leaders cpu.architecture deques
5 dlists fry kernel locals make namespaces sequences ;
6 FROM: sets => conjoin ;
7 IN: compiler.cfg.parallel-copy
11 SYMBOLS: locs preds to-do ready ;
13 : init-to-do ( bs -- )
14 to-do get push-all-back ;
16 : init-ready ( bs -- )
17 locs get '[ _ key? ] reject ready get push-all-front ;
23 [ [ nip dup ] H{ } assoc-map-as locs set ]
24 [ keys [ init-to-do ] [ init-ready ] bi ] tri ;
26 :: process-ready ( b quot: ( dst src -- ) -- )
31 a c = a preds get at and [ a ready get push-front ] when ; inline
33 :: process-to-do ( b temp: ( src -- dst ) quot: ( dst src -- ) -- )
37 temp b locs get set-at
38 b ready get push-front
43 :: parallel-mapping ( mapping temp: ( src -- dst ) quot: ( dst src -- ) -- )
50 temp quot process-to-do
54 : parallel-copy ( mapping -- insns )
55 [ next-vreg '[ drop _ ] [ any-rep ##copy, ] parallel-mapping ] { } make ;
61 : temp-vreg ( rep -- vreg )
62 temp-vregs get [ next-vreg-rep ] cache
63 [ leader-map get conjoin ] keep ;
67 : parallel-copy-rep ( mapping -- insns )
69 H{ } clone temp-vregs set
70 [ rep-of temp-vreg ] [ dup rep-of ##copy, ] parallel-mapping