factor/basis/compiler/tree/propagation/copy/copy.factor

44 lines
1.2 KiB
Factor
Raw Normal View History

! Copyright (C) 2008 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
2014-12-13 19:10:21 -05:00
USING: accessors assocs compiler.tree compiler.tree.def-use
compiler.utilities grouping kernel namespaces sequences sets
stack-checker.branches ;
2008-08-07 07:34:28 -04:00
IN: compiler.tree.propagation.copy
SYMBOL: copies
: resolve-copy ( copy -- val ) copies get compress-path ;
2008-08-01 21:00:12 -04:00
2013-03-21 22:11:20 -04:00
: resolve-copies ( copies -- vals )
copies get [ compress-path ] curry map ;
2008-08-01 21:00:12 -04:00
: is-copy-of ( val copy -- ) copies get set-at ;
2008-08-01 21:00:12 -04:00
: are-copies-of ( vals copies -- ) [ is-copy-of ] 2each ;
2008-08-01 21:00:12 -04:00
: introduce-value ( val -- ) copies get conjoin ;
2013-03-21 22:11:20 -04:00
: introduce-values ( vals -- )
copies get [ conjoin ] curry each ;
GENERIC: compute-copy-equiv* ( node -- )
2008-08-07 07:34:28 -04:00
M: #renaming compute-copy-equiv* inputs/outputs are-copies-of ;
2008-07-27 03:32:40 -04:00
: compute-phi-equiv ( inputs outputs -- )
[
2013-03-21 22:11:20 -04:00
swap remove-bottom resolve-copies
dup [ f ] [ all-equal? ] if-empty
[ first swap is-copy-of ] [ 2drop ] if
] 2each ;
M: #phi compute-copy-equiv*
[ phi-in-d>> flip ] [ out-d>> ] bi compute-phi-equiv ;
M: node compute-copy-equiv* drop ;
: compute-copy-equiv ( node -- )
2013-03-21 22:11:20 -04:00
[ node-defs-values introduce-values ]
[ compute-copy-equiv* ]
bi ;