factor/unfinished/compiler/tree/escape-analysis/branches/branches.factor

34 lines
1.1 KiB
Factor
Raw Normal View History

2008-08-02 00:31:43 -04:00
! Copyright (C) 2008 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
2008-08-03 22:32:12 -04:00
USING: accessors kernel namespaces sequences sets fry
2008-08-02 21:21:25 -04:00
stack-checker.branches
2008-08-02 00:31:43 -04:00
compiler.tree
compiler.tree.propagation.branches
compiler.tree.escape-analysis.nodes
compiler.tree.escape-analysis.allocations ;
IN: compiler.tree.escape-analysis.branches
M: #branch escape-analysis*
live-children sift [ (escape-analysis) ] each ;
: (merge-allocations) ( values -- allocation )
[
2008-08-03 22:32:12 -04:00
dup [ allocation ] map dup [ ] all? [
2008-08-02 00:31:43 -04:00
dup [ length ] map all-equal? [
2008-08-03 22:32:12 -04:00
nip flip
2008-08-02 00:31:43 -04:00
[ (merge-allocations) ] [ [ merge-slots ] map ] bi
[ record-allocations ] keep
2008-08-03 22:32:12 -04:00
] [ drop add-escaping-values f ] if
] [ drop add-escaping-values f ] if
2008-08-02 00:31:43 -04:00
] map ;
: merge-allocations ( in-values out-values -- )
2008-08-03 22:32:12 -04:00
[ [ merge-values ] 2each ]
[ [ (merge-allocations) ] dip record-allocations ]
2bi ;
2008-08-02 00:31:43 -04:00
M: #phi escape-analysis*
[ [ phi-in-d>> ] [ out-d>> ] bi merge-allocations ]
[ [ phi-in-r>> ] [ out-r>> ] bi merge-allocations ]
bi ;