1 ! Copyright (C) 2009 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors assocs fry kernel locals math math.order
4 sequences namespaces sets
9 compiler.cfg.instructions
10 compiler.cfg.liveness.ssa
11 compiler.cfg.critical-edges
12 compiler.cfg.ssa.destruction.state
13 compiler.cfg.ssa.destruction.forest
14 compiler.cfg.ssa.destruction.copies
15 compiler.cfg.ssa.destruction.renaming
16 compiler.cfg.ssa.destruction.live-ranges
17 compiler.cfg.ssa.destruction.process-blocks ;
18 IN: compiler.cfg.ssa.destruction
20 ! Based on "Fast Copy Coalescing and Live-Range Identification"
21 ! http://www.cs.ucsd.edu/classes/sp02/cse231/kenpldi.pdf
23 ! Dominance, liveness and def-use need to be computed
25 : process-blocks ( cfg -- )
26 [ [ process-block ] if-has-phis ] each-basic-block ;
30 :: visit-renaming ( dst assoc src bb -- )
32 src dst bb add-waiting
34 ] [ src seen get conjoin ] if ;
36 :: break-interferences ( -- )
38 renaming-sets get [| dst assoc |
40 dst assoc src bb visit-renaming
44 : remove-phis-from-block ( bb -- )
45 instructions>> [ ##phi? not ] filter-here ;
47 : remove-phis ( cfg -- )
48 [ [ remove-phis-from-block ] if-has-phis ] each-basic-block ;
50 : destruct-ssa ( cfg -- cfg' )
52 dup split-critical-edges
57 dup compute-live-ranges