]> gitweb.factorcode.org Git - factor.git/commitdiff
compiler.cfg.*: more fixes to pass basic-block on the stack than in a
authorBjörn Lindqvist <bjourne@gmail.com>
Sun, 22 Nov 2015 00:06:11 +0000 (01:06 +0100)
committerBjörn Lindqvist <bjourne@gmail.com>
Sun, 22 Nov 2015 00:06:11 +0000 (01:06 +0100)
dynamic variable

basis/compiler/cfg/builder/alien/alien.factor
basis/compiler/cfg/builder/blocks/blocks-docs.factor
basis/compiler/cfg/builder/blocks/blocks-tests.factor
basis/compiler/cfg/builder/blocks/blocks.factor
basis/compiler/cfg/builder/builder-docs.factor
basis/compiler/cfg/builder/builder.factor
basis/compiler/cfg/intrinsics/fixnum/fixnum.factor
basis/compiler/cfg/intrinsics/misc/misc.factor

index 3515f01f03030a35ebfcc5fb5bb00402db6b401c..c8a9b749a0ac8383da71591b54f06b1e19dfaf71 100644 (file)
@@ -169,7 +169,7 @@ M: #alien-assembly emit-node ( node -- )
 M: #alien-callback emit-node
     dup params>> xt>> dup
     [
-        needs-frame-pointer basic-block get begin-word
+        needs-frame-pointer begin-word
         {
             [ params>> callee-parameters ##callback-inputs, ]
             [ params>> box-parameters ]
@@ -177,5 +177,5 @@ M: #alien-callback emit-node
             [ params>> emit-callback-return ]
             [ params>> callback-stack-cleanup ]
         } cleave
-        basic-block get [ end-word ] when
+        basic-block get [ end-word ] when*
     ] with-cfg-builder ;
index 301d80113c4077a3ebf3d83b903705aca302c004..9432af56702238d051eaf9e87244f9747b7aa33d 100644 (file)
@@ -45,7 +45,7 @@ HELP: call-height
 
 HELP: emit-trivial-block
 { $values { "quot" quotation } }
-{ $description "Combinator that emits a trivial block, constructed by calling the supplied quotation." }
+{ $description "Combinator that emits a new trivial block, constructed by calling the supplied quotation. The quotation should not end the current block -- only add instructions to it." }
 { $examples { $unchecked-example $[ ex-emit-trivial-block ] } } ;
 
 HELP: end-branch
index 171706473820b69dc293dbd26f438b628511f20c..814dde12d8d371eebaffe552d1915479e8b9a0ae 100644 (file)
@@ -1,6 +1,7 @@
 USING: accessors compiler.cfg compiler.cfg.builder.blocks
-compiler.cfg.stacks.local compiler.cfg.utilities compiler.test kernel
-namespaces sequences tools.test ;
+compiler.cfg.instructions compiler.cfg.stacks.local
+compiler.cfg.utilities compiler.test kernel make namespaces sequences
+tools.test ;
 IN: compiler.cfg.builder.blocks.tests
 
 ! (begin-basic-block)
@@ -14,6 +15,14 @@ IN: compiler.cfg.builder.blocks.tests
     height-state get <basic-block> begin-branch height-state get eq?
 ] cfg-unit-test
 
+! emit-trivial-block
+{
+    V{ T{ ##no-tco } T{ ##branch } }
+} [
+    [ [ drop ##no-tco, ] emit-trivial-block ] V{ } make drop
+    basic-block get successors>> first instructions>>
+] cfg-unit-test
+
 ! make-kill-block
 { t } [
     <basic-block> [ make-kill-block ] keep kill-block?>>
index 75a1e29a369b8a2a717cd64f8b68aa14efe61ee5..39682f80a14f0582d24b23ec92a795a66f153240 100644 (file)
@@ -23,8 +23,8 @@ IN: compiler.cfg.builder.blocks
 
 : emit-trivial-block ( quot -- )
     ##branch, basic-block get begin-basic-block
-    call
-    ##branch, basic-block get begin-basic-block ; inline
+    basic-block get [ swap call ] keep
+    ##branch, begin-basic-block ; inline
 
 : make-kill-block ( block -- )
     t swap kill-block?<< ;
@@ -32,13 +32,12 @@ IN: compiler.cfg.builder.blocks
 : call-height ( #call -- n )
     [ out-d>> length ] [ in-d>> length ] bi - ;
 
-: emit-call-block ( word height -- )
-    adjust-d ##call, basic-block get make-kill-block ;
+: emit-call-block ( word height block -- )
+    make-kill-block adjust-d ##call, ;
 
 : emit-primitive ( node -- )
-    [
-        [ word>> ] [ call-height ] bi emit-call-block
-    ] emit-trivial-block ;
+    [ word>> ] [ call-height ] bi
+    [ emit-call-block ] emit-trivial-block ;
 
 : begin-branch ( block -- )
     height-state [ clone-height-state ] change (begin-basic-block) ;
@@ -57,9 +56,9 @@ IN: compiler.cfg.builder.blocks
         basic-block get end-branch
     ] with-scope ; inline
 
-: emit-conditional ( branches -- )
+: emit-conditional ( branches block -- )
     ! branches is a sequence of pairs as above
-    basic-block get end-basic-block
+    end-basic-block
     sift [
         dup first second height-state set
         basic-block get begin-basic-block
index 3ebb30119793d0effe59d09a68efb3311833b155..2f9b0a22b85e857dae4091b81726647ef401c036 100644 (file)
@@ -1,6 +1,6 @@
 USING: assocs compiler.cfg compiler.cfg.builder.blocks
-compiler.cfg.stacks.local compiler.tree help.markup help.syntax
-kernel literals math multiline sequences vectors words ;
+compiler.cfg.stacks.local compiler.tree help.markup help.syntax kernel
+literals math multiline quotations sequences vectors words ;
 IN: compiler.cfg.builder
 
 <<
@@ -44,6 +44,10 @@ H{
 ;
 >>
 
+HELP: build-cfg
+{ $values { "nodes" sequence } { "word" word } { "procedures" sequence } }
+{ $description "Builds one or more cfgs from the given word." } ;
+
 HELP: procedures
 { $var-description "A " { $link vector } " used as temporary storage during cfg construction for all procedures being built." } ;
 
@@ -84,9 +88,9 @@ HELP: trivial-branch?
   }
 } ;
 
-HELP: build-cfg
-{ $values { "nodes" sequence } { "word" word } { "procedures" sequence } }
-{ $description "Builds one or more cfgs from the given word." } ;
+HELP: with-cfg-builder
+{ $values { "nodes" sequence } { "word" word } { "label" word } { "quot" quotation } }
+{ $description "Combinator used to begin and end stack analysis so that the given quotation can build the cfg. The quotation is passed the initial basic block on the stack." } ;
 
 ARTICLE: "compiler.cfg.builder"
 "Final stage of compilation generates machine code from dataflow IR"
index 150b9baea5404b9116a61366c254824a3a6e60ed..ed6732064deae3098d5b6154334eb47ac577f588 100644 (file)
@@ -23,14 +23,14 @@ SYMBOL: loops
     '[
         begin-stack-analysis
         begin-procedure
-        @
+        basic-block get @
         end-stack-analysis
     ] with-scope ; inline
 
 : with-dummy-cfg-builder ( node quot -- )
     [
         [ V{ } clone procedures ] 2dip
-        '[ _ t t [ _ call( node -- ) ] with-cfg-builder ] with-variable
+        '[ _ t t [ drop _ call( node -- ) ] with-cfg-builder ] with-variable
     ] { } make drop ;
 
 GENERIC: emit-node ( node -- )
@@ -44,11 +44,7 @@ GENERIC: emit-node ( node -- )
     begin-basic-block ;
 
 : (build-cfg) ( nodes word label -- )
-    [
-
-        basic-block get begin-word
-        emit-nodes
-    ] with-cfg-builder ;
+    [ begin-word emit-nodes ] with-cfg-builder ;
 
 : build-cfg ( nodes word -- procedures )
     V{ } clone [
@@ -93,7 +89,7 @@ M: #recursive emit-node
     [ emit-nodes ] with-branch ;
 
 : emit-if ( node -- )
-    children>> [ emit-branch ] map emit-conditional ;
+    children>> [ emit-branch ] map basic-block get emit-conditional ;
 
 : trivial-branch? ( nodes -- value ? )
     dup length 1 = [
@@ -136,11 +132,12 @@ M: #dispatch emit-node
     ! though.
     ds-pop ^^offset>slot next-vreg ##dispatch, emit-if ;
 
-M: #call emit-node
+M: #call emit-node ( node -- )
     dup word>> dup "intrinsic" word-prop
     [ emit-intrinsic ] [ swap call-height emit-call ] if ;
 
-M: #call-recursive emit-node [ label>> id>> ] [ call-height ] bi emit-call ;
+M: #call-recursive emit-node ( node -- )
+    [ label>> id>> ] [ call-height ] bi emit-call ;
 
 M: #push emit-node
     literal>> ^^load-literal ds-push ;
@@ -173,18 +170,18 @@ M: #shuffle emit-node ( node -- )
     [ out-vregs/stack ] keep store-height-changes [ first2 store-vregs ] each ;
 
 ! #return
-: end-word ( -- )
-    ##branch,
-    basic-block get begin-basic-block
+: end-word ( block -- )
+    ##branch, begin-basic-block
     basic-block get make-kill-block
     ##safepoint,
     ##epilogue,
     ##return, ;
 
-M: #return emit-node drop end-word ;
+M: #return emit-node ( node -- )
+    drop basic-block get end-word ;
 
-M: #return-recursive emit-node
-    label>> id>> loops get key? [ end-word ] unless ;
+M: #return-recursive emit-node ( node -- )
+    label>> id>> loops get key? [ basic-block get end-word ] unless ;
 
 ! #terminate
 M: #terminate emit-node ( node -- )
index 0fcfc844714c742e3206945edf9167c41ca502d2..eff5749b4fc49fa9d5f1cf994ea0d2e41f8ac165 100644 (file)
@@ -1,10 +1,11 @@
 ! Copyright (C) 2008, 2010 Slava Pestov, Doug Coleman.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors arrays combinators compiler.cfg.builder.blocks
-compiler.cfg.comparisons compiler.cfg.hats
-compiler.cfg.instructions compiler.cfg.stacks.local compiler.cfg.registers
-compiler.cfg.stacks compiler.tree.propagation.info cpu.architecture fry kernel
-layouts math math.intervals namespaces sequences ;
+USING: accessors arrays combinators compiler.cfg
+compiler.cfg.builder.blocks compiler.cfg.comparisons compiler.cfg.hats
+compiler.cfg.instructions compiler.cfg.registers compiler.cfg.stacks
+compiler.cfg.stacks.local compiler.tree.propagation.info
+cpu.architecture fry kernel layouts math math.intervals namespaces
+sequences ;
 IN: compiler.cfg.intrinsics.fixnum
 
 : emit-both-fixnums? ( -- )
@@ -28,7 +29,7 @@ IN: compiler.cfg.intrinsics.fixnum
     ds-peek 0 cc> ##compare-integer-imm-branch,
     [ emit-fixnum-left-shift ] with-branch
     [ emit-fixnum-right-shift ] with-branch
-    2array emit-conditional ;
+    2array basic-block get emit-conditional ;
 
 : emit-fixnum-shift-fast ( node -- )
     node-input-infos second interval>> {
@@ -45,7 +46,7 @@ IN: compiler.cfg.intrinsics.fixnum
 
 : emit-overflow-case ( word -- final-bb )
     [
-        -1 emit-call-block
+        -1 basic-block get emit-call-block
     ] with-branch ;
 
 : emit-fixnum-overflow-op ( quot word -- )
@@ -53,7 +54,7 @@ IN: compiler.cfg.intrinsics.fixnum
     ! of loc>vreg sync
     [ [ (2inputs) [ any-rep ^^copy ] bi@ cc/o ] dip call ] dip
     [ emit-no-overflow-case ] [ emit-overflow-case ] bi* 2array
-    emit-conditional ; inline
+    basic-block get emit-conditional ; inline
 
 : fixnum+overflow ( x y -- z ) [ >bignum ] bi@ + ;
 
index 293733e8096cff9f27bf94fa4e0ce1b17ad1ac10..92319327ea32a59d0b8e9cd06a327b34d25c1fd5 100644 (file)
@@ -51,4 +51,4 @@ IN: compiler.cfg.intrinsics.misc
     if ;
 
 : emit-cleanup-allot ( -- )
-    [ ##no-tco, ] emit-trivial-block ;
+    [ drop ##no-tco, ] emit-trivial-block ;