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