factor/unfinished/compiler/tree/propagation/recursive/recursive.factor

63 lines
2.1 KiB
Factor
Raw Normal View History

2008-07-20 05:24:37 -04:00
! Copyright (C) 2008 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
USING: kernel sequences accessors arrays
stack-checker.inlining
2008-07-22 05:45:03 -04:00
compiler.tree
compiler.tree.propagation.info
compiler.tree.propagation.nodes
compiler.tree.propagation.simple
2008-07-20 05:24:37 -04:00
compiler.tree.propagation.branches ;
IN: compiler.tree.propagation.recursive
! What if we reach a fixed point for the phi but not for the
! #call-label output?
! We need to compute scalar evolution so that sccp doesn't
! evaluate loops
! row polymorphism is causing problems
! infer-branch cloning and subsequent loss of state causing problems
2008-07-22 05:45:03 -04:00
: merge-value-infos ( inputs -- infos )
[ [ value-info ] map value-infos-union ] map ;
USE: io
: compute-fixed-point ( label infos outputs -- )
2dup [ length ] bi@ = [ "Wrong length" throw ] unless
"compute-fixed-point" print USE: prettyprint
2dup [ value-info ] map 2dup . . [ = ] 2all? [ 3drop ] [
[ set-value-info ] 2each
f >>fixed-point drop
] if ;
2008-07-22 05:45:03 -04:00
: propagate-recursive-phi ( label #phi -- )
"propagate-recursive-phi" print
[ [ phi-in-d>> merge-value-infos ] [ out-d>> ] bi compute-fixed-point ]
[ [ phi-in-r>> merge-value-infos ] [ out-r>> ] bi compute-fixed-point ] 2bi ;
2008-07-22 05:45:03 -04:00
USING: namespaces math ;
SYMBOL: iter-counter
0 iter-counter set-global
2008-07-22 05:45:03 -04:00
M: #recursive propagate-around ( #recursive -- )
"#recursive" print
iter-counter inc
iter-counter get 10 > [ "Oops" throw ] when
[ label>> ] keep
[ node-child first>> propagate-recursive-phi ]
[ [ t >>fixed-point drop ] [ node-child first>> (propagate) ] bi* ]
[ swap fixed-point>> [ drop ] [ propagate-around ] if ]
2tri ; USE: assocs
2008-07-22 05:45:03 -04:00
M: #call-recursive propagate-before ( #call-label -- )
[ label>> ] [ label>> return>> [ value-info ] map ] [ out-d>> ] tri
dup [ dup value-infos get at [ drop ] [ object <class-info> swap set-value-info ] if ] each
2dup min-length [ tail* ] curry bi@
compute-fixed-point ;
M: #return propagate-before ( #return -- )
"#return" print
dup label>> [
[ label>> ] [ in-d>> [ value-info ] map ] [ in-d>> ] tri
compute-fixed-point
] [ drop ] if ;