From d07c0429fc23b2b24f6d4d6c59079774e0b936c9 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Fri, 3 Jul 2009 22:51:40 -0500 Subject: [PATCH] compiler.cfg.linear-scan: assign spill slots to vregs globally, so that resolve pass never has to perform a memory->memory transfer --- .../linear-scan/allocation/spilling/spilling.factor | 4 +--- .../cfg/linear-scan/allocation/state/state.factor | 12 ++++++++++-- 2 files changed, 11 insertions(+), 5 deletions(-) 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 -- )