compiler.cfg.linear-scan.assignment: refactoring + tests

better expire-old-intervals, activate-new-intervals and assign-gc-roots
locals-and-roots
Björn Lindqvist 2016-04-03 02:48:37 +02:00
parent 86606213de
commit 1a71407112
2 changed files with 34 additions and 26 deletions

View File

@ -6,13 +6,36 @@ cpu.x86.assembler.operands grouping heaps kernel make namespaces random
sequences sorting tools.test ; sequences sorting tools.test ;
IN: compiler.cfg.linear-scan.assignment.tests IN: compiler.cfg.linear-scan.assignment.tests
: cherry-pick ( seq indices -- seq' )
[ swap nth ] with map ;
: (setup-vreg-spills) ( vreg-defs -- reps leaders spill-slots )
[ [ 2 head ] map ]
[ [ { 0 2 } cherry-pick ] map ]
[
[
first4 [ nip [ rep-size 2array ] dip 2array ] [ 3drop f ] if*
] map sift
] tri ;
: setup-vreg-spills ( vreg-defs -- )
(setup-vreg-spills)
[ representations set ] [ leader-map set ] [ spill-slots set ] tri* ;
! assign-gc-roots
{
T{ gc-map { gc-roots { T{ spill-slot { n 7 } } } } }
} [
{ { 23 int-rep 23 T{ spill-slot { n 7 } } } } setup-vreg-spills
<gc-map> 23 1array >>gc-roots [ assign-gc-roots ] keep
] unit-test
! assign-insn-defs ! assign-insn-defs
{ {
T{ ##peek { dst RAX } { loc T{ ds-loc } } { insn# 0 } } T{ ##peek { dst RAX } { loc T{ ds-loc } } { insn# 0 } }
} [ } [
H{ { 37 RAX } } pending-interval-assoc set H{ { 37 RAX } } pending-interval-assoc set
H{ { 37 int-rep } } representations set { { 37 int-rep 37 f } } setup-vreg-spills
H{ { 37 37 } } leader-map set
T{ ##peek f 37 D: 0 0 } [ assign-insn-defs ] keep T{ ##peek f 37 D: 0 0 } [ assign-insn-defs ] keep
] unit-test ] unit-test
@ -46,6 +69,12 @@ IN: compiler.cfg.linear-scan.assignment.tests
[ assign-registers-in-block ] keep instructions>> [ assign-registers-in-block ] keep instructions>>
] unit-test ] unit-test
! expire-old-intervals
{ 3 } [
90 { 50 90 95 120 } [ 25 <live-interval> 2array ] map >min-heap
[ expire-old-intervals ] keep heap-size
] unit-test
! insert-reload ! insert-reload
{ {
{ T{ ##reload { dst RAX } { rep int-rep } { src T{ spill-slot } } } } { T{ ##reload { dst RAX } { rep int-rep } { src T{ spill-slot } } } }
@ -74,22 +103,6 @@ IN: compiler.cfg.linear-scan.assignment.tests
] V{ } make ] V{ } make
] unit-test ] unit-test
: cherry-pick ( seq indices -- seq' )
[ swap nth ] with map ;
: (setup-vreg-spills) ( vreg-defs -- reps leaders spill-slots )
[ [ 2 head ] map ]
[ [ { 0 2 } cherry-pick ] map ]
[
[
first4 [ nip [ rep-size 2array ] dip 2array ] [ 3drop f ] if*
] map sift
] tri ;
: setup-vreg-spills ( vreg-defs -- )
(setup-vreg-spills)
[ representations set ] [ leader-map set ] [ spill-slots set ] tri* ;
! vreg>spill-slot ! vreg>spill-slot
{ T{ spill-slot { n 990 } } } [ { T{ spill-slot { n 990 } } } [
{ { 10 int-rep 10 T{ spill-slot { n 990 } } } } setup-vreg-spills { { 10 int-rep 10 T{ spill-slot { n 990 } } } } setup-vreg-spills
@ -114,8 +127,3 @@ IN: compiler.cfg.linear-scan.assignment.tests
{ { 3 7 } { -1 56 } { -1 3 } } >min-heap [ -1 = ] heap-pop-while { { 3 7 } { -1 56 } { -1 3 } } >min-heap [ -1 = ] heap-pop-while
natural-sort natural-sort
] unit-test ] unit-test
{ 3 } [
90 { 50 90 95 120 } [ 25 <live-interval> 2array ] map >min-heap
[ expire-old-intervals ] keep heap-size
] unit-test

View File

@ -75,7 +75,7 @@ SYMBOL: machine-live-outs
[ remove-pending ] [ handle-spill ] bi ; [ remove-pending ] [ handle-spill ] bi ;
: expire-old-intervals ( n pending-heap -- ) : expire-old-intervals ( n pending-heap -- )
swap '[ _ < ] heap-pop-while [ expire-interval ] each ; [ > ] with heap-pop-while [ expire-interval ] each ;
: insert-reload ( live-interval -- ) : insert-reload ( live-interval -- )
[ reg>> ] [ reload-rep>> ] [ reload-from>> ] tri ##reload, ; [ reg>> ] [ reload-rep>> ] [ reload-from>> ] tri ##reload, ;
@ -87,7 +87,7 @@ SYMBOL: machine-live-outs
[ add-pending ] [ handle-reload ] bi ; [ add-pending ] [ handle-reload ] bi ;
: activate-new-intervals ( n unhandled-heap -- ) : activate-new-intervals ( n unhandled-heap -- )
swap '[ _ = ] heap-pop-while [ activate-interval ] each ; [ = ] with heap-pop-while [ activate-interval ] each ;
: prepare-insn ( n -- ) : prepare-insn ( n -- )
[ pending-interval-heap get expire-old-intervals ] [ pending-interval-heap get expire-old-intervals ]
@ -99,7 +99,7 @@ RENAMING: assign [ vreg>reg ] [ vreg>reg ] [ vreg>reg ]
[ assign-insn-defs ] [ assign-insn-uses ] [ assign-insn-temps ] tri ; [ assign-insn-defs ] [ assign-insn-uses ] [ assign-insn-temps ] tri ;
: assign-gc-roots ( gc-map -- ) : assign-gc-roots ( gc-map -- )
[ [ vreg>spill-slot ] map ] change-gc-roots drop ; gc-roots>> [ vreg>spill-slot ] map! drop ;
: assign-derived-roots ( gc-map -- ) : assign-derived-roots ( gc-map -- )
[ [ [ vreg>spill-slot ] bi@ ] assoc-map ] change-derived-roots drop ; [ [ [ vreg>spill-slot ] bi@ ] assoc-map ] change-derived-roots drop ;