2009-07-16 23:42:13 -04:00
|
|
|
! Copyright (C) 2009 Slava Pestov, Daniel Ehrenberg.
|
2009-05-27 19:58:01 -04:00
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
2009-07-12 23:22:46 -04:00
|
|
|
USING: accessors assocs fry kernel sequences namespaces
|
|
|
|
compiler.cfg compiler.cfg.instructions compiler.cfg.rpo
|
2009-07-16 23:42:13 -04:00
|
|
|
compiler.cfg.utilities compiler.cfg.hats make
|
|
|
|
locals ;
|
2009-05-27 19:58:01 -04:00
|
|
|
IN: compiler.cfg.phi-elimination
|
|
|
|
|
|
|
|
: insert-copy ( predecessor input output -- )
|
|
|
|
'[ _ _ swap ##copy ] add-instructions ;
|
|
|
|
|
2009-07-16 23:42:13 -04:00
|
|
|
: eliminate-phi ( ##phi -- ##copy )
|
|
|
|
i
|
|
|
|
[ [ inputs>> ] dip '[ _ insert-copy ] assoc-each ]
|
|
|
|
[ [ dst>> ] dip \ ##copy new-insn ]
|
|
|
|
2bi ;
|
2009-05-27 19:58:01 -04:00
|
|
|
|
|
|
|
: eliminate-phi-step ( bb -- )
|
2009-07-12 23:22:46 -04:00
|
|
|
H{ } clone added-instructions set
|
2009-07-16 23:42:13 -04:00
|
|
|
[ instructions>> [ dup ##phi? [ eliminate-phi ] when ] change-each ]
|
2009-07-12 23:22:46 -04:00
|
|
|
[ insert-basic-blocks ]
|
|
|
|
bi ;
|
2009-05-27 19:58:01 -04:00
|
|
|
|
2009-05-29 14:11:34 -04:00
|
|
|
: eliminate-phis ( cfg -- cfg' )
|
2009-07-12 23:22:46 -04:00
|
|
|
dup [ eliminate-phi-step ] each-basic-block
|
2009-07-16 23:42:13 -04:00
|
|
|
cfg-changed ;
|