]> gitweb.factorcode.org Git - factor.git/blob - basis/compiler/cfg/ssa/destruction/destruction.factor
scryfall: better moxfield words
[factor.git] / basis / compiler / cfg / ssa / destruction / destruction.factor
1 ! Copyright (C) 2009, 2011 Slava Pestov.
2 ! See https://factorcode.org/license.txt for BSD license.
3 USING: accessors assocs compiler.cfg.def-use compiler.cfg.dominance
4 compiler.cfg.instructions compiler.cfg.liveness
5 compiler.cfg.parallel-copy compiler.cfg.rpo compiler.cfg.ssa.cssa
6 compiler.cfg.ssa.destruction.coalescing compiler.cfg.ssa.destruction.leaders
7 compiler.cfg.ssa.interference.live-ranges compiler.cfg.utilities
8 kernel make sequences namespaces ;
9 IN: compiler.cfg.ssa.destruction
10
11 <PRIVATE
12
13 GENERIC: cleanup-insn ( insn -- )
14
15 : useful-copy? ( insn -- ? )
16     [ dst>> ] [ src>> ] bi leaders = not ; inline
17
18 M: ##copy cleanup-insn
19     dup useful-copy? [ , ] [ drop ] if ;
20
21 M: ##parallel-copy cleanup-insn
22     values>> [ leaders ] assoc-map [ first2 = ] reject
23     parallel-copy-rep % ;
24
25 M: ##tagged>integer cleanup-insn
26     dup useful-copy? [ , ] [ drop ] if ;
27
28 M: ##phi cleanup-insn drop ;
29
30 M: insn cleanup-insn , ;
31
32 : cleanup-cfg ( cfg -- )
33     [ [ [ cleanup-insn ] each ] V{ } make ] simple-optimization ;
34
35 PRIVATE>
36
37 : destruct-ssa ( cfg -- )
38     f leader-map set
39     {
40         needs-dominance
41         construct-cssa
42         compute-defs
43         compute-insns
44         compute-live-sets
45         compute-live-ranges
46         coalesce-cfg
47         cleanup-cfg
48         compute-live-sets
49     } apply-passes ;