]> gitweb.factorcode.org Git - factor.git/blob - extra/compiler/cfg/gvn/graph/graph.factor
factor: trim using lists
[factor.git] / extra / compiler / cfg / gvn / graph / graph.factor
1 ! Copyright (C) 2008, 2010 Slava Pestov, 2011 Alex Vondrak.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: assocs kernel namespaces ;
4 IN: compiler.cfg.gvn.graph
5
6 SYMBOL: input-expr-counter
7
8 ! assoc mapping vregs to value numbers
9 ! this is the identity on canonical representatives
10 SYMBOL: vregs>vns
11
12 ! assoc mapping expressions to value numbers
13 SYMBOL: exprs>vns
14
15 ! assoc mapping value numbers to instructions
16 SYMBOL: vns>insns
17
18 ! assoc mapping each value number to a sequence of vregs
19 ! sharing that value number (i.e., the congruence class)
20 SYMBOL: vns>vregs
21
22 ! boolean to track whether vregs>vns changes
23 SYMBOL: changed?
24
25 ! boolean to track when it's safe to alter the CFG in a rewrite
26 ! method (i.e., after vregs>vns stops changing)
27 SYMBOL: final-iteration?
28
29 : vn>insn ( vn -- insn ) vns>insns get at ;
30
31 : vreg>vn ( vreg -- vn ) vregs>vns get at ;
32
33 : set-vn ( vn vreg -- )
34     vregs>vns get maybe-set-at [ changed? on ] when ;
35
36 : vreg>insn ( vreg -- insn ) vreg>vn vn>insn ;
37
38 : congruence-class ( vreg -- vregs )
39     vreg>vn vns>vregs get at ;
40
41 : clear-exprs ( -- )
42     exprs>vns get clear-assoc
43     vns>insns get clear-assoc ;
44
45 : compute-congruence-classes ( -- )
46     vregs>vns get H{ } clone [
47         [ push-at ] curry assoc-each
48     ] keep vns>vregs set ;
49
50 : init-value-graph ( -- )
51     0 input-expr-counter set
52     H{ } clone vregs>vns set
53     H{ } clone exprs>vns set
54     H{ } clone vns>insns set ;