+++ /dev/null
-! Copyright (C) 2009 Slava Pestov, Daniel Ehrenberg.
-! See http://factorcode.org/license.txt for BSD license.
-USING: accessors assocs fry kernel sequences namespaces
-compiler.cfg compiler.cfg.instructions compiler.cfg.rpo
-compiler.cfg.utilities compiler.cfg.hats make
-locals ;
-IN: compiler.cfg.phi-elimination
-
-! assoc mapping predecessors to sequences
-SYMBOL: added-instructions
-
-: add-instructions ( predecessor quot -- )
- [
- added-instructions get
- [ drop V{ } clone ] cache
- building
- ] dip with-variable ; inline
-
-: insert-basic-blocks ( bb -- )
- [ added-instructions get ] dip
- '[ [ _ ] dip <simple-block> insert-basic-block ] assoc-each ;
-
-: insert-copy ( predecessor input output -- )
- '[ _ _ swap ##copy ] add-instructions ;
-
-: eliminate-phi ( ##phi -- ##copy )
- i
- [ [ inputs>> ] dip '[ _ insert-copy ] assoc-each ]
- [ [ dst>> ] dip \ ##copy new-insn ]
- 2bi ;
-
-: eliminate-phi-step ( bb -- )
- H{ } clone added-instructions set
- [ instructions>> [ dup ##phi? [ eliminate-phi ] when ] change-each ]
- [ insert-basic-blocks ]
- bi ;
-
-: eliminate-phis ( cfg -- cfg' )
- dup [ eliminate-phi-step ] each-basic-block
- cfg-changed ;