factor/basis/compiler/tree/escape-analysis/simple/simple.factor

91 lines
2.6 KiB
Factor
Raw Normal View History

2008-08-02 00:31:43 -04:00
! Copyright (C) 2008 Slava Pestov.
! 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-03 22:32:12 -04:00
combinators dequeues search-dequeues namespaces fry classes
2008-08-07 07:34:28 -04:00
classes.algebra stack-checker.state
2008-08-02 00:31:43 -04:00
compiler.tree
2008-08-08 14:14:36 -04:00
compiler.tree.intrinsics
2008-08-02 00:31:43 -04:00
compiler.tree.propagation.info
compiler.tree.escape-analysis.nodes
compiler.tree.escape-analysis.allocations ;
IN: compiler.tree.escape-analysis.simple
2008-08-07 07:34:28 -04:00
M: #terminate escape-analysis* drop ;
M: #renaming escape-analysis* inputs/outputs [ copy-value ] 2each ;
2008-08-14 00:52:49 -04:00
M: #introduce escape-analysis* out-d>> unknown-allocations ;
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 )
#! Delegation
2008-08-07 07:34:28 -04:00
{
2008-08-08 14:14:36 -04:00
{ [ dup class immutable-tuple-class? ] [ tuple-slots rest-slice ] }
{ [ dup complex? ] [ [ real-part ] [ imaginary-part ] bi 2array ] }
[ 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*
#! Delegation.
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-02 00:31:43 -04:00
: record-tuple-allocation ( #call -- )
2008-08-08 14:14:36 -04:00
[ in-d>> but-last ] [ out-d>> first ] bi record-allocation ;
2008-08-02 00:31:43 -04:00
2008-08-07 07:34:28 -04:00
: record-complex-allocation ( #call -- )
[ in-d>> ] [ out-d>> first ] bi record-allocation ;
: slot-offset ( #call -- n/f )
dup in-d>>
[ first node-value-info class>> ]
[ second node-value-info literal>> ] 2bi
dup fixnum? [
{
{ [ over tuple class<= ] [ 3 - ] }
{ [ over complex class<= ] [ 1 - ] }
[ drop f ]
} cond nip
] [ 2drop f ] if ;
2008-08-02 00:31:43 -04:00
: record-slot-call ( #call -- )
2008-08-07 07:34:28 -04:00
[ out-d>> first ] [ slot-offset ] [ in-d>> first ] tri
2008-08-08 14:14:36 -04:00
over [
[ record-slot-access ] [ copy-slot-value ] 3bi
] [ 2drop unknown-allocation ] if ;
2008-08-02 00:31:43 -04:00
M: #call escape-analysis*
dup word>> {
2008-08-08 14:14:36 -04:00
{ \ <immutable-tuple-boa> [ record-tuple-allocation ] }
2008-08-07 07:34:28 -04:00
{ \ <complex> [ record-complex-allocation ] }
2008-08-02 00:31:43 -04:00
{ \ slot [ record-slot-call ] }
2008-08-04 05:35:31 -04:00
[
drop
[ in-d>> add-escaping-values ]
[ out-d>> unknown-allocations ] bi
]
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 ]
[ out-d>> unknown-allocation ]
bi ;
M: #alien-indirect escape-analysis*
[ in-d>> add-escaping-values ]
[ out-d>> unknown-allocation ]
bi ;