compiler.cfg.value-numbering: identify VNs with their representative vregs, eliminating the vn>vreg hash

db4
Slava Pestov 2010-04-24 06:15:41 -04:00
parent edaf59bf46
commit ef8094e3b3
3 changed files with 11 additions and 25 deletions

View File

@ -77,13 +77,7 @@ M: reference-expr equal?
M: reference-expr hashcode*
nip value>> dup float? [ double>bits ] [ identity-hashcode ] if ;
! Expressions whose values are inputs to the basic block.
TUPLE: input-expr n ;
: next-input-expr ( -- expr )
input-expr-counter counter input-expr boa ;
M: insn >expr drop next-input-expr ;
M: insn >expr drop input-expr-counter counter neg ;
M: ##copy >expr "Fail" throw ;

View File

@ -1,14 +1,13 @@
! Copyright (C) 2008, 2010 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors kernel math namespaces assocs biassocs ;
USING: accessors kernel math namespaces assocs ;
IN: compiler.cfg.value-numbering.graph
! Value numbers are negative, to catch confusion with vregs
SYMBOL: vn-counter
SYMBOL: input-expr-counter
: next-vn ( -- vn ) vn-counter [ 1 - dup ] change ;
! assoc mapping vregs to value numbers
! this is the identity on canonical representatives
SYMBOL: vregs>vns
! assoc mapping expressions to value numbers
SYMBOL: exprs>vns
@ -18,21 +17,14 @@ SYMBOL: vns>insns
: vn>insn ( vn -- insn ) vns>insns get at ;
! biassocs mapping vregs to value numbers, and value numbers to
! their primary vregs
SYMBOL: vregs>vns
: vreg>vn ( vreg -- vn ) vregs>vns get [ drop next-vn ] cache ;
: vn>vreg ( vn -- vreg ) vregs>vns get value-at ;
: vreg>vn ( vreg -- vn ) vregs>vns get [ ] cache ;
: set-vn ( vn vreg -- ) vregs>vns get set-at ;
: vreg>insn ( vreg -- insn ) vreg>vn vn>insn ; inline
: vreg>insn ( vreg -- insn ) vreg>vn vn>insn ;
: init-value-graph ( -- )
0 vn-counter set
0 input-expr-counter set
<bihash> vregs>vns set
H{ } clone vregs>vns set
H{ } clone exprs>vns set
H{ } clone vns>insns set ;

View File

@ -21,11 +21,11 @@ IN: compiler.cfg.value-numbering
GENERIC: process-instruction ( insn -- insn' )
: redundant-instruction ( insn vn -- insn' )
[ dst>> ] dip [ swap set-vn ] [ vn>vreg <copy> ] 2bi ;
[ dst>> ] dip [ swap set-vn ] [ <copy> ] 2bi ;
:: useful-instruction ( insn expr -- insn' )
next-vn :> vn
vn insn dst>> vregs>vns get set-at
insn dst>> :> vn
vn vn vregs>vns get set-at
vn expr exprs>vns get set-at
insn vn vns>insns get set-at
insn ;