]> gitweb.factorcode.org Git - factor.git/blob - extra/compiler/cfg/gvn/graph/graph.factor
compiler.cfg.gvn: preparing for avail-based redundancy elimination
[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 kernel math namespaces assocs ;
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 basic blocks to the set of value numbers that
19 ! are defined in the block
20 SYMBOL: bbs>defns
21
22 ! boolean to track whether vregs>vns changes
23 SYMBOL: changed?
24
25 : vn>insn ( vn -- insn ) vns>insns get at ;
26
27 : vreg>vn ( vreg -- vn ) vregs>vns get at ;
28
29 : set-vn ( vn vreg -- )
30     vregs>vns get maybe-set-at [ changed? on ] when ;
31
32 : vreg>insn ( vreg -- insn ) vreg>vn vn>insn ;
33
34 : defined ( bb -- vns ) bbs>defns get at ;
35
36 : clear-exprs ( -- )
37     exprs>vns get clear-assoc
38     vns>insns get clear-assoc
39     bbs>defns get clear-assoc ;
40
41 : init-value-graph ( -- )
42     0 input-expr-counter set
43     H{ } clone vregs>vns set
44     H{ } clone exprs>vns set
45     H{ } clone vns>insns set
46     H{ } clone bbs>defns set ;