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 compiler.cfg.ssa.destruction.leaders
5 deques dlists fry kernel locals namespaces sequences hashtables ;
6 FROM: sets => conjoin ;
7 IN: compiler.cfg.parallel-copy
9 ! Revisiting Out-of-SSA Translation for Correctness, Code Quality, and Efficiency
10 ! http://hal.archives-ouvertes.fr/docs/00/34/99/25/PDF/OutSSA-RR.pdf,
15 SYMBOLS: locs preds to-do ready ;
17 : init-to-do ( bs -- )
18 to-do get push-all-back ;
20 : init-ready ( bs -- )
21 locs get '[ _ key? not ] filter ready get push-all-front ;
27 [ [ nip dup ] H{ } assoc-map-as locs set ]
28 [ keys [ init-to-do ] [ init-ready ] bi ] tri ;
30 :: process-ready ( b quot: ( dst src -- ) -- )
35 a c = a preds get at and [ a ready get push-front ] when ; inline
37 :: process-to-do ( b temp: ( src -- dst ) quot: ( dst src -- ) -- )
38 ! Note that we check if b = loc(b), not b = loc(pred(b)) as the
39 ! paper suggests. Confirmed by one of the authors at
40 ! http://www.reddit.com/comments/93253/some_lecture_notes_on_ssa_form/c0bco4f
44 temp b locs get set-at
45 b ready get push-front
50 :: parallel-mapping ( mapping temp: ( src -- dst ) quot: ( dst src -- ) -- )
51 ! mapping is a list of { dst src } pairs
58 temp quot process-to-do
62 : parallel-copy ( mapping -- )
63 ! mapping is a list of { dst src } pairs
64 next-vreg '[ drop _ ] [ any-rep ##copy, ] parallel-mapping ;
70 : temp-vreg ( rep -- vreg )
71 temp-vregs get [ next-vreg-rep ] cache
72 [ leader-map get conjoin ] keep ;
76 : parallel-copy-rep ( mapping -- )
77 ! mapping is a list of { dst src } pairs
78 H{ } clone temp-vregs set
79 [ rep-of temp-vreg ] [ dup rep-of ##copy, ] parallel-mapping ;