DCE fixes

db4
Slava Pestov 2008-08-18 21:30:10 -05:00
parent aa9341e579
commit 0efec0eff1
6 changed files with 26 additions and 14 deletions

View File

@ -92,7 +92,7 @@ M: node generate-node drop iterate-next ;
%jump-label ;
: generate-call ( label -- next )
! dup maybe-compile
dup maybe-compile
end-basic-block
dup compiling-loops get at [
%jump-label f

View File

@ -22,9 +22,6 @@ IN: compiler.tree.builder
] with-tree-builder nip
unclip-last in-d>> ;
: ends-with-terminate? ( nodes -- ? )
dup empty? [ drop f ] [ peek #terminate? ] if ;
: build-sub-tree ( #call quot -- nodes )
[ [ out-d>> ] [ in-d>> ] bi ] dip build-tree-with
over ends-with-terminate?

View File

@ -117,11 +117,19 @@ M: #branch cleanup*
[ live-branches>> live-branches set ]
} cleave ;
: eliminate-phi ( #phi -- node )
dup phi-in-d>> length {
{ 0 [ drop f ] }
{ 1 [ [ phi-in-d>> first ] [ out-d>> ] bi #copy ] }
[ drop ]
} case ;
M: #phi cleanup*
#! Remove #phi function inputs which no longer exist.
live-branches get
[ '[ , select-children sift ] change-phi-in-d ]
[ '[ , select-children sift ] change-phi-info-d ] bi
eliminate-phi
live-branches off ;
: >copy ( node -- #copy ) [ in-d>> ] [ out-d>> ] bi #copy ;

View File

@ -1,9 +1,10 @@
! Copyright (C) 2008 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
USING: sequences namespaces kernel accessors assocs sets fry
arrays combinators columns stack-checker.backend compiler.tree
compiler.tree.combinators compiler.tree.dead-code.liveness
compiler.tree.dead-code.simple ;
arrays combinators columns stack-checker.backend
stack-checker.branches compiler.tree compiler.tree.combinators
compiler.tree.dead-code.liveness compiler.tree.dead-code.simple
;
IN: compiler.tree.dead-code.branches
M: #if mark-live-values* look-at-inputs ;
@ -26,10 +27,9 @@ M: #branch remove-dead-code*
bi ;
: remove-phi-inputs ( #phi -- )
dup [ out-d>> ] [ phi-in-d>> flip ] bi
filter-corresponding
flip >>phi-in-d
drop ;
if-node get children>>
[ dup ends-with-terminate? [ drop f ] [ peek out-d>> ] if ] map
pad-with-bottom >>phi-in-d drop ;
: live-value-indices ( values -- indices )
[ length ] keep live-values get
@ -42,7 +42,10 @@ M: #branch remove-dead-code*
#shuffle ;
: insert-drops ( nodes values indices -- nodes' )
'[ , drop-values suffix ] 2map ;
'[
over ends-with-terminate?
[ drop ] [ , drop-values suffix ] if
] 2map ;
: hoist-drops ( #phi -- )
if-node get swap
@ -50,8 +53,7 @@ M: #branch remove-dead-code*
'[ , , insert-drops ] change-children drop ;
: remove-phi-outputs ( #phi -- )
[ filter-live ] change-out-d
drop ;
[ filter-live ] change-out-d drop ;
M: #phi remove-dead-code*
{

View File

@ -98,3 +98,5 @@ IN: compiler.tree.dead-code.tests
[ ] [ [ dup [ 3 throw ] [ ] if ] optimize-quot drop ] unit-test
[ [ [ . ] [ drop ] if ] ] [ [ [ dup . ] [ ] if drop ] optimize-quot ] unit-test
[ [ f ] ] [ [ f dup [ ] [ ] if ] optimize-quot ] unit-test

View File

@ -183,6 +183,9 @@ M: #return-recursive inputs/outputs [ in-d>> ] [ out-d>> ] bi ;
: recursive-phi-in ( #enter-recursive -- seq )
[ label>> calls>> [ in-d>> ] map ] [ in-d>> ] bi suffix ;
: ends-with-terminate? ( nodes -- ? )
dup empty? [ drop f ] [ peek #terminate? ] if ;
M: vector child-visitor V{ } clone ;
M: vector #introduce, #introduce node, ;
M: vector #call, #call node, ;