Cleaning up DCE

db4
Slava Pestov 2008-08-22 18:09:48 -05:00
parent 3eb0476811
commit fd8136786b
5 changed files with 43 additions and 33 deletions

View File

@ -144,7 +144,7 @@ M: object xyz ;
[ f ] [ [ dup 0 < [ neg ] when ] \ - inlined? ] unit-test [ f ] [ [ dup 0 < [ neg ] when ] \ - inlined? ] unit-test
[ f ] [ [ t ] [
[ [
[ no-cond ] 1 [ no-cond ] 1
[ 1array dup quotation? [ >quotation ] unless ] times [ 1array dup quotation? [ >quotation ] unless ] times
@ -433,7 +433,7 @@ cell-bits 32 = [
] { >= fixnum>= } inlined? ] { >= fixnum>= } inlined?
] unit-test ] unit-test
[ t ] [ [ ] [
[ [
4 pick array-capacity? 4 pick array-capacity?
[ set-slot ] [ \ array-capacity 2nip bad-slot-value ] if [ set-slot ] [ \ array-capacity 2nip bad-slot-value ] if

View File

@ -35,7 +35,7 @@ M: #branch remove-dead-code*
[ length ] keep live-values get [ length ] keep live-values get
'[ , nth , key? ] filter ; inline '[ , nth , key? ] filter ; inline
: drop-values ( values indices -- node ) : drop-indexed-values ( values indices -- node )
[ drop filter-live ] [ nths ] 2bi [ drop filter-live ] [ nths ] 2bi
[ make-values ] keep [ make-values ] keep
[ drop ] [ zip ] 2bi [ drop ] [ zip ] 2bi
@ -44,7 +44,7 @@ M: #branch remove-dead-code*
: insert-drops ( nodes values indices -- nodes' ) : insert-drops ( nodes values indices -- nodes' )
'[ '[
over ends-with-terminate? over ends-with-terminate?
[ drop ] [ , drop-values suffix ] if [ drop ] [ , drop-indexed-values suffix ] if
] 2map ; ] 2map ;
: hoist-drops ( #phi -- ) : hoist-drops ( #phi -- )

View File

@ -25,14 +25,13 @@ M: #call-recursive compute-live-values*
[ out-d>> ] [ label>> return>> in-d>> ] bi look-at-mapping ; [ out-d>> ] [ label>> return>> in-d>> ] bi look-at-mapping ;
:: drop-dead-inputs ( inputs outputs -- #shuffle ) :: drop-dead-inputs ( inputs outputs -- #shuffle )
[let* | new-inputs [ inputs make-values ] [let* | live-inputs [ inputs filter-live ]
live-inputs [ outputs inputs filter-corresponding ] new-live-inputs [ outputs inputs filter-corresponding make-values ] |
new-live-inputs [ outputs new-inputs filter-corresponding ] live-inputs
mapping [ new-live-inputs live-inputs zip ] |
inputs filter-live
new-live-inputs new-live-inputs
mapping outputs
#shuffle inputs
drop-values
] ; ] ;
M: #recursive remove-dead-code* ( node -- nodes ) M: #recursive remove-dead-code* ( node -- nodes )
@ -53,18 +52,21 @@ M: #enter-recursive remove-dead-code*
[ nip ] [ nip ]
2bi ; 2bi ;
:: drop-call-recursive-outputs ( node -- #shuffle ) :: (drop-call-recursive-outputs) ( inputs outputs -- #shuffle )
[let* | node-out [ node out-d>> ] [let* | new-live-outputs [ inputs outputs filter-corresponding make-values ]
return-in [ node label>> return>> in-d>> ] live-outputs [ outputs filter-live ] |
node-out-live [ return-in node-out filter-corresponding ] new-live-outputs
new-node-out-live [ node-out-live make-values ] live-outputs
node-out-dropped [ node-out filter-live ] live-outputs
new-node-out-dropped [ node-out-dropped new-node-out-live filter-corresponding ] new-live-outputs
mapping [ node-out-dropped new-node-out-dropped zip ] | drop-values
node new-node-out-live >>out-d drop
new-node-out-live node-out-dropped mapping #shuffle
] ; ] ;
: drop-call-recursive-outputs ( node -- #shuffle )
dup [ label>> return>> in-d>> ] [ out-d>> ] bi
(drop-call-recursive-outputs)
[ in-d>> >>out-d drop ] keep ;
M: #call-recursive remove-dead-code* M: #call-recursive remove-dead-code*
[ drop-call-recursive-inputs ] [ drop-call-recursive-inputs ]
[ ] [ ]

View File

@ -61,20 +61,28 @@ M: #alien-indirect compute-live-values* nip look-at-inputs ;
: filter-live ( values -- values' ) : filter-live ( values -- values' )
[ live-value? ] filter ; [ live-value? ] filter ;
: drop-dead-values ( in out -- #shuffle ) :: drop-values ( inputs outputs mapping-keys mapping-values -- #shuffle )
[ make-values dup ] keep zip #shuffle ; inputs
outputs
outputs
mapping-keys
mapping-values
filter-corresponding zip #shuffle ; inline
:: drop-dead-outputs ( node -- nodes ) :: drop-dead-values ( outputs -- #shuffle )
[let* | old-outputs [ node out-d>> ] [let* | new-outputs [ outputs make-values ]
new-outputs [ old-outputs make-values ] live-outputs [ outputs filter-live ] |
old-live-outputs [ old-outputs filter-live ] new-outputs
new-live-outputs [ old-outputs new-outputs filter-corresponding ] live-outputs
mapping [ old-live-outputs new-live-outputs zip ] | outputs
node new-outputs >>out-d new-outputs
new-outputs old-live-outputs mapping #shuffle drop-values
2array
] ; ] ;
: drop-dead-outputs ( node -- nodes )
dup out-d>> drop-dead-values
[ in-d>> >>out-d drop ] [ 2array ] 2bi ;
M: #introduce remove-dead-code* ( #introduce -- nodes ) M: #introduce remove-dead-code* ( #introduce -- nodes )
drop-dead-outputs ; drop-dead-outputs ;

View File

@ -3,7 +3,7 @@
USING: kernel assocs fry match accessors namespaces effects USING: kernel assocs fry match accessors namespaces effects
sequences sequences.private quotations generic macros arrays sequences sequences.private quotations generic macros arrays
prettyprint prettyprint.backend prettyprint.sections math words prettyprint prettyprint.backend prettyprint.sections math words
combinators io sorting combinators io sorting hints
compiler.tree compiler.tree
compiler.tree.builder compiler.tree.builder
compiler.tree.optimizer compiler.tree.optimizer