factor/basis/compiler/cfg/value-numbering/value-numbering.factor

41 lines
1.1 KiB
Factor
Raw Normal View History

! Copyright (C) 2008, 2009 Slava Pestov.
2008-10-19 02:10:21 -04:00
! See http://factorcode.org/license.txt for BSD license.
USING: namespaces assocs kernel accessors
sorting sets sequences arrays
cpu.architecture
sequences.deep
compiler.cfg
compiler.cfg.rpo
compiler.cfg.def-use
compiler.cfg.instructions
2008-10-22 22:59:07 -04:00
compiler.cfg.value-numbering.graph
compiler.cfg.value-numbering.expressions
2008-10-23 03:49:26 -04:00
compiler.cfg.value-numbering.simplify
compiler.cfg.value-numbering.rewrite ;
2008-10-19 02:10:21 -04:00
IN: compiler.cfg.value-numbering
! Local value numbering.
2009-07-24 07:08:07 -04:00
: >copy ( insn -- insn/##copy )
dup defs-vreg dup vreg>vn vn>vreg
2dup eq? [ 2drop ] [ any-rep \ ##copy new-insn nip ] if ;
GENERIC: process-instruction ( insn -- insn' )
M: insn process-instruction
dup rewrite
[ process-instruction ]
[ dup defs-vreg [ dup number-values >copy ] when ] ?if ;
M: array process-instruction
[ process-instruction ] map ;
: value-numbering-step ( insns -- insns' )
init-value-graph
[ process-instruction ] map flatten ;
: value-numbering ( cfg -- cfg' )
[ value-numbering-step ] local-optimization
cfg-changed predecessors-changed ;