compiler.cfg.linear-scan.resolve: More fixes

db4
Slava Pestov 2009-07-04 00:45:06 -05:00
parent da13681bc8
commit c00af97fa1
2 changed files with 82 additions and 13 deletions

View File

@ -1,7 +1,7 @@
! Copyright (C) 2008, 2009 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors kernel math assocs namespaces sequences heaps
fry make combinators sets
fry make combinators sets locals
cpu.architecture
compiler.cfg.def-use
compiler.cfg.registers
@ -116,8 +116,8 @@ ERROR: already-reloaded ;
] [ 2drop ] if
] if ;
: prepare-insn ( insn -- )
insn#>> [ expire-old-intervals ] [ activate-new-intervals ] bi ;
: prepare-insn ( n -- )
[ expire-old-intervals ] [ activate-new-intervals ] bi ;
GENERIC: assign-registers-in-insn ( insn -- )
@ -171,29 +171,33 @@ M: ##gc assign-registers-in-insn
M: insn assign-registers-in-insn drop ;
: begin-block ( bb -- )
dup block-from prepare-insn
[ block-from compute-live-values ] keep register-live-ins get set-at ;
: end-block ( bb -- )
[ block-to compute-live-values ] keep register-live-outs get set-at ;
: vreg-at-start ( vreg bb -- state ) register-live-ins get at at ;
ERROR: bad-vreg vreg ;
: vreg-at-end ( vreg bb -- state ) register-live-outs get at at ;
: vreg-at-start ( vreg bb -- state )
register-live-ins get at ?at [ bad-vreg ] unless ;
: assign-registers-in-block ( bb -- )
dup
begin-block
[
: vreg-at-end ( vreg bb -- state )
register-live-outs get at ?at [ bad-vreg ] unless ;
:: assign-registers-in-block ( bb -- )
bb [
[
bb begin-block
[
[ prepare-insn ]
[ insn#>> prepare-insn ]
[ assign-registers-in-insn ]
[ , ]
tri
] each
bb end-block
] V{ } make
] change-instructions
end-block ;
] change-instructions drop ;
: assign-registers ( live-intervals rpo -- )
[ init-assignment ] dip

View File

@ -1910,4 +1910,69 @@ V{
[ t ] [ 3 get instructions>> [ _spill? ] any? ] unit-test
[ t ] [ 5 get instructions>> [ _reload? ] any? ] unit-test
[ t ] [ 5 get instructions>> [ _reload? ] any? ] unit-test
! A more complicated failure case with resolve that came up after the above
! got fixed
V{ T{ ##branch } } 0 test-bb
V{
T{ ##peek f V int-regs 0 D 0 }
T{ ##peek f V int-regs 1 D 1 }
T{ ##peek f V int-regs 2 D 2 }
T{ ##peek f V int-regs 3 D 3 }
T{ ##peek f V int-regs 4 D 0 }
T{ ##branch }
} 1 test-bb
V{ T{ ##branch } } 2 test-bb
V{ T{ ##branch } } 3 test-bb
V{
T{ ##replace f V int-regs 1 D 1 }
T{ ##replace f V int-regs 2 D 2 }
T{ ##replace f V int-regs 3 D 3 }
T{ ##replace f V int-regs 4 D 4 }
T{ ##replace f V int-regs 0 D 0 }
T{ ##branch }
} 4 test-bb
V{ T{ ##replace f V int-regs 0 D 0 } T{ ##branch } } 5 test-bb
V{ T{ ##return } } 6 test-bb
V{ T{ ##branch } } 7 test-bb
V{
T{ ##replace f V int-regs 1 D 1 }
T{ ##replace f V int-regs 2 D 2 }
T{ ##replace f V int-regs 3 D 3 }
T{ ##peek f V int-regs 5 D 1 }
T{ ##peek f V int-regs 6 D 2 }
T{ ##peek f V int-regs 7 D 3 }
T{ ##peek f V int-regs 8 D 4 }
T{ ##replace f V int-regs 5 D 1 }
T{ ##replace f V int-regs 6 D 2 }
T{ ##replace f V int-regs 7 D 3 }
T{ ##replace f V int-regs 8 D 4 }
T{ ##branch }
} 8 test-bb
V{
T{ ##replace f V int-regs 1 D 1 }
T{ ##replace f V int-regs 2 D 2 }
T{ ##replace f V int-regs 3 D 3 }
T{ ##return }
} 9 test-bb
0 get 1 get 1vector >>successors drop
1 get 2 get 7 get V{ } 2sequence >>successors drop
7 get 8 get 1vector >>successors drop
8 get 9 get 1vector >>successors drop
2 get 3 get 5 get V{ } 2sequence >>successors drop
3 get 4 get 1vector >>successors drop
4 get 9 get 1vector >>successors drop
5 get 6 get 1vector >>successors drop
[ ] [ { 1 2 3 4 } test-linear-scan-on-cfg ] unit-test
[ _spill ] [ 1 get instructions>> second class ] unit-test
[ _reload ] [ 4 get instructions>> 4 swap nth class ] unit-test
[ V{ 3 2 1 } ] [ 8 get instructions>> [ _spill? ] filter [ n>> ] map ] unit-test
[ V{ 3 2 1 } ] [ 9 get instructions>> [ _reload? ] filter [ n>> ] map ] unit-test
! Resolve pass should insert this
[ _reload ] [ 5 get instructions>> first class ] unit-test