Tweak method inlining heuristic a bit

db4
Slava Pestov 2008-07-04 04:41:27 -05:00
parent c5396ca30c
commit fc9e87db1c
2 changed files with 24 additions and 21 deletions

View File

@ -9,13 +9,12 @@ sequences growable sbufs vectors sequences.private accessors kernel ;
\ dispatching-class must-infer \ dispatching-class must-infer
! Make sure we have sane heuristics ! Make sure we have sane heuristics
: should-inline? ( generic class -- ? ) method flat-length 10 <= ; [ t ] [ \ fixnum \ shift method should-inline? ] unit-test
[ f ] [ \ array \ equal? method should-inline? ] unit-test
[ t ] [ \ fixnum \ shift should-inline? ] unit-test [ f ] [ \ sequence \ hashcode* method should-inline? ] unit-test
[ f ] [ \ array \ equal? should-inline? ] unit-test [ t ] [ \ array \ nth-unsafe method should-inline? ] unit-test
[ f ] [ \ sequence \ hashcode* should-inline? ] unit-test [ t ] [ \ growable \ nth-unsafe method should-inline? ] unit-test
[ t ] [ \ array \ nth-unsafe should-inline? ] unit-test [ t ] [ \ sbuf \ set-nth-unsafe method should-inline? ] unit-test
[ t ] [ \ growable \ nth-unsafe should-inline? ] unit-test [ t ] [ \ growable \ set-nth-unsafe method should-inline? ] unit-test
[ t ] [ \ sbuf \ set-nth-unsafe should-inline? ] unit-test [ t ] [ \ growable \ set-nth method should-inline? ] unit-test
[ t ] [ \ growable \ set-nth-unsafe should-inline? ] unit-test [ t ] [ \ vector \ (>>length) method should-inline? ] unit-test
[ t ] [ \ vector \ (>>length) should-inline? ] unit-test

View File

@ -7,7 +7,7 @@ combinators classes classes.algebra generic.math
optimizer.math.partial continuations optimizer.def-use optimizer.math.partial continuations optimizer.def-use
optimizer.backend generic.standard optimizer.specializers optimizer.backend generic.standard optimizer.specializers
optimizer.def-use optimizer.pattern-match generic.standard optimizer.def-use optimizer.pattern-match generic.standard
optimizer.control kernel.private definitions ; optimizer.control kernel.private definitions sets ;
IN: optimizer.inlining IN: optimizer.inlining
: remember-inlining ( node history -- ) : remember-inlining ( node history -- )
@ -25,19 +25,17 @@ IN: optimizer.inlining
tuck splice-node ; tuck splice-node ;
! A heuristic to avoid excessive inlining ! A heuristic to avoid excessive inlining
SYMBOL: recursive-calls
DEFER: (flat-length) DEFER: (flat-length)
: word-flat-length ( word -- n ) : word-flat-length ( word -- n )
{ {
! heuristic: { ... } declare comes up in method bodies
! and we don't care about it
{ [ dup \ declare eq? ] [ drop -2 ] }
! not inline ! not inline
{ [ dup inline? not ] [ drop 1 ] } { [ dup inline? not ] [ drop 0 ] }
! recursive and inline ! recursive and inline
{ [ dup get ] [ drop 1 ] } { [ dup recursive-calls get key? ] [ drop 4 ] }
! inline ! inline
[ dup dup set def>> (flat-length) ] [ [ recursive-calls get conjoin ] [ def>> (flat-length) ] bi ]
} cond ; } cond ;
: (flat-length) ( seq -- n ) : (flat-length) ( seq -- n )
@ -46,12 +44,16 @@ DEFER: (flat-length)
{ [ dup quotation? ] [ (flat-length) 1+ ] } { [ dup quotation? ] [ (flat-length) 1+ ] }
{ [ dup array? ] [ (flat-length) ] } { [ dup array? ] [ (flat-length) ] }
{ [ dup word? ] [ word-flat-length ] } { [ dup word? ] [ word-flat-length ] }
[ drop 1 ] [ drop 0 ]
} cond } cond
] sigma ; ] sigma ;
: flat-length ( word -- n ) : flat-length ( word -- n )
[ def>> (flat-length) ] with-scope ; H{ } clone recursive-calls [
[ recursive-calls get conjoin ]
[ def>> (flat-length) ]
bi
] with-variable ;
! Single dispatch method inlining optimization ! Single dispatch method inlining optimization
! : dispatching-class ( node generic -- method/f ) ! : dispatching-class ( node generic -- method/f )
@ -208,9 +210,11 @@ DEFER: (flat-length)
dup node-param splice-word-def dup node-param splice-word-def
] if ; ] if ;
: should-inline? ( word -- ? )
flat-length 11 <= ;
: method-body-inline? ( #call -- ? ) : method-body-inline? ( #call -- ? )
node-param dup method-body? node-param dup method-body? [ should-inline? ] [ drop f ] if ;
[ flat-length 10 <= ] [ drop f ] if ;
M: #call optimize-node* M: #call optimize-node*
{ {