From 8477cf8e919cfe8473ad05cb50daa41d12b449e8 Mon Sep 17 00:00:00 2001 From: Daniel Ehrenberg Date: Thu, 16 Jul 2009 22:42:13 -0500 Subject: [PATCH] Phi elimination doesn't have the swap problem now --- .../compiler/cfg/phi-elimination/authors.txt | 3 +- .../phi-elimination-tests.factor | 33 ++++++++++++++----- .../phi-elimination/phi-elimination.factor | 16 +++++---- .../value-numbering-tests.factor | 19 +++++++---- 4 files changed, 49 insertions(+), 22 deletions(-) diff --git a/basis/compiler/cfg/phi-elimination/authors.txt b/basis/compiler/cfg/phi-elimination/authors.txt index d4f5d6b3ae..a44f8d7f8d 100644 --- a/basis/compiler/cfg/phi-elimination/authors.txt +++ b/basis/compiler/cfg/phi-elimination/authors.txt @@ -1 +1,2 @@ -Slava Pestov \ No newline at end of file +Slava Pestov +Daniel Ehrenberg diff --git a/basis/compiler/cfg/phi-elimination/phi-elimination-tests.factor b/basis/compiler/cfg/phi-elimination/phi-elimination-tests.factor index 27458185a5..79d1797720 100644 --- a/basis/compiler/cfg/phi-elimination/phi-elimination-tests.factor +++ b/basis/compiler/cfg/phi-elimination/phi-elimination-tests.factor @@ -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 ] | -[ T{ ##copy f V int-regs 3 V int-regs 2 } ] -[ 3 get successors>> first instructions>> first ] -unit-test +[ ] [ 2 get successors>> first instructions>> first dst>> n>> n! ] unit-test -[ 2 ] [ 4 get instructions>> length ] unit-test \ No newline at end of file +[ 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 + +] + +[ 3 ] [ 4 get instructions>> length ] unit-test diff --git a/basis/compiler/cfg/phi-elimination/phi-elimination.factor b/basis/compiler/cfg/phi-elimination/phi-elimination.factor index 7e184a9b53..7e73f0b854 100644 --- a/basis/compiler/cfg/phi-elimination/phi-elimination.factor +++ b/basis/compiler/cfg/phi-elimination/phi-elimination.factor @@ -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 ; diff --git a/basis/compiler/cfg/value-numbering/value-numbering-tests.factor b/basis/compiler/cfg/value-numbering/value-numbering-tests.factor index 4c431b8a5c..62ed4a7eb3 100644 --- a/basis/compiler/cfg/value-numbering/value-numbering-tests.factor +++ b/basis/compiler/cfg/value-numbering/value-numbering-tests.factor @@ -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