compiler.cfg: Move tail call optimization to the end, compiler.tree: simplify finalization pass because of this

db4
Slava Pestov 2009-07-17 22:57:28 -05:00
parent b83f27af74
commit 5061db2a48
3 changed files with 5 additions and 16 deletions
basis/compiler
tree/finalization

View File

@ -28,7 +28,6 @@ SYMBOL: check-optimizer?
! Note that compute-predecessors has to be called several times.
! The passes that need this document it.
[
optimize-tail-calls
delete-useless-conditionals
compute-predecessors
split-branches
@ -42,5 +41,6 @@ SYMBOL: check-optimizer?
eliminate-dead-code
eliminate-write-barriers
eliminate-phis
optimize-tail-calls
?check
] with-scope ;

View File

@ -99,7 +99,7 @@ IN: compiler.cfg.stack-analysis.tests
! Correct height tracking
[ t ] [
[ pick [ <array> ] [ drop ] if swap ] test-stack-analysis eliminate-dead-code
reverse-post-order 4 swap nth
reverse-post-order 3 swap nth
instructions>> [ ##peek? ] filter first2 [ loc>> ] [ loc>> ] bi*
2array { D 1 D 0 } set=
] unit-test
@ -170,9 +170,9 @@ IN: compiler.cfg.stack-analysis.tests
! Inserted ##peeks reference the wrong stack location
[ t ] [
[ [ "B" ] 2dip dup [ [ /mod ] dip ] when ] test-stack-analysis
eliminate-dead-code reverse-post-order 4 swap nth
eliminate-dead-code reverse-post-order 3 swap nth
instructions>> [ ##peek? ] filter [ loc>> ] map
{ D 0 D 1 } set=
{ R 0 D 0 D 1 } set=
] unit-test
[ D 0 ] [

View File

@ -1,4 +1,4 @@
! Copyright (C) 2008 Slava Pestov.
! Copyright (C) 2008, 2009 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
USING: kernel accessors sequences words memoize combinators
classes classes.builtin classes.tuple math.partial-dispatch
@ -17,23 +17,12 @@ IN: compiler.tree.finalization
! propagation since we need to see 'fixnum?' instead of
! 'tag 0 eq?' and so on, for semantic reasoning.
! We also delete empty stack shuffles and copies to facilitate
! tail call optimization in the code generator.
GENERIC: finalize* ( node -- nodes )
: finalize ( nodes -- nodes' ) [ finalize* ] map-nodes ;
: splice-final ( quot -- nodes ) splice-quot finalize ;
M: #copy finalize* drop f ;
M: #shuffle finalize*
dup
[ [ in-d>> ] [ out-d>> ] [ mapping>> ] tri '[ _ at ] map sequence= ]
[ [ in-r>> ] [ out-r>> ] [ mapping>> ] tri '[ _ at ] map sequence= ]
bi and [ drop f ] when ;
MEMO: cached-expansion ( word -- nodes )
def>> splice-final ;