]> gitweb.factorcode.org Git - factor.git/blob - basis/compiler/cfg/phi-elimination/phi-elimination.factor
db configurations factored out through db.info
[factor.git] / basis / compiler / cfg / phi-elimination / phi-elimination.factor
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
6 locals ;
7 IN: compiler.cfg.phi-elimination
8
9 : insert-copy ( predecessor input output -- )
10     '[ _ _ swap ##copy ] add-instructions ;
11
12 : eliminate-phi ( ##phi -- ##copy )
13     i
14     [ [ inputs>> ] dip '[ _ insert-copy ] assoc-each ]
15     [ [ dst>> ] dip \ ##copy new-insn ]
16     2bi ;
17
18 : eliminate-phi-step ( bb -- )
19     H{ } clone added-instructions set
20     [ instructions>> [ dup ##phi? [ eliminate-phi ] when ] change-each ]
21     [ insert-basic-blocks ]
22     bi ;
23
24 : eliminate-phis ( cfg -- cfg' )
25     dup [ eliminate-phi-step ] each-basic-block
26     cfg-changed ;