]> gitweb.factorcode.org Git - factor.git/commitdiff
Fixing various bugs; alias analysis wasn't handling ##phi nodes, stack analysis incor...
authorSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Fri, 29 May 2009 06:39:14 +0000 (01:39 -0500)
committerSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Fri, 29 May 2009 06:39:14 +0000 (01:39 -0500)
13 files changed:
basis/compiler/cfg/alias-analysis/alias-analysis.factor
basis/compiler/cfg/builder/builder.factor
basis/compiler/cfg/checker/checker.factor
basis/compiler/cfg/instructions/instructions.factor
basis/compiler/cfg/optimizer/optimizer-tests.factor
basis/compiler/cfg/stack-analysis/stack-analysis.factor
basis/compiler/cfg/value-numbering/value-numbering-tests.factor
basis/compiler/codegen/codegen.factor
basis/cpu/architecture/architecture.factor
basis/cpu/ppc/ppc.factor
basis/cpu/x86/32/32.factor
basis/cpu/x86/64/64.factor
basis/cpu/x86/x86.factor

index 0a3671034d2b5aab70195cc7c625eb683c7dab52..7ea02c81e57a6fcae21bc5469bd4bac148e34444 100644 (file)
@@ -215,13 +215,7 @@ GENERIC: analyze-aliases* ( insn -- insn' )
 M: ##load-immediate analyze-aliases*
     dup [ val>> ] [ dst>> ] bi constants get set-at ;
 
-M: ##peek analyze-aliases*
-    dup dst>> set-heap-ac ;
-
-M: ##load-reference analyze-aliases*
-    dup dst>> set-heap-ac ;
-
-M: ##alien-global analyze-aliases*
+M: ##flushable analyze-aliases*
     dup dst>> set-heap-ac ;
 
 M: ##allocation analyze-aliases*
@@ -230,7 +224,7 @@ M: ##allocation analyze-aliases*
     dup dst>> set-new-ac ;
 
 M: ##read analyze-aliases*
-    dup dst>> set-heap-ac
+    call-next-method
     dup [ dst>> ] [ insn-slot# ] [ insn-object ] tri
     2dup live-slot dup [
         2nip f \ ##copy boa analyze-aliases* nip
index 1bf5bab0679e51dd8b2e4a8024703f8a3764f8be..38075c24a3aceee51f4ed155b76f638153d674ae 100755 (executable)
@@ -159,63 +159,8 @@ M: #if emit-node
     } cond iterate-next ;
 
 ! #dispatch
-: trivial-dispatch-branch? ( nodes -- ? )
-    dup length 1 = [
-        first dup #call? [
-            word>> "intrinsic" word-prop not
-        ] [ drop f ] if
-    ] [ drop f ] if ;
-
-: dispatch-branch ( nodes word -- label )
-    over trivial-dispatch-branch? [
-        drop first word>>
-    ] [
-        gensym [
-            [
-                V{ } clone node-stack set
-                ##prologue
-                begin-basic-block
-                emit-nodes
-                basic-block get [
-                    ##epilogue
-                    ##return
-                    end-basic-block
-                ] when
-            ] with-cfg-builder
-        ] keep
-    ] if ;
-
-: dispatch-branches ( node -- )
-    children>> [
-        current-word get dispatch-branch
-        ##dispatch-label
-    ] each ;
-
-: emit-dispatch ( node -- )
-    ##epilogue
-    ds-pop ^^offset>slot i 0 ##dispatch
-    dispatch-branches ;
-
-! If a dispatch is not in tail position, we compile a new word where the dispatch is in
-! tail position, then call this word.
-
-: (non-tail-dispatch) ( -- word )
-    gensym dup t "inlined-block" set-word-prop ;
-
-: <non-tail-dispatch> ( node -- word )
-    current-word get (non-tail-dispatch) [
-        [
-            begin-word
-            emit-dispatch
-        ] with-cfg-builder
-    ] keep ;
-
 M: #dispatch emit-node
-    tail-call? [
-        emit-dispatch stop-iterating
-    ] [
-       <non-tail-dispatch> f emit-call
-    ] if ;
+    ds-pop ^^offset>slot i ##dispatch emit-if iterate-next ;
 
 ! #call
 M: #call emit-node
index bc0eb745541223e04de2c93dc69e52e07412af85..65191d5ac244eeb6cc81a6e7a75eb0cae32cc8a8 100644 (file)
@@ -10,13 +10,13 @@ ERROR: last-insn-not-a-jump insn ;
 : check-last-instruction ( bb -- )
     peek dup {
         [ ##branch? ]
+        [ ##dispatch? ]
         [ ##conditional-branch? ]
         [ ##compare-imm-branch? ]
         [ ##return? ]
         [ ##callback-return? ]
         [ ##jump? ]
         [ ##call? ]
-        [ ##dispatch-label? ]
     } 1|| [ drop ] [ last-insn-not-a-jump ] if ;
 
 ERROR: bad-loop-entry ;
index 747233dbba3cfd25d55526ca12f2c530ed718182..6da9f797bd06b48d224ffc507971ea8b070dab07 100644 (file)
@@ -57,13 +57,12 @@ TUPLE: stack-frame
 spill-counts ;
 
 INSN: ##stack-frame stack-frame ;
-INSN: ##call word height ;
+INSN: ##call word { height integer } ;
 INSN: ##jump word ;
 INSN: ##return ;
 
 ! Jump tables
-INSN: ##dispatch src temp offset ;
-INSN: ##dispatch-label label ;
+INSN: ##dispatch src temp ;
 
 ! Slot access
 INSN: ##slot < ##read { obj vreg } { slot vreg } { tag integer } { temp vreg } ;
@@ -165,7 +164,7 @@ UNION: ##allocation ##allot ##box-float ##box-alien ##integer>bignum ;
 
 INSN: ##write-barrier < ##effect card# table ;
 
-INSN: ##alien-global < ##read symbol library ;
+INSN: ##alien-global < ##flushable symbol library ;
 
 ! FFI
 INSN: ##alien-invoke params ;
index b81d9f81f564d2093adb10e25fd7f69d196ac795..923fe828b5b759d85db528bc0ad2816a154522cf 100644 (file)
@@ -1,14 +1,33 @@
 USING: arrays sequences tools.test compiler.cfg.checker compiler.cfg.debugger
-compiler.cfg.def-use sets kernel kernel.private fry slots.private ;
+compiler.cfg.def-use sets kernel kernel.private fry slots.private vectors
+sequences.private math sbufs math.private slots.private strings ;
 IN: compiler.cfg.optimizer.tests
 
 ! Miscellaneous tests
 
+: more? ( x -- ? ) ;
+
+: test-case-1 ( -- ? ) f ;
+
+: test-case-2 ( -- )
+    test-case-1 [ test-case-2 ] [ ] if ; inline recursive
+
 {
     [ 1array ]
     [ 1 2 ? ]
     [ { array } declare [ ] map ]
     [ { array } declare dup 1 slot [ 1 slot ] when ]
+    [ [ dup more? ] [ dup ] produce ]
+    [ vector new over test-case-1 [ test-case-2 ] [ ] if ]
+    [ [ [ nth-unsafe ".." = 0 ] dip set-nth-unsafe ] 2curry (each-integer) ]
+    [
+        { fixnum sbuf } declare 2dup 3 slot fixnum> [
+            over 3 fixnum* over dup [ 2 slot resize-string ] dip 2 set-slot
+        ] [ ] if
+    ]
+    [ [ 2 fixnum* ] when 3 ]
+    [ [ 2 fixnum+ ] when 3 ]
+    [ [ 2 fixnum- ] when 3 ]
 } [
     [ [ ] ] dip '[ _ test-mr first check-mr ] unit-test
 ] each
index 0aa402ed66822cd29dfa679e264561e27bea6fc4..ffff728ece965eafb1c093cb32c306af78ca987a 100644 (file)
@@ -91,7 +91,8 @@ UNION: neutral-insn
     ##branch
     ##loop-entry
     ##conditional-branch
-    ##compare-imm-branch ;
+    ##compare-imm-branch
+    ##dispatch ;
 
 M: neutral-insn visit , ;
 
@@ -130,22 +131,12 @@ M: ##copy visit
     [ call-next-method ] [ record-copy ] bi ;
 
 M: ##call visit
-    [ call-next-method ] [ height>> [ adjust-d ] [ poison-state ] if* ] bi ;
-
-M: ##fixnum-mul visit
-    call-next-method -1 adjust-d ;
-
-M: ##fixnum-add visit
-    call-next-method -1 adjust-d ;
-
-M: ##fixnum-sub visit
-    call-next-method -1 adjust-d ;
+    [ call-next-method ] [ height>> adjust-d ] bi ;
 
 ! Instructions that poison the stack state
 UNION: poison-insn
     ##jump
     ##return
-    ##dispatch
     ##callback-return
     ##fixnum-mul-tail
     ##fixnum-add-tail
@@ -179,8 +170,6 @@ M: ##alien-indirect visit
 
 M: ##alien-callback visit , ;
 
-M: ##dispatch-label visit , ;
-
 ! Maps basic-blocks to states
 SYMBOLS: state-in state-out ;
 
@@ -245,7 +234,8 @@ ERROR: cannot-merge-poisoned states ;
         [
             drop
             dup [ not ] any? [
-                2drop <state>
+                [ <state> ] 2dip
+                sift merge-heights
             ] [
                 dup [ poisoned?>> ] any? [
                     cannot-merge-poisoned
index c12b5afd2ea5fca54ec8b9798cff4c7c7b54e49e..5063273bf41e503f2e26e2fdea7ecf2011eb38f1 100644 (file)
@@ -50,7 +50,7 @@ sequences compiler.cfg vectors arrays ;
 [ t ] [
     {
         T{ ##peek f V int-regs 1 D 0 }
-        T{ ##dispatch f V int-regs 1 V int-regs 2 }
+        T{ ##dispatch f V int-regs 1 V int-regs 2 }
     } dup test-value-numbering =
 ] unit-test
 
index c7b67b72b4d0bc01ffdf3850927c902ea321862b..11b4e153f6513b5b09563e54853d683d84953a07 100755 (executable)
@@ -92,10 +92,8 @@ M: ##jump generate-insn word>> [ add-call ] [ %jump ] bi ;
 
 M: ##return generate-insn drop %return ;
 
-M: ##dispatch-label generate-insn label>> %dispatch-label ;
-
 M: ##dispatch generate-insn
-    [ src>> register ] [ temp>> register ] [ offset>> ] tri %dispatch ;
+    [ src>> register ] [ temp>> register ] bi %dispatch ;
 
 : >slot< ( insn -- dst obj slot tag )
     {
index de5d1da4e01a0b94e04d54f469ad2dfe50f1145d..98d0c5326b7b72c3a7ac8b9c2fd9e662fd3dc877 100644 (file)
@@ -51,8 +51,7 @@ HOOK: %jump cpu ( word -- )
 HOOK: %jump-label cpu ( label -- )
 HOOK: %return cpu ( -- )
 
-HOOK: %dispatch cpu ( src temp offset -- )
-HOOK: %dispatch-label cpu ( word -- )
+HOOK: %dispatch cpu ( src temp -- )
 
 HOOK: %slot cpu ( dst obj slot tag temp -- )
 HOOK: %slot-imm cpu ( dst obj slot tag -- )
index 617a7c514177fc280489531c953c906b11256088..934b456075eb86b577f90c5da72c18afbc887845 100644 (file)
@@ -124,16 +124,13 @@ M: ppc %jump ( word -- )
 M: ppc %jump-label ( label -- ) B ;
 M: ppc %return ( -- ) BLR ;
 
-M:: ppc %dispatch ( src temp offset -- )
+M:: ppc %dispatch ( src temp -- )
     0 temp LOAD32
-    4 offset + cells rc-absolute-ppc-2/2 rel-here
+    4 cells rc-absolute-ppc-2/2 rel-here
     temp temp src LWZX
     temp MTCTR
     BCTR ;
 
-M: ppc %dispatch-label ( word -- )
-    B{ 0 0 0 0 } % rc-absolute-cell rel-word ;
-
 :: (%slot) ( obj slot tag temp -- reg offset )
     temp slot obj ADD
     temp tag neg ; inline
index 0a0ac4a53e727e570093db26083375cb7b217ca6..4492a3d7625d0aa20841a73e4364687a2ae31a26 100755 (executable)
@@ -26,10 +26,10 @@ M: x86.32 stack-reg ESP ;
 M: x86.32 temp-reg-1 ECX ;
 M: x86.32 temp-reg-2 EDX ;
 
-M:: x86.32 %dispatch ( src temp offset -- )
+M:: x86.32 %dispatch ( src temp -- )
     ! Load jump table base.
     src HEX: ffffffff ADD
-    offset cells rc-absolute-cell rel-here
+    0 rc-absolute-cell rel-here
     ! Go
     src HEX: 7f [+] JMP
     ! Fix up the displacement above
index b77539b7e76d17bce7968b2ad5e50725a9e4f71d..0b9b4e8ddf48d9c935d8dfff5763c3dc8e525e80 100644 (file)
@@ -22,10 +22,10 @@ M: x86.64 ds-reg R14 ;
 M: x86.64 rs-reg R15 ;
 M: x86.64 stack-reg RSP ;
 
-M:: x86.64 %dispatch ( src temp offset -- )
+M:: x86.64 %dispatch ( src temp -- )
     ! Load jump table base.
     temp HEX: ffffffff MOV
-    offset cells rc-absolute-cell rel-here
+    0 rc-absolute-cell rel-here
     ! Add jump table base
     src temp ADD
     src HEX: 7f [+] JMP
index e12cec9738a0051e65a6f75333cb41a79752fd97..8ab247f5e533f3132277715845c9ea073a44e791 100644 (file)
@@ -79,9 +79,6 @@ M: x86 %return ( -- ) 0 RET ;
 : align-code ( n -- )
     0 <repetition> % ;
 
-M: x86 %dispatch-label ( word -- )
-    0 cell, rc-absolute-cell rel-word ;
-
 :: (%slot) ( obj slot tag temp -- op )
     temp slot obj [+] LEA
     temp tag neg [+] ; inline