Fix loop handling in stack-analysis

Slava Pestov 2009-05-31 19:04:26 -05:00
parent 0375ce6bb4
commit 6ac52761c6
3 changed files with 16 additions and 9 deletions

View File

@ -28,6 +28,7 @@ IN: compiler.cfg.optimizer.tests
[ [ 2 fixnum* ] when 3 ]
[ [ 2 fixnum+ ] when 3 ]
[ [ 2 fixnum- ] when 3 ]
[ 10000 [ ] times ]
} [
[ [ ] ] dip '[ _ test-mr first check-mr ] unit-test
] each

View File

@ -106,7 +106,8 @@ IN: compiler.cfg.stack-analysis.tests
! Sync before a back-edge, not after
! ##peeks should be inserted before a ##loop-entry
[ 1 ] [
! Don't optimize out the constants
[ 1 t ] [
[ 1000 [ ] times ] test-stack-analysis eliminate-dead-code linearize
[ ##add-imm? ] count
[ [ ##add-imm? ] count ] [ [ ##load-immediate? ] any? ] bi
] unit-test

View File

@ -87,8 +87,7 @@ GENERIC: visit ( insn -- )
! Instructions which don't have any effect on the stack
UNION: neutral-insn
##flushable
##effect
##loop-entry ;
##effect ;
M: neutral-insn visit , ;
@ -96,17 +95,23 @@ UNION: sync-if-back-edge
##branch
##conditional-branch
##compare-imm-branch
##dispatch ;
##dispatch
##loop-entry ;
SYMBOL: local-only?
t local-only? set-global
: back-edge? ( from to -- ? )
[ number>> ] bi@ > ;
: sync-state? ( -- ? )
basic-block get successors>>
[ [ predecessors>> ] keep '[ _ back-edge? ] any? ] any?
local-only? get or ;
M: sync-if-back-edge visit
basic-block get [ successors>> ] [ number>> ] bi
'[ number>> _ < local-only? get or ] any?
[ sync-state ] when
, ;
sync-state? [ sync-state ] when , ;
: adjust-d ( n -- ) state get [ + ] change-ds-height drop ;