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
7 IN: compiler.cfg.stacks.finalize
9 :: inserting-peeks ( from to -- set )
11 from anticip-out from avail-out union
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
19 : each-insertion ( ... set bb quot: ( ... vreg loc -- ... ) -- ... )
21 '[ [ loc>vreg ] [ _ height>> local-loc>global ] bi @ ] each ; inline
23 ERROR: bad-peek dst loc ;
25 : insert-peeks ( from to -- )
26 [ inserting-peeks ] keep
27 [ dup n>> 0 < [ bad-peek ] [ ##peek, ] if ] each-insertion ;
29 : insert-replaces ( from to -- )
30 [ inserting-replaces ] keep
31 [ dup n>> 0 < [ 2drop ] [ ##replace, ] if ] each-insertion ;
33 : visit-edge ( from to -- )
34 2dup [ [ insert-replaces ] [ insert-peeks ] 2bi ##branch, ] V{ } make
39 : visit-block ( bb -- )
40 [ predecessors>> ] keep '[ _ visit-edge ] each ;
42 : finalize-stack-shuffling ( cfg -- )
43 [ [ visit-block ] each-basic-block ] [ cfg-changed ] bi ;