From 91118ae5df40c748b372a858358a5a5ebfbe1381 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Lindqvist?= Date: Sun, 14 Jun 2015 06:13:34 +0200 Subject: [PATCH] compiler.cfg.linear-scan.allocation.state: fix #1345 by adding vreg to the heap key By having { start end vreg } as the key in the min-heap ordering is guaranteed even if two intervals share the same start and end. --- .../allocation/state/state-tests.factor | 16 ++++++++-------- .../linear-scan/allocation/state/state.factor | 19 +++++++++---------- 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/basis/compiler/cfg/linear-scan/allocation/state/state-tests.factor b/basis/compiler/cfg/linear-scan/allocation/state/state-tests.factor index a072b71d45..4eb76c0c6a 100644 --- a/basis/compiler/cfg/linear-scan/allocation/state/state-tests.factor +++ b/basis/compiler/cfg/linear-scan/allocation/state/state-tests.factor @@ -137,27 +137,27 @@ cpu x86.64? [ cfg get ] unit-test -{ { 33 1/0.0 } } [ - T{ sync-point { n 33 } } sync-point-key +{ { 33 1/0.0 1/0.0 } } [ + T{ sync-point { n 33 } } interval/sync-point-key ] unit-test { { - { { 5 1/0. } T{ sync-point { n 5 } } } + { { 5 1/0. 1/0. } T{ sync-point { n 5 } } } { - { 20 28 } + { 20 28 f } T{ live-interval-state { start 20 } { end 28 } } } { - { 20 30 } + { 20 30 f } T{ live-interval-state { start 20 } { end 30 } } } { - { 33 999 } + { 33 999 f } T{ live-interval-state { start 33 } { end 999 } } } - { { 33 1/0. } T{ sync-point { n 33 } } } - { { 100 1/0. } T{ sync-point { n 100 } } } + { { 33 1/0. 1/0. } T{ sync-point { n 33 } } } + { { 100 1/0. 1/0. } T{ sync-point { n 100 } } } } } [ { diff --git a/basis/compiler/cfg/linear-scan/allocation/state/state.factor b/basis/compiler/cfg/linear-scan/allocation/state/state.factor index bd64e94854..c267f31709 100644 --- a/basis/compiler/cfg/linear-scan/allocation/state/state.factor +++ b/basis/compiler/cfg/linear-scan/allocation/state/state.factor @@ -18,18 +18,19 @@ SYMBOL: progress SYMBOL: unhandled-min-heap -: live-interval-key ( live-interval -- key ) - [ start>> ] [ end>> ] bi 2array ; +GENERIC: interval/sync-point-key ( interval/sync-point -- key ) -: sync-point-key ( sync-point -- key ) - n>> 1/0. 2array ; +M: live-interval-state interval/sync-point-key + [ start>> ] [ end>> ] [ vreg>> ] tri 3array ; + +M: sync-point interval/sync-point-key + n>> 1/0. 1/0. 3array ; : zip-keyed ( seq quot: ( elt -- key ) -- alist ) [ keep ] curry { } map>assoc ; inline : >unhandled-min-heap ( live-intervals sync-points -- min-heap ) - [ [ live-interval-key ] zip-keyed ] - [ [ sync-point-key ] zip-keyed ] bi* append >min-heap ; + append [ interval/sync-point-key ] zip-keyed >min-heap ; SYMBOL: registers @@ -108,10 +109,8 @@ ERROR: register-already-used live-interval ; } process-intervals ; : add-unhandled ( live-interval -- ) - [ check-unhandled ] - [ - dup live-interval-key unhandled-min-heap get heap-push - ] bi ; + dup check-unhandled + dup interval/sync-point-key unhandled-min-heap get heap-push ; : reg-class-assoc ( quot -- assoc ) [ reg-classes ] dip { } map>assoc ; inline