DCE fixes
parent
aa9341e579
commit
0efec0eff1
|
@ -92,7 +92,7 @@ M: node generate-node drop iterate-next ;
|
||||||
%jump-label ;
|
%jump-label ;
|
||||||
|
|
||||||
: generate-call ( label -- next )
|
: generate-call ( label -- next )
|
||||||
! dup maybe-compile
|
dup maybe-compile
|
||||||
end-basic-block
|
end-basic-block
|
||||||
dup compiling-loops get at [
|
dup compiling-loops get at [
|
||||||
%jump-label f
|
%jump-label f
|
||||||
|
|
|
@ -22,9 +22,6 @@ IN: compiler.tree.builder
|
||||||
] with-tree-builder nip
|
] with-tree-builder nip
|
||||||
unclip-last in-d>> ;
|
unclip-last in-d>> ;
|
||||||
|
|
||||||
: ends-with-terminate? ( nodes -- ? )
|
|
||||||
dup empty? [ drop f ] [ peek #terminate? ] if ;
|
|
||||||
|
|
||||||
: build-sub-tree ( #call quot -- nodes )
|
: build-sub-tree ( #call quot -- nodes )
|
||||||
[ [ out-d>> ] [ in-d>> ] bi ] dip build-tree-with
|
[ [ out-d>> ] [ in-d>> ] bi ] dip build-tree-with
|
||||||
over ends-with-terminate?
|
over ends-with-terminate?
|
||||||
|
|
|
@ -117,11 +117,19 @@ M: #branch cleanup*
|
||||||
[ live-branches>> live-branches set ]
|
[ live-branches>> live-branches set ]
|
||||||
} cleave ;
|
} 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*
|
M: #phi cleanup*
|
||||||
#! Remove #phi function inputs which no longer exist.
|
#! Remove #phi function inputs which no longer exist.
|
||||||
live-branches get
|
live-branches get
|
||||||
[ '[ , select-children sift ] change-phi-in-d ]
|
[ '[ , select-children sift ] change-phi-in-d ]
|
||||||
[ '[ , select-children sift ] change-phi-info-d ] bi
|
[ '[ , select-children sift ] change-phi-info-d ] bi
|
||||||
|
eliminate-phi
|
||||||
live-branches off ;
|
live-branches off ;
|
||||||
|
|
||||||
: >copy ( node -- #copy ) [ in-d>> ] [ out-d>> ] bi #copy ;
|
: >copy ( node -- #copy ) [ in-d>> ] [ out-d>> ] bi #copy ;
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
! Copyright (C) 2008 Slava Pestov.
|
! Copyright (C) 2008 Slava Pestov.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: sequences namespaces kernel accessors assocs sets fry
|
USING: sequences namespaces kernel accessors assocs sets fry
|
||||||
arrays combinators columns stack-checker.backend compiler.tree
|
arrays combinators columns stack-checker.backend
|
||||||
compiler.tree.combinators compiler.tree.dead-code.liveness
|
stack-checker.branches compiler.tree compiler.tree.combinators
|
||||||
compiler.tree.dead-code.simple ;
|
compiler.tree.dead-code.liveness compiler.tree.dead-code.simple
|
||||||
|
;
|
||||||
IN: compiler.tree.dead-code.branches
|
IN: compiler.tree.dead-code.branches
|
||||||
|
|
||||||
M: #if mark-live-values* look-at-inputs ;
|
M: #if mark-live-values* look-at-inputs ;
|
||||||
|
@ -26,10 +27,9 @@ M: #branch remove-dead-code*
|
||||||
bi ;
|
bi ;
|
||||||
|
|
||||||
: remove-phi-inputs ( #phi -- )
|
: remove-phi-inputs ( #phi -- )
|
||||||
dup [ out-d>> ] [ phi-in-d>> flip ] bi
|
if-node get children>>
|
||||||
filter-corresponding
|
[ dup ends-with-terminate? [ drop f ] [ peek out-d>> ] if ] map
|
||||||
flip >>phi-in-d
|
pad-with-bottom >>phi-in-d drop ;
|
||||||
drop ;
|
|
||||||
|
|
||||||
: live-value-indices ( values -- indices )
|
: live-value-indices ( values -- indices )
|
||||||
[ length ] keep live-values get
|
[ length ] keep live-values get
|
||||||
|
@ -42,7 +42,10 @@ M: #branch remove-dead-code*
|
||||||
#shuffle ;
|
#shuffle ;
|
||||||
|
|
||||||
: insert-drops ( nodes values indices -- nodes' )
|
: insert-drops ( nodes values indices -- nodes' )
|
||||||
'[ , drop-values suffix ] 2map ;
|
'[
|
||||||
|
over ends-with-terminate?
|
||||||
|
[ drop ] [ , drop-values suffix ] if
|
||||||
|
] 2map ;
|
||||||
|
|
||||||
: hoist-drops ( #phi -- )
|
: hoist-drops ( #phi -- )
|
||||||
if-node get swap
|
if-node get swap
|
||||||
|
@ -50,8 +53,7 @@ M: #branch remove-dead-code*
|
||||||
'[ , , insert-drops ] change-children drop ;
|
'[ , , insert-drops ] change-children drop ;
|
||||||
|
|
||||||
: remove-phi-outputs ( #phi -- )
|
: remove-phi-outputs ( #phi -- )
|
||||||
[ filter-live ] change-out-d
|
[ filter-live ] change-out-d drop ;
|
||||||
drop ;
|
|
||||||
|
|
||||||
M: #phi remove-dead-code*
|
M: #phi remove-dead-code*
|
||||||
{
|
{
|
||||||
|
|
|
@ -98,3 +98,5 @@ IN: compiler.tree.dead-code.tests
|
||||||
[ ] [ [ dup [ 3 throw ] [ ] if ] optimize-quot drop ] unit-test
|
[ ] [ [ dup [ 3 throw ] [ ] if ] optimize-quot drop ] unit-test
|
||||||
|
|
||||||
[ [ [ . ] [ drop ] if ] ] [ [ [ dup . ] [ ] if drop ] optimize-quot ] unit-test
|
[ [ [ . ] [ drop ] if ] ] [ [ [ dup . ] [ ] if drop ] optimize-quot ] unit-test
|
||||||
|
|
||||||
|
[ [ f ] ] [ [ f dup [ ] [ ] if ] optimize-quot ] unit-test
|
||||||
|
|
|
@ -183,6 +183,9 @@ M: #return-recursive inputs/outputs [ in-d>> ] [ out-d>> ] bi ;
|
||||||
: recursive-phi-in ( #enter-recursive -- seq )
|
: recursive-phi-in ( #enter-recursive -- seq )
|
||||||
[ label>> calls>> [ in-d>> ] map ] [ in-d>> ] bi suffix ;
|
[ 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 child-visitor V{ } clone ;
|
||||||
M: vector #introduce, #introduce node, ;
|
M: vector #introduce, #introduce node, ;
|
||||||
M: vector #call, #call node, ;
|
M: vector #call, #call node, ;
|
||||||
|
|
Loading…
Reference in New Issue