! 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
! Instructions which don't have any effect on the stack
UNION: neutral-insn
##flushable
- ##effect
- ##loop-entry ;
+ ##effect ;
M: neutral-insn visit , ;
##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 ;