From dea872c7e3526b9df0bf9995d6084cdc9461de14 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Fri, 10 Jul 2009 00:25:46 -0500 Subject: [PATCH] compiler.cfg.linear-scan.allocation: fix broken spill slot reuse logic --- .../allocation/coalescing/coalescing.factor | 15 +++++++++++---- .../allocation/spilling/spilling.factor | 4 ++-- .../cfg/linear-scan/allocation/state/state.factor | 14 ++------------ 3 files changed, 15 insertions(+), 18 deletions(-) diff --git a/basis/compiler/cfg/linear-scan/allocation/coalescing/coalescing.factor b/basis/compiler/cfg/linear-scan/allocation/coalescing/coalescing.factor index e99c2ba710..ef8a9c56f8 100644 --- a/basis/compiler/cfg/linear-scan/allocation/coalescing/coalescing.factor +++ b/basis/compiler/cfg/linear-scan/allocation/coalescing/coalescing.factor @@ -1,6 +1,6 @@ ! Copyright (C) 2009 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. -USING: accessors kernel sequences +USING: accessors kernel sequences namespaces assocs fry combinators.short-circuit compiler.cfg.linear-scan.live-intervals compiler.cfg.linear-scan.allocation.state ; @@ -20,9 +20,16 @@ IN: compiler.cfg.linear-scan.allocation.coalescing [ avoids-inactive-intervals? ] } 1&& ; +: reuse-spill-slot ( old new -- ) + [ vreg>> spill-slots get at ] dip '[ _ vreg>> spill-slots get set-at ] when* ; + +: reuse-register ( old new -- ) + reg>> >>reg drop ; + +: (coalesce) ( old new -- ) + [ add-active ] [ [ delete-active ] [ add-handled ] bi ] bi* ; + : coalesce ( live-interval -- ) dup copy-from>> active-interval - [ [ add-active ] [ [ delete-active ] [ add-handled ] bi ] bi* ] - [ reg>> >>reg drop ] - 2bi ; + [ reuse-spill-slot ] [ reuse-register ] [ (coalesce) ] 2tri ; \ No newline at end of file diff --git a/basis/compiler/cfg/linear-scan/allocation/spilling/spilling.factor b/basis/compiler/cfg/linear-scan/allocation/spilling/spilling.factor index 8c91ca7f60..b89c1f4de2 100644 --- a/basis/compiler/cfg/linear-scan/allocation/spilling/spilling.factor +++ b/basis/compiler/cfg/linear-scan/allocation/spilling/spilling.factor @@ -38,10 +38,10 @@ ERROR: bad-live-ranges interval ; } 2cleave ; : assign-spill ( live-interval -- ) - dup assign-spill-slot >>spill-to f >>split-next drop ; + dup vreg>> assign-spill-slot >>spill-to f >>split-next drop ; : assign-reload ( live-interval -- ) - dup assign-spill-slot >>reload-from drop ; + dup vreg>> assign-spill-slot >>reload-from drop ; : split-and-spill ( live-interval n -- before after ) split-for-spill 2dup [ assign-spill ] [ assign-reload ] bi* ; diff --git a/basis/compiler/cfg/linear-scan/allocation/state/state.factor b/basis/compiler/cfg/linear-scan/allocation/state/state.factor index 1e670ad6a6..3e646b40f0 100644 --- a/basis/compiler/cfg/linear-scan/allocation/state/state.factor +++ b/basis/compiler/cfg/linear-scan/allocation/state/state.factor @@ -126,18 +126,8 @@ SYMBOL: spill-counts ! Mapping from vregs to spill slots SYMBOL: spill-slots -DEFER: assign-spill-slot - -: compute-spill-slot ( live-interval -- n ) - dup copy-from>> - [ assign-spill-slot ] - [ vreg>> reg-class>> next-spill-slot ] ?if ; - -: assign-spill-slot ( live-interval -- n ) - dup vreg>> spill-slots get at [ ] [ - [ compute-spill-slot dup ] keep - vreg>> spill-slots get set-at - ] ?if ; +: assign-spill-slot ( vreg -- n ) + spill-slots get [ reg-class>> next-spill-slot ] cache ; : init-allocator ( registers -- ) registers set