2008-10-19 02:10:21 -04:00
|
|
|
! Copyright (C) 2008 Slava Pestov.
|
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
2008-10-22 22:59:07 -04:00
|
|
|
USING: namespaces assocs biassocs classes kernel math accessors
|
|
|
|
sorting sets sequences
|
|
|
|
compiler.cfg.def-use
|
|
|
|
compiler.cfg.instructions
|
|
|
|
compiler.cfg.instructions.syntax
|
|
|
|
compiler.cfg.value-numbering.graph
|
|
|
|
compiler.cfg.value-numbering.expressions
|
|
|
|
compiler.cfg.value-numbering.liveness
|
|
|
|
compiler.cfg.value-numbering.propagate
|
|
|
|
compiler.cfg.value-numbering.simplify ;
|
2008-10-19 02:10:21 -04:00
|
|
|
IN: compiler.cfg.value-numbering
|
|
|
|
|
|
|
|
: insn>vn ( insn -- vn ) >expr simplify ; inline
|
|
|
|
|
2008-10-22 22:59:07 -04:00
|
|
|
GENERIC: number-values ( insn -- )
|
2008-10-19 02:10:21 -04:00
|
|
|
|
2008-10-22 22:59:07 -04:00
|
|
|
M: ##flushable number-values
|
|
|
|
dup ##pure? [ dup call-next-method ] unless
|
|
|
|
[ insn>vn ] [ dst>> ] bi set-vn ;
|
|
|
|
|
|
|
|
M: insn number-values uses-vregs [ live-vreg ] each ;
|
2008-10-19 02:10:21 -04:00
|
|
|
|
|
|
|
: init-value-numbering ( -- )
|
|
|
|
init-value-graph
|
|
|
|
init-expressions
|
|
|
|
init-liveness ;
|
|
|
|
|
2008-10-22 22:59:07 -04:00
|
|
|
: value-numbering ( insns -- insns' )
|
2008-10-19 02:10:21 -04:00
|
|
|
init-value-numbering
|
2008-10-22 22:59:07 -04:00
|
|
|
[ [ number-values ] each ]
|
|
|
|
[ [ eliminate propagate ] map sift ]
|
|
|
|
bi ;
|