-Slava Pestov
\ No newline at end of file
+Slava Pestov
+Daniel Ehrenberg
-IN: compiler.cfg.phi-elimination.tests
+! Copyright (C) 2009 Slava Pestov, Daniel Ehrenberg.
+! See http://factorcode.org/license.txt for BSD license.
USING: compiler.cfg.instructions compiler.cfg compiler.cfg.registers
-compiler.cfg.comparisons compiler.cfg.debugger
+compiler.cfg.comparisons compiler.cfg.debugger locals
compiler.cfg.phi-elimination kernel accessors sequences classes
namespaces tools.test cpu.architecture arrays ;
+IN: compiler.cfg.phi-elimination.tests
V{ T{ ##branch } } 0 test-bb
[ ] [ cfg new 0 get >>entry eliminate-phis drop ] unit-test
-[ T{ ##copy f V int-regs 3 V int-regs 1 } ]
-[ 2 get successors>> first instructions>> first ]
-unit-test
+[let | n! [ f ] |
+
+[ ] [ 2 get successors>> first instructions>> first dst>> n>> n! ] unit-test
+
+[ t ] [
+ T{ ##copy f V int-regs n V int-regs 1 }
+ 2 get successors>> first instructions>> first =
+] unit-test
+
+[ t ] [
+ T{ ##copy f V int-regs n V int-regs 2 }
+ 3 get successors>> first instructions>> first =
+] unit-test
+
+[ t ] [
+ T{ ##copy f V int-regs 3 V int-regs n }
+ 4 get instructions>> first =
+] unit-test
-[ T{ ##copy f V int-regs 3 V int-regs 2 } ]
-[ 3 get successors>> first instructions>> first ]
-unit-test
+]
-[ 2 ] [ 4 get instructions>> length ] unit-test
\ No newline at end of file
+[ 3 ] [ 4 get instructions>> length ] unit-test
-! Copyright (C) 2009 Slava Pestov.
+! 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.utilities compiler.cfg.hats make
+locals ;
IN: compiler.cfg.phi-elimination
: insert-copy ( predecessor input output -- )
'[ _ _ swap ##copy ] add-instructions ;
-: eliminate-phi ( ##phi -- )
- [ inputs>> ] [ dst>> ] bi '[ _ insert-copy ] assoc-each ;
+: 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 f ] [ drop t ] if ] filter-here ]
+ [ 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 ;
\ No newline at end of file
+ cfg-changed ;
USING: compiler.cfg.value-numbering compiler.cfg.instructions
compiler.cfg.registers compiler.cfg.debugger compiler.cfg.comparisons
cpu.architecture tools.test kernel math combinators.short-circuit
-accessors sequences compiler.cfg.predecessors
+accessors sequences compiler.cfg.predecessors locals
compiler.cfg.phi-elimination compiler.cfg.dce compiler.cfg.liveness
compiler.cfg assocs vectors arrays layouts namespaces ;
[ t ] [ 1 get successors>> first 3 get eq? ] unit-test
-[ T{ ##copy f V int-regs 3 V int-regs 2 } ]
-[ 3 get successors>> first instructions>> first ]
-unit-test
+[let | n! [ f ] |
-[ 2 ] [ 4 get instructions>> length ] unit-test
+[ ] [ 2 get successors>> first instructions>> first src>> n>> n! ] unit-test
+
+[ t ] [
+ T{ ##copy f V int-regs n V int-regs 2 }
+ 3 get successors>> first instructions>> first =
+] unit-test
+
+]
+
+[ 3 ] [ 4 get instructions>> length ] unit-test
V{
T{ ##peek f V int-regs 0 D 0 }
compute-liveness value-numbering eliminate-dead-code drop
] unit-test
-[ f ] [ 1 get instructions>> [ ##peek? ] any? ] unit-test
\ No newline at end of file
+[ f ] [ 1 get instructions>> [ ##peek? ] any? ] unit-test