1 ! Copyright (C) 2009 Slava Pestov, Daniel Ehrenberg.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors assocs fry kernel sequences namespaces
4 compiler.cfg compiler.cfg.instructions compiler.cfg.rpo
5 compiler.cfg.utilities compiler.cfg.hats make
7 IN: compiler.cfg.phi-elimination
9 : insert-copy ( predecessor input output -- )
10 '[ _ _ swap ##copy ] add-instructions ;
12 : eliminate-phi ( ##phi -- ##copy )
14 [ [ inputs>> ] dip '[ _ insert-copy ] assoc-each ]
15 [ [ dst>> ] dip \ ##copy new-insn ]
18 : eliminate-phi-step ( bb -- )
19 H{ } clone added-instructions set
20 [ instructions>> [ dup ##phi? [ eliminate-phi ] when ] change-each ]
21 [ insert-basic-blocks ]
24 : eliminate-phis ( cfg -- cfg' )
25 dup [ eliminate-phi-step ] each-basic-block