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
10 M: #branch escape-analysis*
11 [ in-d>> add-escaping-values ]
12 [ live-children [ [ (escape-analysis) ] when* ] each ]
15 : (merge-allocations) ( values -- allocation )
17 dup [ allocation ] map sift [ drop f ] [
18 dup [ t eq? not ] all? [
19 dup [ length ] map all-equal? [
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
28 : merge-allocations ( in-values out-values -- )
29 [ [ remove-bottom ] map ] dip
30 [ [ merge-values ] 2each ]
31 [ [ (merge-allocations) ] dip record-allocations ]
34 M: #phi escape-analysis*
35 [ phi-in-d>> flip ] [ out-d>> ] bi merge-allocations ;