diff --git a/basis/compiler/cfg/linear-scan/allocation/spilling/spilling.factor b/basis/compiler/cfg/linear-scan/allocation/spilling/spilling.factor index 73d4570b02..e5c4b10021 100644 --- a/basis/compiler/cfg/linear-scan/allocation/spilling/spilling.factor +++ b/basis/compiler/cfg/linear-scan/allocation/spilling/spilling.factor @@ -48,9 +48,7 @@ ERROR: bad-live-ranges interval ; } 2cleave ; : assign-spill ( live-interval -- live-interval ) - dup reload-from>> - [ dup vreg>> reg-class>> next-spill-location ] unless* - >>spill-to ; + dup vreg>> assign-spill-slot >>spill-to ; : assign-reload ( before after -- before after ) over spill-to>> >>reload-from ; diff --git a/basis/compiler/cfg/linear-scan/allocation/state/state.factor b/basis/compiler/cfg/linear-scan/allocation/state/state.factor index 737133aa32..a17a1181b5 100644 --- a/basis/compiler/cfg/linear-scan/allocation/state/state.factor +++ b/basis/compiler/cfg/linear-scan/allocation/state/state.factor @@ -109,18 +109,26 @@ CONSTANT: reg-classes { int-regs double-float-regs } : reg-class-assoc ( quot -- assoc ) [ reg-classes ] dip { } map>assoc ; inline +! Mapping from register classes to spill counts SYMBOL: spill-counts -: next-spill-location ( reg-class -- n ) +: next-spill-slot ( reg-class -- n ) spill-counts get [ dup 1 + ] change-at ; +! Mapping from vregs to spill slots +SYMBOL: spill-slots + +: assign-spill-slot ( vreg -- n ) + spill-slots get [ reg-class>> next-spill-slot ] cache ; + : init-allocator ( registers -- ) registers set - [ 0 ] reg-class-assoc spill-counts set unhandled-intervals set [ V{ } clone ] reg-class-assoc active-intervals set [ V{ } clone ] reg-class-assoc inactive-intervals set V{ } clone handled-intervals set + [ 0 ] reg-class-assoc spill-counts set + H{ } clone spill-slots set -1 progress set ; : init-unhandled ( live-intervals -- )