2009-08-09 17:29:21 -04:00
|
|
|
! Copyright (C) 2008, 2009 Slava Pestov.
|
2008-08-02 00:31:43 -04:00
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
|
|
|
USING: kernel accessors sequences classes.tuple
|
2008-08-07 07:34:28 -04:00
|
|
|
classes.tuple.private arrays math math.private slots.private
|
2008-08-27 06:52:38 -04:00
|
|
|
combinators deques search-deques namespaces fry classes
|
2009-08-09 17:29:21 -04:00
|
|
|
classes.algebra assocs stack-checker.state
|
2008-08-02 00:31:43 -04:00
|
|
|
compiler.tree
|
|
|
|
compiler.tree.propagation.info
|
|
|
|
compiler.tree.escape-analysis.nodes
|
|
|
|
compiler.tree.escape-analysis.allocations ;
|
|
|
|
IN: compiler.tree.escape-analysis.simple
|
|
|
|
|
2009-08-09 17:29:21 -04:00
|
|
|
M: #declare escape-analysis* drop ;
|
|
|
|
|
2008-08-07 07:34:28 -04:00
|
|
|
M: #terminate escape-analysis* drop ;
|
|
|
|
|
2008-08-31 10:03:03 -04:00
|
|
|
M: #renaming escape-analysis* inputs/outputs copy-values ;
|
2008-08-07 07:34:28 -04:00
|
|
|
|
2009-08-09 17:29:21 -04:00
|
|
|
: declared-class ( value -- class/f )
|
|
|
|
next-node get dup #declare? [ declaration>> at ] [ 2drop f ] if ;
|
|
|
|
|
|
|
|
: record-param-allocation ( value class -- )
|
|
|
|
dup immutable-tuple-class? [
|
|
|
|
[ swap set-value-class ] [
|
|
|
|
all-slots [
|
|
|
|
[ <slot-value> dup ] [ class>> ] bi*
|
|
|
|
record-param-allocation
|
|
|
|
] map swap record-allocation
|
|
|
|
] 2bi
|
|
|
|
] [ drop unknown-allocation ] if ;
|
|
|
|
|
|
|
|
M: #introduce escape-analysis*
|
|
|
|
out-d>> [ dup declared-class record-param-allocation ] each ;
|
2008-08-07 07:34:28 -04:00
|
|
|
|
|
|
|
DEFER: record-literal-allocation
|
|
|
|
|
|
|
|
: make-literal-slots ( seq -- values )
|
|
|
|
[ <slot-value> [ swap record-literal-allocation ] keep ] map ;
|
|
|
|
|
2008-08-08 14:14:36 -04:00
|
|
|
: object-slots ( object -- slots/f )
|
2008-08-07 07:34:28 -04:00
|
|
|
{
|
2008-09-03 04:46:56 -04:00
|
|
|
{ [ dup class immutable-tuple-class? ] [ tuple-slots ] }
|
2008-08-08 14:14:36 -04:00
|
|
|
[ drop f ]
|
2008-08-07 07:34:28 -04:00
|
|
|
} cond ;
|
2008-08-04 05:35:31 -04:00
|
|
|
|
2008-08-08 14:14:36 -04:00
|
|
|
: record-literal-allocation ( value object -- )
|
2008-08-10 00:00:27 -04:00
|
|
|
object-slots
|
|
|
|
[ make-literal-slots swap record-allocation ]
|
|
|
|
[ unknown-allocation ]
|
|
|
|
if* ;
|
2008-08-08 14:14:36 -04:00
|
|
|
|
2008-08-03 22:32:12 -04:00
|
|
|
M: #push escape-analysis*
|
2008-08-04 05:35:31 -04:00
|
|
|
[ out-d>> first ] [ literal>> ] bi record-literal-allocation ;
|
2008-08-03 22:32:12 -04:00
|
|
|
|
2008-08-22 16:30:57 -04:00
|
|
|
: record-unknown-allocation ( #call -- )
|
|
|
|
[ in-d>> add-escaping-values ]
|
|
|
|
[ out-d>> unknown-allocations ] bi ;
|
|
|
|
|
2008-08-02 00:31:43 -04:00
|
|
|
: record-tuple-allocation ( #call -- )
|
2008-08-22 16:30:57 -04:00
|
|
|
dup immutable-tuple-boa?
|
|
|
|
[ [ in-d>> but-last ] [ out-d>> first ] bi record-allocation ]
|
|
|
|
[ record-unknown-allocation ]
|
|
|
|
if ;
|
2008-08-02 00:31:43 -04:00
|
|
|
|
2008-08-07 07:34:28 -04:00
|
|
|
: slot-offset ( #call -- n/f )
|
|
|
|
dup in-d>>
|
2009-05-15 18:18:38 -04:00
|
|
|
[ second node-value-info literal>> ]
|
|
|
|
[ first node-value-info class>> ] 2bi
|
|
|
|
2dup [ fixnum? ] [ tuple class<= ] bi* and [
|
|
|
|
over 2 >= [ drop 2 - ] [ 2drop f ] if
|
2008-08-07 07:34:28 -04:00
|
|
|
] [ 2drop f ] if ;
|
|
|
|
|
2008-08-02 00:31:43 -04:00
|
|
|
: record-slot-call ( #call -- )
|
2008-08-18 16:47:49 -04:00
|
|
|
[ out-d>> first ] [ slot-offset ] [ in-d>> first ] tri over
|
|
|
|
[ [ record-slot-access ] [ copy-slot-value ] 3bi ]
|
|
|
|
[ [ unknown-allocation ] [ drop ] [ add-escaping-value ] tri* ]
|
|
|
|
if ;
|
2008-08-02 00:31:43 -04:00
|
|
|
|
|
|
|
M: #call escape-analysis*
|
|
|
|
dup word>> {
|
2008-08-22 16:30:57 -04:00
|
|
|
{ \ <tuple-boa> [ record-tuple-allocation ] }
|
2008-08-02 00:31:43 -04:00
|
|
|
{ \ slot [ record-slot-call ] }
|
2008-08-22 16:30:57 -04:00
|
|
|
[ drop record-unknown-allocation ]
|
2008-08-02 00:31:43 -04:00
|
|
|
} case ;
|
|
|
|
|
|
|
|
M: #return escape-analysis*
|
|
|
|
in-d>> add-escaping-values ;
|
2008-08-12 03:41:18 -04:00
|
|
|
|
|
|
|
M: #alien-invoke escape-analysis*
|
|
|
|
[ in-d>> add-escaping-values ]
|
2008-08-15 00:35:19 -04:00
|
|
|
[ out-d>> unknown-allocations ]
|
2008-08-12 03:41:18 -04:00
|
|
|
bi ;
|
|
|
|
|
|
|
|
M: #alien-indirect escape-analysis*
|
|
|
|
[ in-d>> add-escaping-values ]
|
2008-08-15 00:35:19 -04:00
|
|
|
[ out-d>> unknown-allocations ]
|
2008-08-12 03:41:18 -04:00
|
|
|
bi ;
|
2008-08-18 16:47:49 -04:00
|
|
|
|
|
|
|
M: #alien-callback escape-analysis* drop ;
|