1 ! Copyright (C) 2008, 2010 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors compiler.cfg.gvn.avail kernel math namespaces
5 IN: compiler.cfg.gvn.graph
7 SYMBOL: input-expr-counter
9 ! assoc mapping vregs to value numbers
10 ! this is the identity on canonical representatives
13 ! assoc mapping expressions to value numbers
16 ! assoc mapping value numbers to instructions
19 ! boolean to track whether vregs>vns changes
22 ! boolean to track when it's safe to alter the CFG in a rewrite
23 ! method (i.e., after vregs>vns stops changing)
24 SYMBOL: final-iteration?
26 : vn>insn ( vn -- insn ) vns>insns get at ;
28 : vreg>leader ( vreg -- vn ) vregs>vns get at ;
30 : vreg>vn ( vreg -- vn )
31 dup vreg>leader dup available? [ nip ] [ drop ] if ;
33 : set-vn ( vn vreg -- )
34 vregs>vns get maybe-set-at [ changed? on ] when ;
36 : vreg>insn ( vreg -- insn ) vreg>vn vn>insn ;
39 exprs>vns get clear-assoc
40 vns>insns get clear-assoc ;
42 : init-value-graph ( -- )
43 0 input-expr-counter set
44 H{ } clone vregs>vns set
45 H{ } clone exprs>vns set
46 H{ } clone vns>insns set ;