]> gitweb.factorcode.org Git - factor.git/blob - basis/compiler/cfg/linear-scan/allocation/splitting/splitting.factor
Language change: tuple slot setter words with stack effect ( value object -- ) are...
[factor.git] / basis / compiler / cfg / linear-scan / allocation / splitting / splitting.factor
1 ! Copyright (C) 2009, 2010 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors arrays assocs combinators fry hints kernel locals
4 math sequences sets sorting splitting namespaces
5 compiler.cfg.linear-scan.allocation.state
6 compiler.cfg.linear-scan.live-intervals ;
7 IN: compiler.cfg.linear-scan.allocation.splitting
8
9 : split-range ( live-range n -- before after )
10     [ [ from>> ] dip <live-range> ]
11     [ 1 + swap to>> <live-range> ]
12     2bi ;
13
14 : split-last-range? ( last n -- ? )
15     swap to>> <= ;
16
17 : split-last-range ( before after last n -- before' after' )
18     split-range [ [ but-last ] dip suffix ] [ prefix ] bi-curry* bi* ;
19
20 : split-ranges ( live-ranges n -- before after )
21     [ '[ from>> _ <= ] partition ]
22     [
23         [ over last ] dip 2dup split-last-range?
24         [ split-last-range ] [ 2drop ] if
25     ] bi ;
26
27 : split-uses ( uses n -- before after )
28     '[ n>> _ <= ] partition ;
29
30 ERROR: splitting-too-early ;
31
32 ERROR: splitting-too-late ;
33
34 ERROR: splitting-atomic-interval ;
35
36 : check-split ( live-interval n -- )
37     check-allocation? get [
38         [ [ start>> ] dip > [ splitting-too-early ] when ]
39         [ [ end>> ] dip <= [ splitting-too-late ] when ]
40         [ drop [ end>> ] [ start>> ] bi = [ splitting-atomic-interval ] when ]
41         2tri
42     ] [ 2drop ] if ; inline
43
44 : split-before ( before -- before' )
45     f >>spill-to ; inline
46
47 : split-after ( after -- after' )
48     f >>reg f >>reload-from ; inline
49
50 :: split-interval ( live-interval n -- before after )
51     live-interval n check-split
52     live-interval clone :> before
53     live-interval clone :> after
54     live-interval uses>> n split-uses before after [ uses<< ] bi-curry@ bi*
55     live-interval ranges>> n split-ranges before after [ ranges<< ] bi-curry@ bi*
56     before split-before
57     after split-after ;
58
59 HINTS: split-interval live-interval object ;