2009-08-02 11:26:52 -04:00
|
|
|
! Copyright (C) 2009 Slava Pestov.
|
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
2009-09-23 03:47:56 -04:00
|
|
|
USING: accessors assocs kernel locals fry sequences
|
2009-08-07 18:44:50 -04:00
|
|
|
cpu.architecture
|
2009-08-02 11:26:52 -04:00
|
|
|
compiler.cfg.rpo
|
2009-09-23 03:47:56 -04:00
|
|
|
compiler.cfg.def-use
|
2009-08-02 11:26:52 -04:00
|
|
|
compiler.cfg.utilities
|
2009-08-08 01:24:46 -04:00
|
|
|
compiler.cfg.registers
|
|
|
|
compiler.cfg.instructions
|
2010-04-21 03:08:52 -04:00
|
|
|
compiler.cfg.representations.conversion ;
|
2009-08-02 11:26:52 -04:00
|
|
|
IN: compiler.cfg.ssa.cssa
|
|
|
|
|
2009-08-08 05:02:18 -04:00
|
|
|
! Convert SSA to conventional SSA. This pass runs after representation
|
|
|
|
! selection, so it must keep track of representations when introducing
|
|
|
|
! new values.
|
2009-08-02 11:26:52 -04:00
|
|
|
|
2009-09-23 03:47:56 -04:00
|
|
|
: insert-copy? ( bb vreg -- ? )
|
|
|
|
! If the last instruction defines a value (which means it is
|
|
|
|
! ##fixnum-add, ##fixnum-sub or ##fixnum-mul) then we don't
|
|
|
|
! need to insert a copy since in fact doing so will result
|
|
|
|
! in incorrect code.
|
|
|
|
[ instructions>> last defs-vreg ] dip eq? not ;
|
|
|
|
|
2009-08-08 01:24:46 -04:00
|
|
|
:: insert-copy ( bb src rep -- bb dst )
|
2009-09-23 03:47:56 -04:00
|
|
|
bb src insert-copy? [
|
|
|
|
rep next-vreg-rep :> dst
|
|
|
|
bb [ dst src rep src rep-of emit-conversion ] add-instructions
|
|
|
|
bb dst
|
|
|
|
] [ bb src ] if ;
|
2009-08-02 11:26:52 -04:00
|
|
|
|
|
|
|
: convert-phi ( ##phi -- )
|
2009-08-08 05:02:18 -04:00
|
|
|
dup dst>> rep-of '[ [ _ insert-copy ] assoc-map ] change-inputs drop ;
|
2009-08-02 11:26:52 -04:00
|
|
|
|
|
|
|
: construct-cssa ( cfg -- )
|
|
|
|
[ [ convert-phi ] each-phi ] each-basic-block ;
|