]> gitweb.factorcode.org Git - factor.git/commitdiff
compiler.cfg.linear-scan.assignment: utility word heap-pop-while which lets you expre...
authorBjörn Lindqvist <bjourne@gmail.com>
Sun, 14 Dec 2014 04:45:40 +0000 (05:45 +0100)
committerBjörn Lindqvist <bjourne@gmail.com>
Mon, 15 Dec 2014 19:40:49 +0000 (20:40 +0100)
basis/compiler/cfg/linear-scan/assignment/assignment-tests.factor
basis/compiler/cfg/linear-scan/assignment/assignment.factor

index 22d2775ceea73d1b6867e27adb6221ee4790da9b..be4792e371a849bc9fc9cb8e60972478dde15561 100644 (file)
@@ -1,6 +1,7 @@
-USING: compiler.cfg.instructions compiler.cfg.linear-scan.assignment
-compiler.cfg.linear-scan.live-intervals cpu.x86.assembler.operands make
-tools.test ;
+USING: accessors arrays compiler.cfg.instructions
+compiler.cfg.linear-scan.assignment compiler.cfg.linear-scan.live-intervals
+compiler.cfg.utilities cpu.architecture cpu.x86.assembler.operands grouping
+heaps kernel make namespaces random sequences sorting tools.test ;
 IN: compiler.cfg.linear-scan.assignment.tests
 
 { { T{ ##spill { src RAX } } } } [
@@ -8,3 +9,28 @@ IN: compiler.cfg.linear-scan.assignment.tests
         T{ live-interval-state { vreg 1234 } { reg RAX } } insert-spill
     ] { } make
 ] unit-test
+
+{ } [
+    { } init-assignment
+    V{ T{ ##inc-d { n 3 } { insn# 7 } } } 0 insns>block
+    assign-registers-in-block
+] unit-test
+
+{ V{ T{ ##spill { src RAX } { rep int-rep } } } } [
+    [
+        1234 int-regs <live-interval>
+        RAX >>reg int-rep >>spill-rep
+        insert-spill
+    ] V{ } make
+] unit-test
+
+{ { 3 56 } } [
+    { { 3 7 } { -1 56 } { -1 3 } } >min-heap [ -1 = ] heap-pop-while
+    natural-sort
+] unit-test
+
+{ 3 } [
+    { 50 90 95 120 } [ 25 int-regs <live-interval> 2array ] map >min-heap
+    pending-interval-heap set 90 expire-old-intervals
+    pending-interval-heap get heap-size
+] unit-test
index 151cbb21b2d77792b649667a1c7d832c8c812e12..54f3600052c1bc39b8922a1c24fb6c3a4d453b13 100644 (file)
@@ -77,6 +77,10 @@ SYMBOL: machine-live-outs
     H{ } clone machine-edge-live-ins set
     H{ } clone machine-live-outs set ;
 
+: heap-pop-while ( heap quot: ( key -- ? ) -- values )
+    '[ dup heap-empty? [ f f ] [ dup heap-peek @ ] if ]
+    [ over heap-pop* ] produce 2nip ; inline
+
 : insert-spill ( live-interval -- )
     [ reg>> ] [ spill-rep>> ] [ spill-to>> ] tri ##spill, ;
 
@@ -86,16 +90,9 @@ SYMBOL: machine-live-outs
 : expire-interval ( live-interval -- )
     [ remove-pending ] [ handle-spill ] bi ;
 
-: (expire-old-intervals) ( n heap -- )
-    dup heap-empty? [ 2drop ] [
-        2dup heap-peek nip <= [ 2drop ] [
-            dup heap-pop drop expire-interval
-            (expire-old-intervals)
-        ] if
-    ] if ;
-
 : expire-old-intervals ( n -- )
-    pending-interval-heap get (expire-old-intervals) ;
+    pending-interval-heap get swap '[ _ < ] heap-pop-while
+    [ expire-interval ] each ;
 
 : insert-reload ( live-interval -- )
     [ reg>> ] [ reload-rep>> ] [ reload-from>> ] tri ##reload, ;
@@ -106,16 +103,9 @@ SYMBOL: machine-live-outs
 : activate-interval ( live-interval -- )
     [ add-pending ] [ handle-reload ] bi ;
 
-: (activate-new-intervals) ( n heap -- )
-    dup heap-empty? [ 2drop ] [
-        2dup heap-peek nip = [
-            dup heap-pop drop activate-interval
-            (activate-new-intervals)
-        ] [ 2drop ] if
-    ] if ;
-
 : activate-new-intervals ( n -- )
-    unhandled-intervals get (activate-new-intervals) ;
+    unhandled-intervals get swap '[ _ = ] heap-pop-while
+    [ activate-interval ] each ;
 
 : prepare-insn ( n -- )
     [ expire-old-intervals ] [ activate-new-intervals ] bi ;