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
10 : resolve-copy ( copy -- val ) copies get compress-path ;
12 : resolve-copies ( copies -- vals )
13 copies get [ compress-path ] curry map ;
15 : is-copy-of ( val copy -- ) copies get set-at ;
17 : are-copies-of ( vals copies -- ) [ is-copy-of ] 2each ;
19 : introduce-value ( val -- ) copies get conjoin ;
21 : introduce-values ( vals -- )
22 copies get [ conjoin ] curry each ;
24 GENERIC: compute-copy-equiv* ( node -- )
26 M: #renaming compute-copy-equiv* inputs/outputs are-copies-of ;
28 : compute-phi-equiv ( inputs outputs -- )
30 swap remove-bottom resolve-copies
31 dup [ f ] [ all-equal? ] if-empty
32 [ first swap is-copy-of ] [ 2drop ] if
35 M: #phi compute-copy-equiv*
36 [ phi-in-d>> flip ] [ out-d>> ] bi compute-phi-equiv ;
38 M: node compute-copy-equiv* drop ;
40 : compute-copy-equiv ( node -- )
41 [ node-defs-values introduce-values ]
42 [ compute-copy-equiv* ]