1 ! Copyright (C) 2009 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: assocs cpu.architecture compiler.cfg.registers
4 compiler.cfg.instructions deques dlists fry kernel locals namespaces
6 IN: compiler.cfg.parallel-copy
8 ! Revisiting Out-of-SSA Translation for Correctness, Code Quality, and Efficiency
9 ! http://hal.archives-ouvertes.fr/docs/00/34/99/25/PDF/OutSSA-RR.pdf,
14 SYMBOLS: locs preds to-do ready ;
16 : init-to-do ( bs -- )
17 to-do get push-all-back ;
19 : init-ready ( bs -- )
20 locs get '[ _ key? not ] filter ready get push-all-front ;
26 [ [ nip dup ] H{ } assoc-map-as locs set ]
27 [ keys [ init-to-do ] [ init-ready ] bi ] tri ;
29 :: process-ready ( b quot: ( dst src -- ) -- )
34 a c = a preds get at and [ a ready get push-front ] when ; inline
36 :: process-to-do ( b temp: ( src -- dst ) quot: ( dst src -- ) -- )
37 ! Note that we check if b = loc(b), not b = loc(pred(b)) as the
38 ! paper suggests. Confirmed by one of the authors at
39 ! http://www.reddit.com/comments/93253/some_lecture_notes_on_ssa_form/c0bco4f
43 temp b locs get set-at
44 b ready get push-front
49 :: parallel-mapping ( mapping temp: ( src -- dst ) quot: ( dst src -- ) -- )
50 ! mapping is a list of { dst src } pairs
57 temp quot process-to-do
61 : parallel-copy ( mapping -- )
62 ! mapping is a list of { dst src } pairs
63 next-vreg '[ drop _ ] [ any-rep ##copy ] parallel-mapping ;
69 : temp-vreg ( rep -- vreg )
70 temp-vregs get [ next-vreg-rep ] cache ;
74 : parallel-copy-rep ( mapping -- )
75 ! mapping is a list of { dst src } pairs
76 H{ } clone temp-vregs set
77 [ rep-of temp-vreg ] [ dup rep-of ##copy ] parallel-mapping ;