]> gitweb.factorcode.org Git - factor.git/blob - basis/compiler/cfg/ssa/cssa/cssa.factor
Solution to Project Euler problem 65
[factor.git] / basis / compiler / cfg / ssa / cssa / cssa.factor
1 ! Copyright (C) 2009 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors assocs kernel locals fry
4 cpu.architecture
5 compiler.cfg.rpo
6 compiler.cfg.utilities
7 compiler.cfg.registers
8 compiler.cfg.instructions
9 compiler.cfg.representations ;
10 IN: compiler.cfg.ssa.cssa
11
12 ! Convert SSA to conventional SSA. This pass runs after representation
13 ! selection, so it must keep track of representations when introducing
14 ! new values.
15
16 :: insert-copy ( bb src rep -- bb dst )
17     rep next-vreg-rep :> dst
18     bb [ dst src rep src rep-of emit-conversion ] add-instructions
19     bb dst ;
20
21 : convert-phi ( ##phi -- )
22     dup dst>> rep-of '[ [ _ insert-copy ] assoc-map ] change-inputs drop ;
23
24 : construct-cssa ( cfg -- )
25     [ [ convert-phi ] each-phi ] each-basic-block ;