compiler.cfg.linear-scan: code cleanups
parent
c20e6c290f
commit
4507bdcbc0
|
@ -29,7 +29,7 @@ IN: compiler.cfg.linear-scan.allocation
|
||||||
second 0 = ; inline
|
second 0 = ; inline
|
||||||
|
|
||||||
: register-partially-available ( new result -- )
|
: register-partially-available ( new result -- )
|
||||||
[ second split-before-use ] keep
|
[ second split-to-fit ] keep
|
||||||
'[ _ register-available ] [ add-unhandled ] bi* ;
|
'[ _ register-available ] [ add-unhandled ] bi* ;
|
||||||
|
|
||||||
: assign-register ( new -- )
|
: assign-register ( new -- )
|
||||||
|
|
|
@ -80,10 +80,10 @@ ERROR: bad-live-ranges interval ;
|
||||||
[ add-unhandled ]
|
[ add-unhandled ]
|
||||||
} cleave ;
|
} cleave ;
|
||||||
|
|
||||||
: split-intersecting? ( live-interval new reg -- ? )
|
: spill-live-out ( live-interval -- )
|
||||||
{ [ [ drop reg>> ] dip = ] [ drop intervals-intersect? ] } 3&& ;
|
! The interval has no more usages after the spill location. This
|
||||||
|
! means it is the first child of an interval that was split. We
|
||||||
: split-live-out ( live-interval -- )
|
! spill the value and let the resolve pass insert a reload later.
|
||||||
{
|
{
|
||||||
[ trim-before-ranges ]
|
[ trim-before-ranges ]
|
||||||
[ compute-start/end ]
|
[ compute-start/end ]
|
||||||
|
@ -91,7 +91,11 @@ ERROR: bad-live-ranges interval ;
|
||||||
[ add-handled ]
|
[ add-handled ]
|
||||||
} cleave ;
|
} cleave ;
|
||||||
|
|
||||||
: split-live-in ( live-interval -- )
|
: spill-live-in ( live-interval -- )
|
||||||
|
! The interval does not have any usages before the spill location.
|
||||||
|
! This means it is the second child of an interval that was
|
||||||
|
! split. We reload the value and let the resolve pass insert a
|
||||||
|
! split later.
|
||||||
{
|
{
|
||||||
[ trim-after-ranges ]
|
[ trim-after-ranges ]
|
||||||
[ compute-start/end ]
|
[ compute-start/end ]
|
||||||
|
@ -99,40 +103,48 @@ ERROR: bad-live-ranges interval ;
|
||||||
[ add-unhandled ]
|
[ add-unhandled ]
|
||||||
} cleave ;
|
} cleave ;
|
||||||
|
|
||||||
: (split-intersecting) ( live-interval new -- )
|
: (spill-intersecting) ( live-interval new -- )
|
||||||
start>> {
|
start>> {
|
||||||
{ [ 2dup [ uses>> last ] dip < ] [ drop split-live-out ] }
|
{ [ 2dup [ uses>> last ] dip < ] [ drop spill-live-out ] }
|
||||||
{ [ 2dup [ uses>> first ] dip > ] [ drop split-live-in ] }
|
{ [ 2dup [ uses>> first ] dip > ] [ drop spill-live-in ] }
|
||||||
[ split-and-spill [ add-handled ] [ add-unhandled ] bi* ]
|
[ split-and-spill [ add-handled ] [ add-unhandled ] bi* ]
|
||||||
} cond ;
|
} cond ;
|
||||||
|
|
||||||
: (split-intersecting-active) ( active new -- )
|
:: spill-intersecting-active ( new reg -- )
|
||||||
[ drop delete-active ]
|
! If there is an active interval using 'reg' (there should be at
|
||||||
[ (split-intersecting) ] 2bi ;
|
! most one) are split and spilled and removed from the inactive
|
||||||
|
! set.
|
||||||
|
new vreg>> active-intervals-for [ [ reg>> reg = ] find swap dup ] keep
|
||||||
|
'[ _ delete-nth new (spill-intersecting) ] [ 2drop ] if ;
|
||||||
|
|
||||||
: split-intersecting-active ( new reg -- )
|
:: spill-intersecting-inactive ( new reg -- )
|
||||||
[ [ vreg>> active-intervals-for ] keep ] dip
|
! Any inactive intervals using 'reg' are split and spilled
|
||||||
[ '[ _ _ split-intersecting? ] filter ] 2keep drop
|
! and removed from the inactive set.
|
||||||
'[ _ (split-intersecting-active) ] each ;
|
new vreg>> inactive-intervals-for [
|
||||||
|
dup reg>> reg = [
|
||||||
|
dup new intervals-intersect? [
|
||||||
|
new (spill-intersecting) f
|
||||||
|
] [ drop t ] if
|
||||||
|
] [ drop t ] if
|
||||||
|
] filter-here ;
|
||||||
|
|
||||||
: (split-intersecting-inactive) ( inactive new -- )
|
: spill-intersecting ( new reg -- )
|
||||||
[ drop delete-inactive ]
|
! Split and spill all active and inactive intervals
|
||||||
[ (split-intersecting) ] 2bi ;
|
! which intersect 'new' and use 'reg'.
|
||||||
|
[ spill-intersecting-active ]
|
||||||
: split-intersecting-inactive ( new reg -- )
|
[ spill-intersecting-inactive ]
|
||||||
[ [ vreg>> inactive-intervals-for ] keep ] dip
|
|
||||||
[ '[ _ _ split-intersecting? ] filter ] 2keep drop
|
|
||||||
'[ _ (split-intersecting-inactive) ] each ;
|
|
||||||
|
|
||||||
: split-intersecting ( new reg -- )
|
|
||||||
[ split-intersecting-active ]
|
|
||||||
[ split-intersecting-inactive ]
|
|
||||||
2bi ;
|
2bi ;
|
||||||
|
|
||||||
: spill-available ( new pair -- )
|
: spill-available ( new pair -- )
|
||||||
[ first split-intersecting ] [ register-available ] 2bi ;
|
! A register would become fully available if all
|
||||||
|
! active and inactive intervals using it were split
|
||||||
|
! and spilled.
|
||||||
|
[ first spill-intersecting ] [ register-available ] 2bi ;
|
||||||
|
|
||||||
: spill-partially-available ( new pair -- )
|
: spill-partially-available ( new pair -- )
|
||||||
|
! A register would be available for part of the new
|
||||||
|
! interval's lifetime if all active and inactive intervals
|
||||||
|
! using that register were split and spilled.
|
||||||
[ second 1 - split-and-spill add-unhandled ] keep
|
[ second 1 - split-and-spill add-unhandled ] keep
|
||||||
spill-available ;
|
spill-available ;
|
||||||
|
|
||||||
|
|
|
@ -72,7 +72,7 @@ HINTS: split-interval live-interval object ;
|
||||||
[ 1 + '[ _ > ] filter ]
|
[ 1 + '[ _ > ] filter ]
|
||||||
2tri 3append ;
|
2tri 3append ;
|
||||||
|
|
||||||
: split-before-use ( new n -- before after )
|
: split-to-fit ( new n -- before after )
|
||||||
1 -
|
1 -
|
||||||
2dup swap covers? [
|
2dup swap covers? [
|
||||||
[ '[ _ insert-use-for-copy ] change-uses ] keep
|
[ '[ _ insert-use-for-copy ] change-uses ] keep
|
||||||
|
|
|
@ -175,7 +175,7 @@ check-numbering? on
|
||||||
{ end 5 }
|
{ end 5 }
|
||||||
{ uses V{ 0 1 5 } }
|
{ uses V{ 0 1 5 } }
|
||||||
{ ranges V{ T{ live-range f 0 5 } } }
|
{ ranges V{ T{ live-range f 0 5 } } }
|
||||||
} 5 split-before-use [ f >>split-next ] bi@
|
} 5 split-to-fit [ f >>split-next ] bi@
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
||||||
[
|
[
|
||||||
|
@ -200,7 +200,7 @@ check-numbering? on
|
||||||
{ end 10 }
|
{ end 10 }
|
||||||
{ uses V{ 0 1 10 } }
|
{ uses V{ 0 1 10 } }
|
||||||
{ ranges V{ T{ live-range f 0 10 } } }
|
{ ranges V{ T{ live-range f 0 10 } } }
|
||||||
} 5 split-before-use [ f >>split-next ] bi@
|
} 5 split-to-fit [ f >>split-next ] bi@
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
||||||
[
|
[
|
||||||
|
@ -225,7 +225,7 @@ check-numbering? on
|
||||||
{ end 10 }
|
{ end 10 }
|
||||||
{ uses V{ 0 1 4 5 10 } }
|
{ uses V{ 0 1 4 5 10 } }
|
||||||
{ ranges V{ T{ live-range f 0 10 } } }
|
{ ranges V{ T{ live-range f 0 10 } } }
|
||||||
} 5 split-before-use [ f >>split-next ] bi@
|
} 5 split-to-fit [ f >>split-next ] bi@
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
||||||
[
|
[
|
||||||
|
|
Loading…
Reference in New Issue