Fix loop handling in stack-analysis
							parent
							
								
									32f17f3e14
								
							
						
					
					
						commit
						2c8223fdaf
					
				| 
						 | 
				
			
			@ -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
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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 ;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue