]> gitweb.factorcode.org Git - factor.git/blob - basis/compiler/cfg/ssa/cssa/cssa.factor
merge project-euler.factor
[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 sequences
4 cpu.architecture
5 compiler.cfg.rpo
6 compiler.cfg.def-use
7 compiler.cfg.utilities
8 compiler.cfg.registers
9 compiler.cfg.instructions
10 compiler.cfg.representations ;
11 IN: compiler.cfg.ssa.cssa
12
13 ! Convert SSA to conventional SSA. This pass runs after representation
14 ! selection, so it must keep track of representations when introducing
15 ! new values.
16
17 : insert-copy? ( bb vreg -- ? )
18     ! If the last instruction defines a value (which means it is
19     ! ##fixnum-add, ##fixnum-sub or ##fixnum-mul) then we don't
20     ! need to insert a copy since in fact doing so will result
21     ! in incorrect code.
22     [ instructions>> last defs-vreg ] dip eq? not ;
23
24 :: insert-copy ( bb src rep -- bb dst )
25     bb src insert-copy? [
26         rep next-vreg-rep :> dst
27         bb [ dst src rep src rep-of emit-conversion ] add-instructions
28         bb dst
29     ] [ bb src ] if ;
30
31 : convert-phi ( ##phi -- )
32     dup dst>> rep-of '[ [ _ insert-copy ] assoc-map ] change-inputs drop ;
33
34 : construct-cssa ( cfg -- )
35     [ [ convert-phi ] each-phi ] each-basic-block ;