factor/basis/compiler/cfg/copy-prop/copy-prop.factor

37 lines
996 B
Factor
Raw Normal View History

! Copyright (C) 2008, 2009 Slava Pestov.
2008-10-22 19:37:47 -04:00
! See http://factorcode.org/license.txt for BSD license.
USING: kernel namespaces assocs accessors sequences
compiler.cfg.rpo compiler.cfg.renaming compiler.cfg.instructions ;
2008-10-22 19:37:47 -04:00
IN: compiler.cfg.copy-prop
! The first three definitions are also used in compiler.cfg.alias-analysis.
2008-10-22 19:37:47 -04:00
SYMBOL: copies
: resolve ( vreg -- vreg )
2009-05-19 18:28:13 -04:00
[ copies get at ] keep or ;
2008-10-22 19:37:47 -04:00
: record-copy ( insn -- )
[ src>> resolve ] [ dst>> ] bi copies get set-at ; inline
: collect-copies ( cfg -- )
H{ } clone copies set
[
instructions>>
[ dup ##copy? [ record-copy ] [ drop ] if ] each
] each-basic-block ;
: rename-copies ( cfg -- )
copies get dup assoc-empty? [ 2drop ] [
renamings set
[
instructions>>
[ dup ##copy? [ drop f ] [ rename-insn-uses t ] if ] filter-here
] each-basic-block
] if ;
: copy-propagation ( cfg -- cfg' )
[ collect-copies ]
[ rename-copies ]
[ ]
tri ;