2010-04-24 02:38:43 -04:00
|
|
|
! Copyright (C) 2008, 2010 Slava Pestov.
|
2008-10-19 02:10:21 -04:00
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
2010-04-24 06:06:16 -04:00
|
|
|
USING: namespaces arrays assocs kernel accessors
|
|
|
|
sorting sets sequences locals
|
2009-08-08 05:02:18 -04:00
|
|
|
cpu.architecture
|
2009-08-27 01:06:19 -04:00
|
|
|
sequences.deep
|
2009-07-14 21:43:06 -04:00
|
|
|
compiler.cfg
|
2009-07-22 04:08:28 -04:00
|
|
|
compiler.cfg.rpo
|
2009-09-02 07:22:37 -04:00
|
|
|
compiler.cfg.def-use
|
2010-04-24 02:38:43 -04:00
|
|
|
compiler.cfg.utilities
|
2009-07-24 06:30:30 -04:00
|
|
|
compiler.cfg.instructions
|
2010-04-21 03:08:52 -04:00
|
|
|
compiler.cfg.value-numbering.alien
|
|
|
|
compiler.cfg.value-numbering.comparisons
|
|
|
|
compiler.cfg.value-numbering.graph
|
|
|
|
compiler.cfg.value-numbering.math
|
|
|
|
compiler.cfg.value-numbering.rewrite
|
2010-04-24 06:32:46 -04:00
|
|
|
compiler.cfg.value-numbering.slots
|
2010-05-01 03:04:31 -04:00
|
|
|
compiler.cfg.value-numbering.misc
|
2010-04-24 06:32:46 -04:00
|
|
|
compiler.cfg.value-numbering.expressions ;
|
2008-10-19 02:10:21 -04:00
|
|
|
IN: compiler.cfg.value-numbering
|
|
|
|
|
2009-07-24 06:30:30 -04:00
|
|
|
GENERIC: process-instruction ( insn -- insn' )
|
|
|
|
|
2010-04-24 06:06:16 -04:00
|
|
|
: redundant-instruction ( insn vn -- insn' )
|
2010-04-24 06:15:41 -04:00
|
|
|
[ dst>> ] dip [ swap set-vn ] [ <copy> ] 2bi ;
|
2010-04-24 06:06:16 -04:00
|
|
|
|
|
|
|
:: useful-instruction ( insn expr -- insn' )
|
2010-04-24 06:15:41 -04:00
|
|
|
insn dst>> :> vn
|
|
|
|
vn vn vregs>vns get set-at
|
2010-04-24 06:06:16 -04:00
|
|
|
vn expr exprs>vns get set-at
|
|
|
|
insn vn vns>insns get set-at
|
|
|
|
insn ;
|
|
|
|
|
|
|
|
: check-redundancy ( insn -- insn' )
|
|
|
|
dup >expr dup exprs>vns get at
|
|
|
|
[ redundant-instruction ] [ useful-instruction ] ?if ;
|
|
|
|
|
2009-07-24 06:30:30 -04:00
|
|
|
M: insn process-instruction
|
2010-07-13 07:40:14 -04:00
|
|
|
dup rewrite [ process-instruction ] [ ] ?if ;
|
|
|
|
|
|
|
|
M: foldable-insn process-instruction
|
2009-07-24 06:30:30 -04:00
|
|
|
dup rewrite
|
2009-09-02 07:22:37 -04:00
|
|
|
[ process-instruction ]
|
2010-07-13 07:40:14 -04:00
|
|
|
[ dup defs-vregs length 1 = [ check-redundancy ] when ] ?if ;
|
2010-04-24 02:38:43 -04:00
|
|
|
|
|
|
|
M: ##copy process-instruction
|
|
|
|
dup [ src>> vreg>vn ] [ dst>> ] bi set-vn ;
|
2009-07-10 00:14:26 -04:00
|
|
|
|
2009-08-27 01:06:19 -04:00
|
|
|
M: array process-instruction
|
|
|
|
[ process-instruction ] map ;
|
|
|
|
|
2009-05-26 20:56:56 -04:00
|
|
|
: value-numbering-step ( insns -- insns' )
|
2009-07-22 04:08:28 -04:00
|
|
|
init-value-graph
|
2009-08-27 01:06:19 -04:00
|
|
|
[ process-instruction ] map flatten ;
|
2009-05-26 20:31:19 -04:00
|
|
|
|
2010-04-30 18:55:20 -04:00
|
|
|
: value-numbering ( cfg -- cfg )
|
|
|
|
dup [ value-numbering-step ] simple-optimization
|
2009-08-08 21:02:56 -04:00
|
|
|
|
|
|
|
cfg-changed predecessors-changed ;
|