]> gitweb.factorcode.org Git - factor.git/commitdiff
Phi elimination doesn't have the swap problem now
authorDaniel Ehrenberg <littledan@Macintosh-122.local>
Fri, 17 Jul 2009 03:42:13 +0000 (22:42 -0500)
committerDaniel Ehrenberg <littledan@Macintosh-122.local>
Fri, 17 Jul 2009 03:42:13 +0000 (22:42 -0500)
basis/compiler/cfg/phi-elimination/authors.txt
basis/compiler/cfg/phi-elimination/phi-elimination-tests.factor
basis/compiler/cfg/phi-elimination/phi-elimination.factor
basis/compiler/cfg/value-numbering/value-numbering-tests.factor

index d4f5d6b3aeb70f66356d80c70755fbb63ef584df..a44f8d7f8d462129605979ca2bec95cc98dc3a48 100644 (file)
@@ -1 +1,2 @@
-Slava Pestov
\ No newline at end of file
+Slava Pestov
+Daniel Ehrenberg
index 27458185a5e6785978a0545e43f44764b48c5834..79d1797720f0e5872ccdf21290f53781d5c5c256 100644 (file)
@@ -1,8 +1,10 @@
-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
 
@@ -36,12 +38,25 @@ test-diamond
 
 [ ] [ 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
index 7e184a9b5317fb5e89d2ba5428849d6652b45f29..7e73f0b8549408b5ace81c58a60c85f2f3b01e19 100644 (file)
@@ -1,22 +1,26 @@
-! 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 ;
index 4c431b8a5c8fd423def8811b7ce04a4c829c3306..62ed4a7eb3cd7bdb7f4549091ef2f2f7eebb3be4 100644 (file)
@@ -2,7 +2,7 @@ IN: compiler.cfg.value-numbering.tests
 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 ;
 
@@ -1218,11 +1218,18 @@ test-diamond
 
 [ 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 }
@@ -1331,4 +1338,4 @@ V{
     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