]> gitweb.factorcode.org Git - factor.git/blob - basis/compiler/tree/propagation/copy/copy.factor
Switch to https urls
[factor.git] / basis / compiler / tree / propagation / copy / copy.factor
1 ! Copyright (C) 2008 Slava Pestov.
2 ! See https://factorcode.org/license.txt for BSD license.
3 USING: accessors assocs compiler.tree compiler.tree.def-use
4 compiler.utilities grouping kernel namespaces sequences sets
5 stack-checker.branches ;
6 IN: compiler.tree.propagation.copy
7
8 SYMBOL: copies
9
10 : resolve-copy ( copy -- val ) copies get compress-path ;
11
12 : resolve-copies ( copies -- vals )
13     copies get [ compress-path ] curry map ;
14
15 : is-copy-of ( val copy -- ) copies get set-at ;
16
17 : are-copies-of ( vals copies -- ) [ is-copy-of ] 2each ;
18
19 : introduce-value ( val -- ) copies get conjoin ;
20
21 : introduce-values ( vals -- )
22     copies get [ conjoin ] curry each ;
23
24 GENERIC: compute-copy-equiv* ( node -- )
25
26 M: #renaming compute-copy-equiv* inputs/outputs are-copies-of ;
27
28 : compute-phi-equiv ( inputs outputs -- )
29     [
30         swap remove-bottom resolve-copies
31         dup [ f ] [ all-equal? ] if-empty
32         [ first swap is-copy-of ] [ 2drop ] if
33     ] 2each ;
34
35 M: #phi compute-copy-equiv*
36     [ phi-in-d>> flip ] [ out-d>> ] bi compute-phi-equiv ;
37
38 M: node compute-copy-equiv* drop ;
39
40 : compute-copy-equiv ( node -- )
41     [ node-defs-values introduce-values ]
42     [ compute-copy-equiv* ]
43     bi ;