1 ! Copyright (C) 2009 Slava Pestov.
2 ! See https://factorcode.org/license.txt for BSD license.
3 USING: assocs compiler.cfg.instructions compiler.cfg.registers
4 compiler.cfg.ssa.destruction.leaders compiler.utilities
5 cpu.architecture deques dlists kernel make namespaces sequences ;
6 IN: compiler.cfg.parallel-copy
10 SYMBOLS: locs preds to-do ready ;
12 : init-to-do ( bs -- )
13 to-do get push-all-back ;
15 : init-ready ( bs -- )
16 locs get '[ _ key? ] reject ready get push-all-front ;
22 [ [ nip dup ] H{ } assoc-map-as locs set ]
23 [ keys [ init-to-do ] [ init-ready ] bi ] tri ;
25 :: process-ready ( b quot: ( dst src -- ) -- )
30 a c = a preds get at and [ a ready get push-front ] when ; inline
32 :: process-to-do ( b temp: ( src -- dst ) quot: ( dst src -- ) -- )
36 temp b locs get set-at
37 b ready get push-front
42 :: parallel-mapping ( mapping temp: ( src -- dst ) quot: ( dst src -- ) -- )
49 temp quot process-to-do
53 : parallel-copy ( mapping -- insns )
54 [ next-vreg '[ drop _ ] [ any-rep ##copy, ] parallel-mapping ] { } make ;
60 : temp-vreg ( rep -- vreg )
61 temp-vregs get [ next-vreg-rep ] cache
62 [ leader-map get conjoin ] keep ;
66 : parallel-copy-rep ( mapping -- insns )
68 H{ } clone temp-vregs set
69 [ rep-of temp-vreg ] [ dup rep-of ##copy, ] parallel-mapping