From 5061db2a48a83151f56ab0c7af227df36a1b27f8 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Fri, 17 Jul 2009 22:57:28 -0500 Subject: [PATCH] compiler.cfg: Move tail call optimization to the end, compiler.tree: simplify finalization pass because of this --- basis/compiler/cfg/optimizer/optimizer.factor | 2 +- .../cfg/stack-analysis/stack-analysis-tests.factor | 6 +++--- .../compiler/tree/finalization/finalization.factor | 13 +------------ 3 files changed, 5 insertions(+), 16 deletions(-) diff --git a/basis/compiler/cfg/optimizer/optimizer.factor b/basis/compiler/cfg/optimizer/optimizer.factor index 1af0fcbc53..49a07de1e4 100644 --- a/basis/compiler/cfg/optimizer/optimizer.factor +++ b/basis/compiler/cfg/optimizer/optimizer.factor @@ -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 ; diff --git a/basis/compiler/cfg/stack-analysis/stack-analysis-tests.factor b/basis/compiler/cfg/stack-analysis/stack-analysis-tests.factor index 9fbf7acf78..64e75aa7e9 100644 --- a/basis/compiler/cfg/stack-analysis/stack-analysis-tests.factor +++ b/basis/compiler/cfg/stack-analysis/stack-analysis-tests.factor @@ -99,7 +99,7 @@ IN: compiler.cfg.stack-analysis.tests ! Correct height tracking [ t ] [ [ pick [ ] [ 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 ] [ diff --git a/basis/compiler/tree/finalization/finalization.factor b/basis/compiler/tree/finalization/finalization.factor index 4c17399c95..d1dd4e39a4 100644 --- a/basis/compiler/tree/finalization/finalization.factor +++ b/basis/compiler/tree/finalization/finalization.factor @@ -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 ;