compiler.cfg.*: more refactoring to remove basic-block get:s
Now almost all words pass around the current basic block on the stack. Left is updating all intrinsics.db4
parent
f9c6d7cc43
commit
482998974b
|
@ -59,7 +59,11 @@ HELP: emit-conditional
|
||||||
{ $description "Emits a sequence of conditional branches to the current " { $link cfg } ". Each branch is a pair where the first item is the entry basic block and the second the branches " { $link height-state } ". 'block' is the block in which the control flow is branched and \"block'\" the block in which it converges again." } ;
|
{ $description "Emits a sequence of conditional branches to the current " { $link cfg } ". Each branch is a pair where the first item is the entry basic block and the second the branches " { $link height-state } ". 'block' is the block in which the control flow is branched and \"block'\" the block in which it converges again." } ;
|
||||||
|
|
||||||
HELP: emit-trivial-block
|
HELP: emit-trivial-block
|
||||||
{ $values { "quot" quotation } }
|
{ $values
|
||||||
|
{ "block" basic-block }
|
||||||
|
{ "quot" quotation }
|
||||||
|
{ "block'" basic-block }
|
||||||
|
}
|
||||||
{ $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." }
|
{ $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 ] } } ;
|
{ $examples { $unchecked-example $[ ex-emit-trivial-block ] } } ;
|
||||||
|
|
||||||
|
@ -76,7 +80,11 @@ HELP: set-basic-block
|
||||||
{ $description "Sets the given blocks as the current one by storing it in the basic-block dynamic variable. If it has any " { $slot "instructions" } " the current " { $link building } " is set to those." } ;
|
{ $description "Sets the given blocks as the current one by storing it in the basic-block dynamic variable. If it has any " { $slot "instructions" } " the current " { $link building } " is set to those." } ;
|
||||||
|
|
||||||
HELP: with-branch
|
HELP: with-branch
|
||||||
{ $values { "quot" quotation } { "pair/f" { $maybe "pair" } } }
|
{ $values
|
||||||
|
{ "block" basic-block }
|
||||||
|
{ "quot" quotation }
|
||||||
|
{ "pair/f" { $maybe "pair" } }
|
||||||
|
}
|
||||||
{ $description "The pair is either " { $link f } " or a two-tuple containing a " { $link basic-block } " and a " { $link height-state } " two-tuple." } ;
|
{ $description "The pair is either " { $link f } " or a two-tuple containing a " { $link basic-block } " and a " { $link height-state } " two-tuple." } ;
|
||||||
|
|
||||||
ARTICLE: "compiler.cfg.builder.blocks"
|
ARTICLE: "compiler.cfg.builder.blocks"
|
||||||
|
|
|
@ -23,8 +23,9 @@ IN: compiler.cfg.builder.blocks.tests
|
||||||
{
|
{
|
||||||
V{ T{ ##no-tco } T{ ##branch } }
|
V{ T{ ##no-tco } T{ ##branch } }
|
||||||
} [
|
} [
|
||||||
[ [ drop ##no-tco, ] emit-trivial-block ] V{ } make drop
|
<basic-block> dup set-basic-block
|
||||||
basic-block get successors>> first instructions>>
|
[ drop ##no-tco, ] emit-trivial-block
|
||||||
|
predecessors>> first instructions>>
|
||||||
] cfg-unit-test
|
] cfg-unit-test
|
||||||
|
|
||||||
! end-basic-block
|
! end-basic-block
|
||||||
|
|
|
@ -21,10 +21,10 @@ IN: compiler.cfg.builder.blocks
|
||||||
: begin-basic-block ( block -- block' )
|
: begin-basic-block ( block -- block' )
|
||||||
dup [ end-local-analysis ] when* (begin-basic-block) ;
|
dup [ end-local-analysis ] when* (begin-basic-block) ;
|
||||||
|
|
||||||
: emit-trivial-block ( quot: ( ..a block -- ..b ) -- )
|
: emit-trivial-block ( block quot: ( ..a block' -- ..b ) -- block' )
|
||||||
##branch, basic-block get begin-basic-block
|
##branch, swap begin-basic-block
|
||||||
[ swap call ] keep
|
[ swap call ] keep
|
||||||
##branch, begin-basic-block drop ; inline
|
##branch, begin-basic-block ; inline
|
||||||
|
|
||||||
: make-kill-block ( block -- )
|
: make-kill-block ( block -- )
|
||||||
t swap kill-block?<< ;
|
t swap kill-block?<< ;
|
||||||
|
@ -35,8 +35,8 @@ IN: compiler.cfg.builder.blocks
|
||||||
: emit-call-block ( word height block -- )
|
: emit-call-block ( word height block -- )
|
||||||
make-kill-block adjust-d ##call, ;
|
make-kill-block adjust-d ##call, ;
|
||||||
|
|
||||||
: emit-primitive ( node -- )
|
: emit-primitive ( block node -- block' )
|
||||||
[ word>> ] [ call-height ] bi
|
[ word>> ] [ call-height ] bi rot
|
||||||
[ emit-call-block ] emit-trivial-block ;
|
[ emit-call-block ] emit-trivial-block ;
|
||||||
|
|
||||||
: begin-branch ( block -- block' )
|
: begin-branch ( block -- block' )
|
||||||
|
@ -49,12 +49,8 @@ IN: compiler.cfg.builder.blocks
|
||||||
height-state get clone-height-state 2array
|
height-state get clone-height-state 2array
|
||||||
] when* ;
|
] when* ;
|
||||||
|
|
||||||
: with-branch ( quot -- pair/f )
|
: with-branch ( block quot: ( ..a block -- ..b block' ) -- pair/f )
|
||||||
[
|
[ [ begin-branch ] dip call end-branch ] with-scope ; inline
|
||||||
basic-block get begin-branch drop
|
|
||||||
call
|
|
||||||
basic-block get end-branch
|
|
||||||
] with-scope ; inline
|
|
||||||
|
|
||||||
: emit-conditional ( block branches -- block' )
|
: emit-conditional ( block branches -- block' )
|
||||||
swap end-basic-block
|
swap end-basic-block
|
||||||
|
|
|
@ -55,9 +55,7 @@ GENERIC: emit-node ( block node -- block' )
|
||||||
[ swap connect-bbs ] [ end-basic-block ] bi ;
|
[ swap connect-bbs ] [ end-basic-block ] bi ;
|
||||||
|
|
||||||
: emit-trivial-call ( block word height -- block' )
|
: emit-trivial-call ( block word height -- block' )
|
||||||
##branch, rot begin-basic-block
|
rot [ emit-call-block ] emit-trivial-block ;
|
||||||
[ emit-call-block ] keep
|
|
||||||
##branch, begin-basic-block ;
|
|
||||||
|
|
||||||
: emit-call ( block word height -- block' )
|
: emit-call ( block word height -- block' )
|
||||||
over loops get at [
|
over loops get at [
|
||||||
|
@ -81,7 +79,7 @@ M: #recursive emit-node ( block node -- block' )
|
||||||
|
|
||||||
! #if
|
! #if
|
||||||
: emit-branch ( nodes block -- pair/f )
|
: emit-branch ( nodes block -- pair/f )
|
||||||
[ begin-branch swap emit-nodes end-branch ] with-scope ;
|
[ swap emit-nodes ] with-branch ;
|
||||||
|
|
||||||
: emit-if ( block node -- block' )
|
: emit-if ( block node -- block' )
|
||||||
children>> over '[ _ emit-branch ] map emit-conditional ;
|
children>> over '[ _ emit-branch ] map emit-conditional ;
|
||||||
|
|
|
@ -1,11 +1,10 @@
|
||||||
! Copyright (C) 2008, 2010 Slava Pestov.
|
! Copyright (C) 2008, 2010 Slava Pestov.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: accessors kernel sequences alien math classes.algebra fry
|
USING: accessors alien classes.algebra combinators
|
||||||
locals combinators combinators.short-circuit cpu.architecture
|
combinators.short-circuit compiler.cfg compiler.cfg.builder.blocks
|
||||||
compiler.tree.propagation.info compiler.cfg.hats
|
compiler.cfg.hats compiler.cfg.instructions compiler.cfg.stacks
|
||||||
compiler.cfg.registers compiler.cfg.stacks
|
compiler.tree.propagation.info cpu.architecture fry kernel locals math
|
||||||
compiler.cfg.instructions compiler.cfg.utilities
|
namespaces sequences ;
|
||||||
compiler.cfg.builder.blocks ;
|
|
||||||
IN: compiler.cfg.intrinsics.alien
|
IN: compiler.cfg.intrinsics.alien
|
||||||
|
|
||||||
: emit-<displaced-alien>? ( node -- ? )
|
: emit-<displaced-alien>? ( node -- ? )
|
||||||
|
@ -20,13 +19,13 @@ IN: compiler.cfg.intrinsics.alien
|
||||||
_ node-input-infos second class>>
|
_ node-input-infos second class>>
|
||||||
^^box-displaced-alien
|
^^box-displaced-alien
|
||||||
] binary-op
|
] binary-op
|
||||||
] [ emit-primitive ] if ;
|
] [ basic-block get swap emit-primitive drop ] if ;
|
||||||
|
|
||||||
:: inline-accessor ( node quot test -- )
|
:: inline-accessor ( node quot test -- )
|
||||||
node node-input-infos :> infos
|
node node-input-infos :> infos
|
||||||
infos test call
|
infos test call
|
||||||
[ infos quot call ]
|
[ infos quot call ]
|
||||||
[ node emit-primitive ] if ; inline
|
[ node basic-block get swap emit-primitive drop ] if ; inline
|
||||||
|
|
||||||
: inline-load-memory? ( infos -- ? )
|
: inline-load-memory? ( infos -- ? )
|
||||||
[ first class>> c-ptr class<= ]
|
[ first class>> c-ptr class<= ]
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
! Copyright (C) 2008, 2010 Slava Pestov.
|
! Copyright (C) 2008, 2010 Slava Pestov.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: accessors arrays byte-arrays compiler.cfg.builder.blocks
|
USING: accessors arrays byte-arrays compiler.cfg
|
||||||
compiler.cfg.hats compiler.cfg.instructions compiler.cfg.registers
|
compiler.cfg.builder.blocks compiler.cfg.hats
|
||||||
compiler.cfg.stacks compiler.constants compiler.tree.propagation.info
|
compiler.cfg.instructions compiler.cfg.registers compiler.cfg.stacks
|
||||||
cpu.architecture fry kernel layouts locals math math.order
|
compiler.constants compiler.tree.propagation.info cpu.architecture fry
|
||||||
sequences ;
|
kernel layouts locals math math.order namespaces sequences ;
|
||||||
IN: compiler.cfg.intrinsics.allot
|
IN: compiler.cfg.intrinsics.allot
|
||||||
|
|
||||||
: ##set-slots, ( regs obj class -- )
|
: ##set-slots, ( regs obj class -- )
|
||||||
|
@ -28,7 +28,7 @@ IN: compiler.cfg.intrinsics.allot
|
||||||
ds-drop
|
ds-drop
|
||||||
[ tuple-slot-regs ] [ second ^^allot-tuple ] bi
|
[ tuple-slot-regs ] [ second ^^allot-tuple ] bi
|
||||||
[ tuple ##set-slots, ] [ ds-push drop ] 2bi
|
[ tuple ##set-slots, ] [ ds-push drop ] 2bi
|
||||||
] [ drop emit-primitive ] if ;
|
] [ drop basic-block get swap emit-primitive drop ] if ;
|
||||||
|
|
||||||
: store-length ( len reg class -- )
|
: store-length ( len reg class -- )
|
||||||
[ [ ^^load-literal ] dip 1 ] dip type-number ##set-slot-imm, ;
|
[ [ ^^load-literal ] dip 1 ] dip type-number ##set-slot-imm, ;
|
||||||
|
@ -51,7 +51,7 @@ IN: compiler.cfg.intrinsics.allot
|
||||||
len reg array store-length
|
len reg array store-length
|
||||||
len reg elt array store-initial-element
|
len reg elt array store-initial-element
|
||||||
reg ds-push
|
reg ds-push
|
||||||
] [ node emit-primitive ] if ;
|
] [ node basic-block get swap emit-primitive drop ] if ;
|
||||||
|
|
||||||
: expand-(byte-array)? ( obj -- ? )
|
: expand-(byte-array)? ( obj -- ? )
|
||||||
dup integer? [ 0 1024 between? ] [ drop f ] if ;
|
dup integer? [ 0 1024 between? ] [ drop f ] if ;
|
||||||
|
@ -69,7 +69,7 @@ IN: compiler.cfg.intrinsics.allot
|
||||||
|
|
||||||
: emit-(byte-array) ( node -- )
|
: emit-(byte-array) ( node -- )
|
||||||
dup node-input-infos first literal>> dup expand-(byte-array)?
|
dup node-input-infos first literal>> dup expand-(byte-array)?
|
||||||
[ nip emit-allot-byte-array drop ] [ drop emit-primitive ] if ;
|
[ nip emit-allot-byte-array drop ] [ drop basic-block get swap emit-primitive drop ] if ;
|
||||||
|
|
||||||
:: zero-byte-array ( len reg -- )
|
:: zero-byte-array ( len reg -- )
|
||||||
0 ^^load-literal :> elt
|
0 ^^load-literal :> elt
|
||||||
|
@ -83,4 +83,4 @@ IN: compiler.cfg.intrinsics.allot
|
||||||
:> len
|
:> len
|
||||||
len emit-allot-byte-array :> reg
|
len emit-allot-byte-array :> reg
|
||||||
len reg zero-byte-array
|
len reg zero-byte-array
|
||||||
] [ drop node emit-primitive ] if ;
|
] [ drop node basic-block get swap emit-primitive drop ] if ;
|
||||||
|
|
|
@ -27,8 +27,8 @@ IN: compiler.cfg.intrinsics.fixnum
|
||||||
|
|
||||||
: emit-fixnum-shift-general ( -- )
|
: emit-fixnum-shift-general ( -- )
|
||||||
ds-peek 0 cc> ##compare-integer-imm-branch,
|
ds-peek 0 cc> ##compare-integer-imm-branch,
|
||||||
[ emit-fixnum-left-shift ] with-branch
|
basic-block get [ emit-fixnum-left-shift ] with-branch
|
||||||
[ emit-fixnum-right-shift ] with-branch
|
basic-block get [ emit-fixnum-right-shift ] with-branch
|
||||||
2array basic-block get swap emit-conditional drop ;
|
2array basic-block get swap emit-conditional drop ;
|
||||||
|
|
||||||
: emit-fixnum-shift-fast ( node -- )
|
: emit-fixnum-shift-fast ( node -- )
|
||||||
|
@ -42,11 +42,13 @@ IN: compiler.cfg.intrinsics.fixnum
|
||||||
'[ _ ^^compare-integer ] binary-op ;
|
'[ _ ^^compare-integer ] binary-op ;
|
||||||
|
|
||||||
: emit-no-overflow-case ( dst -- final-bb )
|
: emit-no-overflow-case ( dst -- final-bb )
|
||||||
[ D: -2 inc-stack ds-push ] with-branch ;
|
basic-block get [
|
||||||
|
swap D: -2 inc-stack ds-push
|
||||||
|
] with-branch ;
|
||||||
|
|
||||||
: emit-overflow-case ( word -- final-bb )
|
: emit-overflow-case ( word -- final-bb )
|
||||||
[
|
basic-block get [
|
||||||
-1 basic-block get emit-call-block
|
swap -1 basic-block get emit-call-block
|
||||||
] with-branch ;
|
] with-branch ;
|
||||||
|
|
||||||
: emit-fixnum-overflow-op ( quot word -- )
|
: emit-fixnum-overflow-op ( quot word -- )
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
! Copyright (C) 2008, 2010 Slava Pestov.
|
! Copyright (C) 2008, 2010 Slava Pestov.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: accessors classes.algebra classes.struct
|
USING: accessors classes.algebra classes.struct compiler.cfg
|
||||||
compiler.cfg.builder.blocks compiler.cfg.comparisons compiler.cfg.hats
|
compiler.cfg.builder.blocks compiler.cfg.comparisons compiler.cfg.hats
|
||||||
compiler.cfg.instructions compiler.cfg.stacks compiler.constants
|
compiler.cfg.instructions compiler.cfg.stacks compiler.constants
|
||||||
compiler.tree.propagation.info cpu.architecture kernel layouts math
|
compiler.tree.propagation.info cpu.architecture kernel layouts math
|
||||||
|
@ -19,13 +19,13 @@ IN: compiler.cfg.intrinsics.misc
|
||||||
ds-drop
|
ds-drop
|
||||||
vm-special-object-offset ^^vm-field
|
vm-special-object-offset ^^vm-field
|
||||||
ds-push
|
ds-push
|
||||||
] [ emit-primitive ] ?if ;
|
] [ basic-block get swap emit-primitive drop ] ?if ;
|
||||||
|
|
||||||
: emit-set-special-object ( node -- )
|
: emit-set-special-object ( node -- )
|
||||||
dup node-input-infos second literal>> [
|
dup node-input-infos second literal>> [
|
||||||
ds-drop
|
ds-drop
|
||||||
[ ds-pop ] dip vm-special-object-offset ##set-vm-field,
|
[ ds-pop ] dip vm-special-object-offset ##set-vm-field,
|
||||||
] [ emit-primitive ] ?if ;
|
] [ basic-block get swap emit-primitive drop ] ?if ;
|
||||||
|
|
||||||
: context-object-offset ( n -- n )
|
: context-object-offset ( n -- n )
|
||||||
cells "context-objects" context offset-of + ;
|
cells "context-objects" context offset-of + ;
|
||||||
|
@ -34,7 +34,7 @@ IN: compiler.cfg.intrinsics.misc
|
||||||
dup node-input-infos first literal>> [
|
dup node-input-infos first literal>> [
|
||||||
"ctx" vm offset-of ^^vm-field
|
"ctx" vm offset-of ^^vm-field
|
||||||
ds-drop swap context-object-offset cell /i 0 ^^slot-imm ds-push
|
ds-drop swap context-object-offset cell /i 0 ^^slot-imm ds-push
|
||||||
] [ emit-primitive ] ?if ;
|
] [ basic-block get swap emit-primitive drop ] ?if ;
|
||||||
|
|
||||||
: emit-identity-hashcode ( -- )
|
: emit-identity-hashcode ( -- )
|
||||||
[
|
[
|
||||||
|
@ -47,8 +47,8 @@ IN: compiler.cfg.intrinsics.misc
|
||||||
: emit-local-allot ( node -- )
|
: emit-local-allot ( node -- )
|
||||||
dup node-input-infos first2 [ literal>> ] bi@ 2dup [ integer? ] both?
|
dup node-input-infos first2 [ literal>> ] bi@ 2dup [ integer? ] both?
|
||||||
[ ds-drop ds-drop f ^^local-allot ^^box-alien ds-push drop ]
|
[ ds-drop ds-drop f ^^local-allot ^^box-alien ds-push drop ]
|
||||||
[ 2drop emit-primitive ]
|
[ 2drop basic-block get swap emit-primitive drop ]
|
||||||
if ;
|
if ;
|
||||||
|
|
||||||
: emit-cleanup-allot ( -- )
|
: emit-cleanup-allot ( -- )
|
||||||
[ drop ##no-tco, ] emit-trivial-block ;
|
basic-block get [ drop ##no-tco, ] emit-trivial-block drop ;
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
! Copyright (C) 2008, 2010 Slava Pestov.
|
! Copyright (C) 2008, 2010 Slava Pestov.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: accessors classes.algebra classes.builtin
|
USING: accessors classes.algebra classes.builtin
|
||||||
combinators.short-circuit compiler.cfg.builder.blocks
|
combinators.short-circuit compiler.cfg compiler.cfg.builder.blocks
|
||||||
compiler.cfg.hats compiler.cfg.instructions compiler.cfg.registers
|
compiler.cfg.hats compiler.cfg.instructions compiler.cfg.registers
|
||||||
compiler.cfg.stacks compiler.tree.propagation.info cpu.architecture
|
compiler.cfg.stacks compiler.tree.propagation.info cpu.architecture
|
||||||
kernel layouts locals math namespaces sequences slots.private ;
|
kernel layouts locals math namespaces sequences ;
|
||||||
IN: compiler.cfg.intrinsics.slots
|
IN: compiler.cfg.intrinsics.slots
|
||||||
|
|
||||||
: class-tag ( class -- tag/f )
|
: class-tag ( class -- tag/f )
|
||||||
|
@ -37,7 +37,7 @@ IN: compiler.cfg.intrinsics.slots
|
||||||
dup second literal>> immediate-slot-offset?
|
dup second literal>> immediate-slot-offset?
|
||||||
[ (emit-slot-imm) ] [ (emit-slot) ] if
|
[ (emit-slot-imm) ] [ (emit-slot) ] if
|
||||||
ds-push
|
ds-push
|
||||||
] [ drop emit-primitive ] if ;
|
] [ drop basic-block get swap emit-primitive drop ] if ;
|
||||||
|
|
||||||
:: (emit-set-slot-imm) ( write-barrier? tag slot -- )
|
:: (emit-set-slot-imm) ( write-barrier? tag slot -- )
|
||||||
ds-drop
|
ds-drop
|
||||||
|
@ -71,4 +71,4 @@ IN: compiler.cfg.intrinsics.slots
|
||||||
: emit-set-slot ( node -- )
|
: emit-set-slot ( node -- )
|
||||||
dup node>set-slot-data over [
|
dup node>set-slot-data over [
|
||||||
emit-intrinsic-set-slot drop
|
emit-intrinsic-set-slot drop
|
||||||
] [ 3drop emit-primitive ] if ;
|
] [ 3drop basic-block get swap emit-primitive drop ] if ;
|
||||||
|
|
Loading…
Reference in New Issue