2009-07-24 06:30:46 -04:00
|
|
|
! Copyright (C) 2008, 2009 Slava Pestov.
|
2008-10-22 19:37:47 -04:00
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
2009-07-24 06:30:46 -04:00
|
|
|
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
|
|
|
|
|
2009-07-24 06:30:46 -04:00
|
|
|
! 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
|
2009-07-24 06:30:46 -04:00
|
|
|
|
|
|
|
: 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 ;
|