]> gitweb.factorcode.org Git - factor.git/blob - basis/compiler/cfg/parallel-copy/parallel-copy.factor
Merge branch 'master' of git@github.com:prunedtree/factor
[factor.git] / basis / compiler / cfg / parallel-copy / parallel-copy.factor
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
5 sequences hashtables ;
6 IN: compiler.cfg.parallel-copy
7
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,
10 ! Algorithm 1
11
12 <PRIVATE
13
14 SYMBOLS: temp locs preds to-do ready ;
15
16 : init-to-do ( bs -- )
17     to-do get push-all-back ;
18
19 : init-ready ( bs -- )
20     locs get '[ _ key? not ] filter ready get push-all-front ;
21
22 : init ( mapping temp -- )
23     temp set
24     <dlist> to-do set
25     <dlist> ready set
26     [ preds set ]
27     [ [ nip dup ] H{ } assoc-map-as locs set ]
28     [ keys [ init-to-do ] [ init-ready ] bi ] tri ;
29
30 :: process-ready ( b quot -- )
31     b preds get at :> a
32     a locs get at :> c
33     b c quot call
34     b a locs get set-at
35     a c = a preds get at and [ a ready get push-front ] when ; inline
36
37 :: process-to-do ( b quot -- )
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
41     b locs get at b = [
42         temp get b quot call
43         temp get b locs get set-at
44         b ready get push-front
45     ] when ; inline
46
47 PRIVATE>
48
49 :: parallel-mapping ( mapping temp quot -- )
50     [
51         mapping temp init
52         to-do get [
53             ready get [
54                 quot process-ready
55             ] slurp-deque
56             quot process-to-do
57         ] slurp-deque
58     ] with-scope ; inline
59
60 : parallel-copy ( mapping -- )
61     next-vreg [ any-rep ##copy ] parallel-mapping ;