]> gitweb.factorcode.org Git - factor.git/blob - basis/compiler/cfg/stacks/finalize/finalize.factor
Switch to https urls
[factor.git] / basis / compiler / cfg / stacks / finalize / finalize.factor
1 ! Copyright (C) 2009 Slava Pestov.
2 ! See https://factorcode.org/license.txt for BSD license.
3 USING: accessors compiler.cfg compiler.cfg.instructions
4 compiler.cfg.rpo compiler.cfg.stacks.global
5 compiler.cfg.stacks.local compiler.cfg.utilities kernel make
6 math sequences sets ;
7 IN: compiler.cfg.stacks.finalize
8
9 :: inserting-peeks ( from to -- set )
10     to anticip-in
11     from anticip-out from avail-out union
12     diff ;
13
14 :: inserting-replaces ( from to -- set )
15     from pending-out to pending-in diff
16     to dead-in to live-in to anticip-in diff diff
17     diff ;
18
19 : each-insertion ( ... set bb quot: ( ... vreg loc -- ... ) -- ... )
20     [ members ] 2dip
21     '[ [ loc>vreg ] [ _ height>> local-loc>global ] bi @ ] each ; inline
22
23 ERROR: bad-peek dst loc ;
24
25 : insert-peeks ( from to -- )
26     [ inserting-peeks ] keep
27     [ dup n>> 0 < [ bad-peek ] [ ##peek, ] if ] each-insertion ;
28
29 : insert-replaces ( from to -- )
30     [ inserting-replaces ] keep
31     [ dup n>> 0 < [ 2drop ] [ ##replace, ] if ] each-insertion ;
32
33 : visit-edge ( from to -- )
34     2dup [ [ insert-replaces ] [ insert-peeks ] 2bi ##branch, ] V{ } make
35     dup length 1 > [
36         insert-basic-block
37     ] [ 3drop ] if ;
38
39 : visit-block ( bb -- )
40     [ predecessors>> ] keep '[ _ visit-edge ] each ;
41
42 : finalize-stack-shuffling ( cfg -- )
43     [ [ visit-block ] each-basic-block ] [ cfg-changed ] bi ;