compiler.cfg.*: big changes which removes the last basic-block uses
All intrinsic code generating words signatures are changed from ( node -- ) to ( block node -- block' ) so the current block is now always passed on the stack.db4
parent
482998974b
commit
9df955e199
|
@ -35,11 +35,15 @@ HELP: check-dlsym
|
|||
{ $description "Checks that a symbol with the given name exists in the given library. Throws an error if not." } ;
|
||||
|
||||
HELP: emit-callback-body
|
||||
{ $values { "params" alien-node-params } }
|
||||
{ $values
|
||||
{ "block" basic-block }
|
||||
{ "nodes" alien-node-params }
|
||||
{ "block'" basic-block }
|
||||
}
|
||||
{ $description "Emits the nodes that forms the body of the alien callback." } ;
|
||||
|
||||
HELP: emit-callback-return
|
||||
{ $values { "params" alien-node-params } { "block" basic-block } }
|
||||
{ $values { "block" basic-block } { "params" alien-node-params } }
|
||||
{ $description "Emits a " { $link ##callback-outputs } " instruction for the " { $link #alien-callback } " if needed." } ;
|
||||
|
||||
HELP: unbox-parameters
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
USING: accessors alien alien.c-types compiler.cfg compiler.cfg.builder
|
||||
compiler.cfg.builder.alien compiler.cfg.instructions
|
||||
compiler.cfg.registers compiler.test compiler.tree.builder
|
||||
compiler.tree.optimizer cpu.architecture cpu.x86.assembler
|
||||
cpu.x86.assembler.operands kernel make namespaces sequences system
|
||||
tools.test words ;
|
||||
compiler.cfg.builder.alien compiler.cfg.builder.blocks
|
||||
compiler.cfg.instructions compiler.cfg.registers compiler.test
|
||||
compiler.tree.builder compiler.tree.optimizer cpu.architecture
|
||||
cpu.x86.assembler cpu.x86.assembler.operands kernel make namespaces
|
||||
sequences system tools.test words ;
|
||||
IN: compiler.cfg.builder.alien.tests
|
||||
|
||||
! unboxing ints is only needed on 32bit archs
|
||||
|
@ -35,7 +35,7 @@ cpu x86.32?
|
|||
] alien-assembly ;
|
||||
|
||||
{ t } [
|
||||
<basic-block> dup basic-block set dup
|
||||
<basic-block> dup set-basic-block dup
|
||||
\ dummy-assembly build-tree optimize-tree first
|
||||
[ emit-node ] V{ } make drop eq?
|
||||
] unit-test
|
||||
|
@ -58,7 +58,7 @@ cpu x86.32?
|
|||
T{ ##branch }
|
||||
}
|
||||
} [
|
||||
basic-block get
|
||||
<basic-block> dup set-basic-block
|
||||
\ dummy-callback build-tree optimize-tree 3 swap nth child>>
|
||||
[ emit-callback-body drop ] V{ } make
|
||||
] cfg-unit-test
|
||||
|
|
|
@ -35,7 +35,7 @@ HELP: begin-basic-block
|
|||
HELP: begin-branch
|
||||
{ $values
|
||||
{ "block" "current " { $link basic-block } }
|
||||
{ "block" basic-block }
|
||||
{ "block'" basic-block }
|
||||
}
|
||||
{ $description "Used to begin emitting a branch." } ;
|
||||
|
||||
|
@ -87,9 +87,7 @@ HELP: with-branch
|
|||
}
|
||||
{ $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"
|
||||
"CFG construction utilities"
|
||||
$nl
|
||||
ARTICLE: "compiler.cfg.builder.blocks" "CFG construction utilities"
|
||||
"This vocab contains utilities for that helps " { $vocab-link "compiler.cfg.builder" } " to construct CFG:s."
|
||||
$nl
|
||||
"Combinators:"
|
||||
|
@ -102,6 +100,7 @@ $nl
|
|||
begin-branch
|
||||
emit-call-block
|
||||
emit-conditional
|
||||
emit-trivial-call
|
||||
} ;
|
||||
|
||||
ABOUT: "compiler.cfg.builder.blocks"
|
||||
|
|
|
@ -29,8 +29,8 @@ IN: compiler.cfg.builder.blocks.tests
|
|||
] cfg-unit-test
|
||||
|
||||
! end-basic-block
|
||||
{ f } [
|
||||
f end-basic-block basic-block get
|
||||
{ } [
|
||||
<basic-block> dup set-basic-block ##branch, end-basic-block
|
||||
] unit-test
|
||||
|
||||
! make-kill-block
|
||||
|
|
|
@ -35,9 +35,11 @@ IN: compiler.cfg.builder.blocks
|
|||
: emit-call-block ( word height block -- )
|
||||
make-kill-block adjust-d ##call, ;
|
||||
|
||||
: emit-primitive ( block node -- block' )
|
||||
[ word>> ] [ call-height ] bi rot
|
||||
[ emit-call-block ] emit-trivial-block ;
|
||||
: emit-trivial-call ( block word height -- block' )
|
||||
rot [ emit-call-block ] emit-trivial-block ;
|
||||
|
||||
: emit-primitive ( block #call -- block' )
|
||||
[ word>> ] [ call-height ] bi emit-trivial-call ;
|
||||
|
||||
: begin-branch ( block -- block' )
|
||||
height-state [ clone-height-state ] change (begin-basic-block) ;
|
||||
|
|
|
@ -128,7 +128,6 @@ HELP: with-cfg-builder
|
|||
|
||||
ARTICLE: "compiler.cfg.builder"
|
||||
"Final stage of compilation generates machine code from dataflow IR"
|
||||
$nl
|
||||
"The compiler first builds an SSA IR tree of the word to be compiled (see " { $vocab-link "compiler.tree.builder" } ") then this vocab converts it to a CFG IR tree. The result is not in SSA form; this is constructed later by calling compiler.cfg.ssa.construction:construct-ssa."
|
||||
$nl
|
||||
"Main word:"
|
||||
|
@ -148,7 +147,6 @@ $nl
|
|||
{ $subsections
|
||||
emit-call
|
||||
emit-loop-call
|
||||
emit-trivial-call
|
||||
}
|
||||
"Emitters for " { $link #dispatch } " and " { $link #if } ":"
|
||||
{ $subsections
|
||||
|
|
|
@ -271,17 +271,10 @@ SYMBOL: foo
|
|||
] cfg-unit-test
|
||||
|
||||
! emit-loop-call
|
||||
{ 1 } [
|
||||
V{ } 0 insns>block basic-block set init-cfg-test
|
||||
V{ } 1 insns>block [ basic-block get emit-loop-call ] V{ } make drop
|
||||
basic-block get successors>> length
|
||||
] unit-test
|
||||
|
||||
{ "bar" } [
|
||||
V{ } "foo" insns>block basic-block set
|
||||
init-cfg-test
|
||||
[ V{ } "bar" insns>block basic-block get emit-loop-call ] V{ } make drop
|
||||
basic-block get successors>> first number>>
|
||||
{ 1 "good" } [
|
||||
V{ } 0 insns>block dup set-basic-block
|
||||
V{ } "good" insns>block swap [ emit-loop-call ] keep
|
||||
[ successors>> length ] [ successors>> first number>> ] bi
|
||||
] unit-test
|
||||
|
||||
! emit-node
|
||||
|
@ -342,8 +335,8 @@ SYMBOL: foo
|
|||
{
|
||||
V{ T{ ##call { word set-slot } } T{ ##branch } }
|
||||
} [
|
||||
[ f call-node-1 emit-node drop ] V{ } make drop
|
||||
basic-block get successors>> first instructions>>
|
||||
[ f call-node-1 emit-node ] V{ } make drop
|
||||
predecessors>> first instructions>>
|
||||
] cfg-unit-test
|
||||
|
||||
! ! #push
|
||||
|
@ -372,7 +365,7 @@ SYMBOL: foo
|
|||
! ! #terminate
|
||||
|
||||
{ f } [
|
||||
basic-block get dup set-basic-block
|
||||
<basic-block> dup set-basic-block
|
||||
T{ #terminate { in-d { } } { in-r { } } } emit-node
|
||||
] cfg-unit-test
|
||||
|
||||
|
|
|
@ -54,9 +54,6 @@ GENERIC: emit-node ( block node -- block' )
|
|||
##safepoint, ##branch,
|
||||
[ swap connect-bbs ] [ end-basic-block ] bi ;
|
||||
|
||||
: emit-trivial-call ( block word height -- block' )
|
||||
rot [ emit-call-block ] emit-trivial-block ;
|
||||
|
||||
: emit-call ( block word height -- block' )
|
||||
over loops get at [
|
||||
2nip swap emit-loop-call f
|
||||
|
@ -127,7 +124,7 @@ M: #dispatch emit-node ( block node -- block' )
|
|||
|
||||
M: #call emit-node ( block node -- block' )
|
||||
dup word>> dup "intrinsic" word-prop [
|
||||
nip call( node -- ) drop basic-block get
|
||||
nip call( block #call -- block' )
|
||||
] [ swap call-height emit-call ] if* ;
|
||||
|
||||
M: #call-recursive emit-node ( block node -- block' )
|
||||
|
|
|
@ -13,19 +13,19 @@ IN: compiler.cfg.intrinsics.alien
|
|||
[ second class>> c-ptr class<= ]
|
||||
} 1&& ;
|
||||
|
||||
: emit-<displaced-alien> ( node -- )
|
||||
: emit-<displaced-alien> ( block node -- block' )
|
||||
dup emit-<displaced-alien>? [
|
||||
'[
|
||||
_ node-input-infos second class>>
|
||||
^^box-displaced-alien
|
||||
] binary-op
|
||||
] [ basic-block get swap emit-primitive drop ] if ;
|
||||
] [ emit-primitive ] if ;
|
||||
|
||||
:: inline-accessor ( node quot test -- )
|
||||
node node-input-infos :> infos
|
||||
:: inline-accessor ( block #call quot test -- block' )
|
||||
#call node-input-infos :> infos
|
||||
infos test call
|
||||
[ infos quot call ]
|
||||
[ node basic-block get swap emit-primitive drop ] if ; inline
|
||||
[ infos quot call block ]
|
||||
[ block #call emit-primitive ] if ; inline
|
||||
|
||||
: inline-load-memory? ( infos -- ? )
|
||||
[ first class>> c-ptr class<= ]
|
||||
|
@ -38,15 +38,15 @@ IN: compiler.cfg.intrinsics.alien
|
|||
: prepare-load-memory ( infos -- base offset )
|
||||
[ 2inputs ] dip first prepare-accessor ;
|
||||
|
||||
: (emit-load-memory) ( node rep c-type quot -- )
|
||||
: (emit-load-memory) ( block node rep c-type quot -- block' )
|
||||
'[ prepare-load-memory _ _ ^^load-memory-imm @ ds-push ]
|
||||
[ inline-load-memory? ]
|
||||
inline-accessor ; inline
|
||||
|
||||
: emit-load-memory ( node rep c-type -- )
|
||||
: emit-load-memory ( block node rep c-type -- block' )
|
||||
[ ] (emit-load-memory) ;
|
||||
|
||||
: emit-alien-cell ( node -- )
|
||||
: emit-alien-cell ( block node -- block' )
|
||||
int-rep f [ ^^box-alien ] (emit-load-memory) ;
|
||||
|
||||
: inline-store-memory? ( infos class -- ? )
|
||||
|
@ -58,14 +58,14 @@ IN: compiler.cfg.intrinsics.alien
|
|||
: prepare-store-memory ( infos -- value base offset )
|
||||
[ 3inputs ] dip second prepare-accessor ;
|
||||
|
||||
:: (emit-store-memory) ( node rep c-type prepare-quot test-quot -- )
|
||||
node
|
||||
:: (emit-store-memory) ( block node rep c-type prepare-quot test-quot -- block' )
|
||||
block node
|
||||
[ prepare-quot call rep c-type ##store-memory-imm, ]
|
||||
[ test-quot call inline-store-memory? ]
|
||||
inline-accessor ; inline
|
||||
|
||||
:: emit-store-memory ( node rep c-type -- )
|
||||
node rep c-type
|
||||
:: emit-store-memory ( block node rep c-type -- block' )
|
||||
block node rep c-type
|
||||
[ prepare-store-memory ]
|
||||
[
|
||||
rep {
|
||||
|
@ -76,7 +76,7 @@ IN: compiler.cfg.intrinsics.alien
|
|||
]
|
||||
(emit-store-memory) ;
|
||||
|
||||
: emit-set-alien-cell ( node -- )
|
||||
: emit-set-alien-cell ( block node -- block' )
|
||||
int-rep f
|
||||
[
|
||||
[ first class>> ] [ prepare-store-memory ] bi
|
||||
|
|
|
@ -1,18 +1,33 @@
|
|||
USING: byte-arrays compiler.tree help.markup help.syntax ;
|
||||
USING: byte-arrays classes.tuple.private compiler.cfg compiler.tree
|
||||
help.markup help.syntax ;
|
||||
IN: compiler.cfg.intrinsics.allot
|
||||
|
||||
HELP: emit-<byte-array>
|
||||
{ $values { "node" node } }
|
||||
{ $values
|
||||
{ "block" "current " { $link basic-block } }
|
||||
{ "#call" node }
|
||||
{ "block'" basic-block }
|
||||
}
|
||||
{ $description "Emits optimized cfg instructions for allocating a " { $link byte-array } "." } ;
|
||||
|
||||
HELP: emit-<tuple-boa>
|
||||
{ $values { "node" node } }
|
||||
{ $description "Emits optimized cfg instructions for building and allocating tuples." } ;
|
||||
{ $values
|
||||
{ "block" "current " { $link basic-block } }
|
||||
{ "#call" #call }
|
||||
{ "block'" basic-block }
|
||||
}
|
||||
{ $description "Emits intrinsic cfg instructions for building and allocating tuples. The intrinsic condition is that the tuple layout given to " { $link <tuple-boa> } " must be a literal." }
|
||||
{ $see-also <tuple-boa> } ;
|
||||
|
||||
ARTICLE: "compiler.cfg.intrinsics.allot" "Generating instructions for inline memory allocation"
|
||||
"Generating instructions for inline memory allocation"
|
||||
$nl
|
||||
"Emitters:"
|
||||
{ $subsections emit-<byte-array> emit-<tuple-boa> } ;
|
||||
{ $subsections
|
||||
emit-(byte-array)
|
||||
emit-<array>
|
||||
emit-<byte-array>
|
||||
emit-<tuple-boa>
|
||||
} ;
|
||||
|
||||
ABOUT: "compiler.cfg.intrinsics.allot"
|
||||
|
|
|
@ -21,14 +21,14 @@ IN: compiler.cfg.intrinsics.allot
|
|||
: ^^allot-tuple ( n -- dst )
|
||||
2 + cells tuple ^^allot ;
|
||||
|
||||
: emit-<tuple-boa> ( node -- )
|
||||
: emit-<tuple-boa> ( block #call -- block' )
|
||||
dup node-input-infos last literal>>
|
||||
dup array? [
|
||||
nip
|
||||
ds-drop
|
||||
[ tuple-slot-regs ] [ second ^^allot-tuple ] bi
|
||||
[ tuple ##set-slots, ] [ ds-push drop ] 2bi
|
||||
] [ drop basic-block get swap emit-primitive drop ] if ;
|
||||
] [ drop emit-primitive ] if ;
|
||||
|
||||
: store-length ( len reg class -- )
|
||||
[ [ ^^load-literal ] dip 1 ] dip type-number ##set-slot-imm, ;
|
||||
|
@ -42,7 +42,7 @@ IN: compiler.cfg.intrinsics.allot
|
|||
: ^^allot-array ( n -- dst )
|
||||
2 + cells array ^^allot ;
|
||||
|
||||
:: emit-<array> ( node -- )
|
||||
:: emit-<array> ( block node -- block' )
|
||||
node node-input-infos first literal>> :> len
|
||||
len expand-<array>? [
|
||||
ds-pop :> elt
|
||||
|
@ -50,8 +50,8 @@ IN: compiler.cfg.intrinsics.allot
|
|||
ds-drop
|
||||
len reg array store-length
|
||||
len reg elt array store-initial-element
|
||||
reg ds-push
|
||||
] [ node basic-block get swap emit-primitive drop ] if ;
|
||||
reg ds-push block
|
||||
] [ block node emit-primitive ] if ;
|
||||
|
||||
: expand-(byte-array)? ( obj -- ? )
|
||||
dup integer? [ 0 1024 between? ] [ drop f ] if ;
|
||||
|
@ -67,9 +67,10 @@ IN: compiler.cfg.intrinsics.allot
|
|||
: emit-allot-byte-array ( len -- dst )
|
||||
ds-drop ^^allot-byte-array dup ds-push ;
|
||||
|
||||
: emit-(byte-array) ( node -- )
|
||||
dup node-input-infos first literal>> dup expand-(byte-array)?
|
||||
[ nip emit-allot-byte-array drop ] [ drop basic-block get swap emit-primitive drop ] if ;
|
||||
: emit-(byte-array) ( block node -- block' )
|
||||
dup node-input-infos first literal>> dup expand-(byte-array)? [
|
||||
nip emit-allot-byte-array drop
|
||||
] [ drop emit-primitive ] if ;
|
||||
|
||||
:: zero-byte-array ( len reg -- )
|
||||
0 ^^load-literal :> elt
|
||||
|
@ -78,9 +79,9 @@ IN: compiler.cfg.intrinsics.allot
|
|||
[ elt reg ] dip cells byte-array-offset + int-rep f ##store-memory-imm,
|
||||
] each ;
|
||||
|
||||
:: emit-<byte-array> ( node -- )
|
||||
node node-input-infos first literal>> dup expand-<byte-array>? [
|
||||
:: emit-<byte-array> ( block #call -- block' )
|
||||
#call node-input-infos first literal>> dup expand-<byte-array>? [
|
||||
:> len
|
||||
len emit-allot-byte-array :> reg
|
||||
len reg zero-byte-array
|
||||
] [ drop node basic-block get swap emit-primitive drop ] if ;
|
||||
len reg zero-byte-array block
|
||||
] [ drop block #call emit-primitive ] if ;
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
! Copyright (C) 2008, 2010 Slava Pestov, Doug Coleman.
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
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 ;
|
||||
USING: accessors arrays combinators 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
|
||||
locals math math.intervals namespaces sequences ;
|
||||
IN: compiler.cfg.intrinsics.fixnum
|
||||
|
||||
: emit-both-fixnums? ( -- )
|
||||
|
@ -25,13 +24,13 @@ IN: compiler.cfg.intrinsics.fixnum
|
|||
tag-bits get ^^sar-imm
|
||||
] binary-op ;
|
||||
|
||||
: emit-fixnum-shift-general ( -- )
|
||||
ds-peek 0 cc> ##compare-integer-imm-branch,
|
||||
basic-block get [ emit-fixnum-left-shift ] with-branch
|
||||
basic-block get [ emit-fixnum-right-shift ] with-branch
|
||||
2array basic-block get swap emit-conditional drop ;
|
||||
: emit-fixnum-shift-general ( block -- block' )
|
||||
ds-peek 0 cc> ##compare-integer-imm-branch, dup
|
||||
[ [ emit-fixnum-left-shift ] with-branch ]
|
||||
[ [ emit-fixnum-right-shift ] with-branch ] bi 2array
|
||||
emit-conditional ;
|
||||
|
||||
: emit-fixnum-shift-fast ( node -- )
|
||||
: emit-fixnum-shift-fast ( block #call -- block' )
|
||||
node-input-infos second interval>> {
|
||||
{ [ dup 0 [a,inf] interval-subset? ] [ drop emit-fixnum-left-shift ] }
|
||||
{ [ dup 0 [-inf,a] interval-subset? ] [ drop emit-fixnum-right-shift ] }
|
||||
|
@ -41,22 +40,17 @@ IN: compiler.cfg.intrinsics.fixnum
|
|||
: emit-fixnum-comparison ( cc -- )
|
||||
'[ _ ^^compare-integer ] binary-op ;
|
||||
|
||||
: emit-no-overflow-case ( dst -- final-bb )
|
||||
basic-block get [
|
||||
swap D: -2 inc-stack ds-push
|
||||
] with-branch ;
|
||||
: emit-no-overflow-case ( dst block -- final-bb )
|
||||
[ swap D: -2 inc-stack ds-push ] with-branch ;
|
||||
|
||||
: emit-overflow-case ( word -- final-bb )
|
||||
basic-block get [
|
||||
swap -1 basic-block get emit-call-block
|
||||
] with-branch ;
|
||||
: emit-overflow-case ( word block -- final-bb )
|
||||
[ -1 swap [ emit-call-block ] keep ] with-branch ;
|
||||
|
||||
: emit-fixnum-overflow-op ( quot word -- )
|
||||
! Inputs to the final instruction need to be copied because
|
||||
! of loc>vreg sync
|
||||
[ [ (2inputs) [ any-rep ^^copy ] bi@ cc/o ] dip call ] dip
|
||||
[ emit-no-overflow-case ] [ emit-overflow-case ] bi* 2array
|
||||
basic-block get swap emit-conditional drop ; inline
|
||||
:: emit-fixnum-overflow-op ( block quot word -- block' )
|
||||
(2inputs) [ any-rep ^^copy ] bi@ cc/o
|
||||
quot call( vreg1 vreg2 cc -- vreg ) block emit-no-overflow-case
|
||||
word block emit-overflow-case 2array
|
||||
block swap emit-conditional ; inline
|
||||
|
||||
: fixnum+overflow ( x y -- z ) [ >bignum ] bi@ + ;
|
||||
|
||||
|
@ -64,11 +58,11 @@ IN: compiler.cfg.intrinsics.fixnum
|
|||
|
||||
: fixnum*overflow ( x y -- z ) [ >bignum ] bi@ * ;
|
||||
|
||||
: emit-fixnum+ ( -- )
|
||||
: emit-fixnum+ ( block -- block' )
|
||||
[ ^^fixnum-add ] \ fixnum+overflow emit-fixnum-overflow-op ;
|
||||
|
||||
: emit-fixnum- ( -- )
|
||||
: emit-fixnum- ( block -- block' )
|
||||
[ ^^fixnum-sub ] \ fixnum-overflow emit-fixnum-overflow-op ;
|
||||
|
||||
: emit-fixnum* ( -- )
|
||||
: emit-fixnum* ( block -- block' )
|
||||
[ ^^fixnum-mul ] \ fixnum*overflow emit-fixnum-overflow-op ;
|
||||
|
|
|
@ -65,7 +65,7 @@ ERROR: inline-intrinsics-not-supported word quot ;
|
|||
{ byte-arrays:(byte-array) [ emit-(byte-array) ] }
|
||||
{ kernel:<wrapper> [ emit-simple-allot ] }
|
||||
{ alien.data.private:(local-allot) [ emit-local-allot ] }
|
||||
{ alien.data.private:(cleanup-allot) [ drop emit-cleanup-allot ] }
|
||||
{ alien.data.private:(cleanup-allot) [ emit-cleanup-allot ] }
|
||||
{ alien:<displaced-alien> [ emit-<displaced-alien> ] }
|
||||
{ alien.accessors:alien-unsigned-1 [ int-rep alien.c-types:uchar emit-load-memory ] }
|
||||
{ alien.accessors:set-alien-unsigned-1 [ int-rep alien.c-types:uchar emit-store-memory ] }
|
||||
|
|
|
@ -1,6 +1,11 @@
|
|||
USING: compiler.tree help.markup help.syntax kernel.private words ;
|
||||
USING: compiler.cfg compiler.tree help.markup help.syntax
|
||||
kernel.private ;
|
||||
IN: compiler.cfg.intrinsics.misc
|
||||
|
||||
HELP: emit-context-object
|
||||
{ $values { "node" node } }
|
||||
{ $values
|
||||
{ "block" "current " { $link basic-block } }
|
||||
{ "node" node }
|
||||
{ "block'" basic-block }
|
||||
}
|
||||
{ $description "Emits intrinsic code for a call to the " { $link context-object } " primitive." } ;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
! Copyright (C) 2008, 2010 Slava Pestov.
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: accessors classes.algebra classes.struct compiler.cfg
|
||||
USING: accessors classes.algebra classes.struct
|
||||
compiler.cfg.builder.blocks compiler.cfg.comparisons compiler.cfg.hats
|
||||
compiler.cfg.instructions compiler.cfg.stacks compiler.constants
|
||||
compiler.tree.propagation.info cpu.architecture kernel layouts math
|
||||
|
@ -14,27 +14,27 @@ IN: compiler.cfg.intrinsics.misc
|
|||
node-input-infos first2 [ class>> fixnum class<= ] both?
|
||||
[ [ cc= ^^compare-integer ] binary-op ] [ [ cc= ^^compare ] binary-op ] if ;
|
||||
|
||||
: emit-special-object ( node -- )
|
||||
: emit-special-object ( block node -- block' )
|
||||
dup node-input-infos first literal>> [
|
||||
ds-drop
|
||||
vm-special-object-offset ^^vm-field
|
||||
ds-push
|
||||
] [ basic-block get swap emit-primitive drop ] ?if ;
|
||||
] [ emit-primitive ] ?if ;
|
||||
|
||||
: emit-set-special-object ( node -- )
|
||||
: emit-set-special-object ( block node -- block' )
|
||||
dup node-input-infos second literal>> [
|
||||
ds-drop
|
||||
[ ds-pop ] dip vm-special-object-offset ##set-vm-field,
|
||||
] [ basic-block get swap emit-primitive drop ] ?if ;
|
||||
] [ emit-primitive ] ?if ;
|
||||
|
||||
: context-object-offset ( n -- n )
|
||||
cells "context-objects" context offset-of + ;
|
||||
|
||||
: emit-context-object ( node -- )
|
||||
: emit-context-object ( block node -- block' )
|
||||
dup node-input-infos first literal>> [
|
||||
"ctx" vm offset-of ^^vm-field
|
||||
ds-drop swap context-object-offset cell /i 0 ^^slot-imm ds-push
|
||||
] [ basic-block get swap emit-primitive drop ] ?if ;
|
||||
] [ emit-primitive ] ?if ;
|
||||
|
||||
: emit-identity-hashcode ( -- )
|
||||
[
|
||||
|
@ -44,11 +44,10 @@ IN: compiler.cfg.intrinsics.misc
|
|||
hashcode-shift ^^shr-imm
|
||||
] unary-op ;
|
||||
|
||||
: emit-local-allot ( node -- )
|
||||
: emit-local-allot ( block node -- block' )
|
||||
dup node-input-infos first2 [ literal>> ] bi@ 2dup [ integer? ] both?
|
||||
[ ds-drop ds-drop f ^^local-allot ^^box-alien ds-push drop ]
|
||||
[ 2drop basic-block get swap emit-primitive drop ]
|
||||
if ;
|
||||
[ 2drop emit-primitive ] if ;
|
||||
|
||||
: emit-cleanup-allot ( -- )
|
||||
basic-block get [ drop ##no-tco, ] emit-trivial-block drop ;
|
||||
: emit-cleanup-allot ( block node -- block' )
|
||||
drop [ drop ##no-tco, ] emit-trivial-block ;
|
||||
|
|
|
@ -633,7 +633,7 @@ PREDICATE: fixnum-vector-rep < int-vector-rep
|
|||
{ float-vector-rep [ ^select-vector ] }
|
||||
} [ integer? ] emit-vl-vector-op ;
|
||||
|
||||
: emit-alien-vector ( node -- )
|
||||
: emit-alien-vector ( block node -- block' )
|
||||
dup [
|
||||
'[
|
||||
ds-drop prepare-load-memory
|
||||
|
@ -642,14 +642,13 @@ PREDICATE: fixnum-vector-rep < int-vector-rep
|
|||
[ inline-load-memory? ] inline-accessor
|
||||
] with { [ %alien-vector-reps member? ] } if-literals-match ;
|
||||
|
||||
: emit-set-alien-vector ( node -- )
|
||||
: emit-set-alien-vector ( block node -- block' )
|
||||
dup [
|
||||
'[
|
||||
ds-drop prepare-store-memory
|
||||
_ f ##store-memory-imm,
|
||||
]
|
||||
[ byte-array inline-store-memory? ]
|
||||
inline-accessor
|
||||
[ byte-array inline-store-memory? ] inline-accessor
|
||||
] with { [ %alien-vector-reps member? ] } if-literals-match ;
|
||||
|
||||
: enable-simd ( -- )
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
USING: classes classes.builtin compiler.cfg.instructions compiler.tree
|
||||
compiler.tree.propagation.info help.markup help.syntax kernel layouts
|
||||
math slots.private ;
|
||||
USING: classes classes.builtin compiler.cfg compiler.cfg.instructions
|
||||
compiler.tree compiler.tree.propagation.info help.markup help.syntax
|
||||
kernel layouts math slots.private ;
|
||||
IN: compiler.cfg.intrinsics.slots
|
||||
|
||||
HELP: class-tag
|
||||
|
@ -39,5 +39,21 @@ HELP: value-tag
|
|||
{ $description "Finds the class number for this value-info-states class (an index in the " { $link builtins } " list), or " { $link f } " if it hasn't one." } ;
|
||||
|
||||
HELP: emit-set-slot
|
||||
{ $values { "node" node } }
|
||||
{ $values
|
||||
{ "block" basic-block }
|
||||
{ "#call" #call }
|
||||
{ "block'" basic-block }
|
||||
}
|
||||
{ $description "Emits intrinsic code for a " { $link set-slot } " call." } ;
|
||||
|
||||
ARTICLE: "compiler.cfg.intrinsics.slots"
|
||||
"Generating instructions for slot access"
|
||||
"This vocab has words for generating intrinsic CFG instructions for slot accessors."
|
||||
$nl
|
||||
"Main words, called directly by the compiler through the \"intrinsic\" word property:"
|
||||
{ $subsections
|
||||
emit-set-slot
|
||||
emit-slot
|
||||
} ;
|
||||
|
||||
ABOUT: "compiler.cfg.intrinsics.slots"
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
USING: accessors arrays compiler.cfg compiler.cfg.instructions
|
||||
compiler.cfg.intrinsics.slots compiler.test compiler.tree
|
||||
compiler.tree.propagation.info kernel layouts literals make math
|
||||
math.intervals namespaces sequences slots.private tools.test ;
|
||||
USING: accessors arrays compiler.cfg compiler.cfg.builder.blocks
|
||||
compiler.cfg.instructions compiler.cfg.intrinsics.slots compiler.test
|
||||
compiler.tree compiler.tree.propagation.info kernel layouts literals
|
||||
make math math.intervals sequences slots.private tools.test ;
|
||||
IN: compiler.cfg.intrinsics.slots.tests
|
||||
|
||||
: call-node-1 ( -- node )
|
||||
|
@ -111,8 +111,9 @@ IN: compiler.cfg.intrinsics.slots.tests
|
|||
{
|
||||
V{ T{ ##call { word set-slot } } T{ ##branch } }
|
||||
} [
|
||||
<basic-block> dup set-basic-block
|
||||
call-node-1 [ emit-set-slot ] V{ } make drop
|
||||
basic-block get successors>> first instructions>>
|
||||
predecessors>> first instructions>>
|
||||
] cfg-unit-test
|
||||
|
||||
{
|
||||
|
|
|
@ -30,14 +30,14 @@ IN: compiler.cfg.intrinsics.slots
|
|||
: immediate-slot-offset? ( object -- ? )
|
||||
{ [ fixnum? ] [ cell * immediate-arithmetic? ] } 1&& ;
|
||||
|
||||
: emit-slot ( node -- )
|
||||
: emit-slot ( block node -- block' )
|
||||
dup node-input-infos
|
||||
dup first value-tag [
|
||||
nip
|
||||
dup second literal>> immediate-slot-offset?
|
||||
[ (emit-slot-imm) ] [ (emit-slot) ] if
|
||||
ds-push
|
||||
] [ drop basic-block get swap emit-primitive drop ] if ;
|
||||
] [ drop emit-primitive ] if ;
|
||||
|
||||
:: (emit-set-slot-imm) ( write-barrier? tag slot -- )
|
||||
ds-drop
|
||||
|
@ -68,7 +68,7 @@ IN: compiler.cfg.intrinsics.slots
|
|||
(emit-set-slot-imm)
|
||||
] [ drop (emit-set-slot) ] if ;
|
||||
|
||||
: emit-set-slot ( node -- )
|
||||
: emit-set-slot ( block #call -- block' )
|
||||
dup node>set-slot-data over [
|
||||
emit-intrinsic-set-slot drop
|
||||
] [ 3drop basic-block get swap emit-primitive drop ] if ;
|
||||
] [ 3drop emit-primitive ] if ;
|
||||
|
|
Loading…
Reference in New Issue