]> gitweb.factorcode.org Git - factor.git/blob - basis/compiler/tree/escape-analysis/branches/branches.factor
Merge branch 'master' into experimental
[factor.git] / basis / compiler / tree / escape-analysis / branches / branches.factor
1 ! Copyright (C) 2008 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors kernel namespaces sequences sets fry columns
4 grouping stack-checker.branches
5 compiler.tree
6 compiler.tree.propagation.branches
7 compiler.tree.escape-analysis.nodes
8 compiler.tree.escape-analysis.allocations ;
9 IN: compiler.tree.escape-analysis.branches
10
11 M: #branch escape-analysis*
12     [ in-d>> add-escaping-values ]
13     [ live-children sift [ (escape-analysis) ] each ]
14     bi ;
15
16 : (merge-allocations) ( values -- allocation )
17     [
18         dup [ allocation ] map sift [ drop f ] [
19             dup [ t eq? not ] all? [
20                 dup [ length ] map all-equal? [
21                     nip flip
22                     [ (merge-allocations) ] [ [ merge-slots ] map ] bi
23                     [ record-allocations ] keep
24                 ] [ drop add-escaping-values t ] if
25             ] [ drop add-escaping-values t ] if
26         ] if-empty
27     ] map ;
28
29 : merge-allocations ( in-values out-values -- )
30     [ [ remove-bottom ] map ] dip
31     [ [ merge-values ] 2each ]
32     [ [ (merge-allocations) ] dip record-allocations ]
33     2bi ;
34
35 M: #phi escape-analysis*
36     [ phi-in-d>> flip ] [ out-d>> ] bi merge-allocations ;