1 ! Copyright (C) 2008, 2009 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: namespaces assocs kernel accessors
7 compiler.cfg.instructions
8 compiler.cfg.value-numbering.graph
9 compiler.cfg.value-numbering.expressions
10 compiler.cfg.value-numbering.simplify
11 compiler.cfg.value-numbering.rewrite ;
12 IN: compiler.cfg.value-numbering
14 ! Local value numbering. Predecessors must be recomputed after this
15 : >copy ( insn -- insn/##copy )
16 dup dst>> dup vreg>vn vn>vreg
17 2dup eq? [ 2drop ] [ \ ##copy new-insn nip ] if ;
19 : rewrite-loop ( insn -- insn' )
20 dup rewrite [ rewrite-loop ] [ ] ?if ;
22 GENERIC: process-instruction ( insn -- insn' )
24 M: ##flushable process-instruction
26 [ process-instruction ]
27 [ dup number-values >copy ] ?if ;
29 M: insn process-instruction
31 [ process-instruction ] [ ] ?if ;
33 : value-numbering-step ( insns -- insns' )
36 [ process-instruction ] map ;
38 : value-numbering ( cfg -- cfg' )
39 [ value-numbering-step ] local-optimization cfg-changed ;