1 ! Copyright (C) 2008, 2010 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors kernel math namespaces assocs ;
4 IN: compiler.cfg.gvn.graph
6 SYMBOL: input-expr-counter
8 ! assoc mapping vregs to *optimistic* value numbers
9 ! initialized per iteration of global value numbering
10 ! this is the identity on canonical representatives
13 ! assoc mapping expressions to value numbers
16 ! assoc mapping value numbers to instructions
19 ! assoc mapping vregs to value numbers
20 ! once this stops changing, we know the value numbers are sound
23 ! boolean to track whether valid-vns changes
26 : vn>insn ( vn -- insn ) vns>insns get at ;
28 : vreg>vn ( vreg -- vn ) valid-vns get at ;
30 : optimistic-vn ( default-vn vreg -- vn )
33 [ dupd vregs>vns get set-at ] if ;
35 : set-vn ( default-vn vreg -- )
36 [ optimistic-vn ] keep
37 valid-vns get maybe-set-at [ changed? on ] when ;
39 : vreg>insn ( vreg -- insn ) vreg>vn vn>insn ;
41 : clear-optimistic-value-graph ( -- )
42 vregs>vns get clear-assoc
43 exprs>vns get clear-assoc
44 vns>insns get clear-assoc ;
46 : init-value-graph ( -- )
47 0 input-expr-counter set
48 H{ } clone valid-vns set
49 H{ } clone vregs>vns set
50 H{ } clone exprs>vns set
51 H{ } clone vns>insns set ;