]> gitweb.factorcode.org Git - factor.git/blob - extra/compiler/cfg/gvn/graph/graph.factor
compiler.cfg.gvn: some poorly thought-out attempts at redundancy elimination that...
[factor.git] / extra / compiler / cfg / gvn / graph / graph.factor
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
4 assocs ;
5 IN: compiler.cfg.gvn.graph
6
7 SYMBOL: input-expr-counter
8
9 ! assoc mapping vregs to value numbers
10 ! this is the identity on canonical representatives
11 SYMBOL: vregs>vns
12
13 ! assoc mapping expressions to value numbers
14 SYMBOL: exprs>vns
15
16 ! assoc mapping value numbers to instructions
17 SYMBOL: vns>insns
18
19 ! boolean to track whether vregs>vns changes
20 SYMBOL: changed?
21
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?
25
26 : vn>insn ( vn -- insn ) vns>insns get at ;
27
28 : vreg>leader ( vreg -- vn ) vregs>vns get at ;
29
30 : vreg>vn ( vreg -- vn )
31     dup vreg>leader dup available? [ nip ] [ drop ] if ;
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 : clear-exprs ( -- )
39     exprs>vns get clear-assoc
40     vns>insns get clear-assoc ;
41
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 ;