New inlining heuristic: number of usages within this word. Speeds up bootstrap by 10%
parent
e304d3c9f8
commit
fa6a2047f0
|
@ -20,6 +20,10 @@ SYMBOL: node-count
|
||||||
: count-nodes ( nodes -- )
|
: count-nodes ( nodes -- )
|
||||||
0 swap [ drop 1+ ] each-node node-count set ;
|
0 swap [ drop 1+ ] each-node node-count set ;
|
||||||
|
|
||||||
|
! We try not to inline the same word too many times, to avoid
|
||||||
|
! combinatorial explosion
|
||||||
|
SYMBOL: inlining-count
|
||||||
|
|
||||||
! Splicing nodes
|
! Splicing nodes
|
||||||
GENERIC: splicing-nodes ( #call word/quot/f -- nodes )
|
GENERIC: splicing-nodes ( #call word/quot/f -- nodes )
|
||||||
|
|
||||||
|
@ -120,17 +124,25 @@ DEFER: (flat-length)
|
||||||
bi and
|
bi and
|
||||||
] contains? ;
|
] contains? ;
|
||||||
|
|
||||||
|
: node-count-bias ( -- n )
|
||||||
|
45 node-count get [-] 8 /i ;
|
||||||
|
|
||||||
|
: body-length-bias ( word -- n )
|
||||||
|
[ flat-length ] [ inlining-count get at 0 or 2/ 1+ ] bi *
|
||||||
|
24 swap [-] 4 /i ;
|
||||||
|
|
||||||
: inlining-rank ( #call word -- n )
|
: inlining-rank ( #call word -- n )
|
||||||
[ classes-known? 2 0 ? ]
|
[ classes-known? 2 0 ? ]
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
[ drop node-count get 45 swap [-] 8 /i ]
|
[ body-length-bias ]
|
||||||
[ flat-length 24 swap [-] 4 /i ]
|
|
||||||
[ "default" word-prop -4 0 ? ]
|
[ "default" word-prop -4 0 ? ]
|
||||||
[ "specializer" word-prop 1 0 ? ]
|
[ "specializer" word-prop 1 0 ? ]
|
||||||
[ method-body? 1 0 ? ]
|
[ method-body? 1 0 ? ]
|
||||||
} cleave
|
} cleave
|
||||||
] bi* + + + + + ;
|
node-count-bias
|
||||||
|
loop-nesting get 0 or 2 *
|
||||||
|
] bi* + + + + + + ;
|
||||||
|
|
||||||
: should-inline? ( #call word -- ? )
|
: should-inline? ( #call word -- ? )
|
||||||
dup "inline" word-prop [ 2drop t ] [ inlining-rank 5 >= ] if ;
|
dup "inline" word-prop [ 2drop t ] [ inlining-rank 5 >= ] if ;
|
||||||
|
@ -138,12 +150,12 @@ DEFER: (flat-length)
|
||||||
SYMBOL: history
|
SYMBOL: history
|
||||||
|
|
||||||
: remember-inlining ( word -- )
|
: remember-inlining ( word -- )
|
||||||
history [ swap suffix ] change ;
|
[ [ 1 ] dip inlining-count get at+ ]
|
||||||
|
[ history [ swap suffix ] change ]
|
||||||
|
bi ;
|
||||||
|
|
||||||
: inline-word-def ( #call word quot -- ? )
|
: inline-word-def ( #call word quot -- ? )
|
||||||
over history get memq? [
|
over history get memq? [ 3drop f ] [
|
||||||
3drop f
|
|
||||||
] [
|
|
||||||
[
|
[
|
||||||
swap remember-inlining
|
swap remember-inlining
|
||||||
dupd splicing-nodes >>body
|
dupd splicing-nodes >>body
|
||||||
|
|
|
@ -6,6 +6,8 @@ compiler.tree.propagation.copy
|
||||||
compiler.tree.propagation.info ;
|
compiler.tree.propagation.info ;
|
||||||
IN: compiler.tree.propagation.nodes
|
IN: compiler.tree.propagation.nodes
|
||||||
|
|
||||||
|
SYMBOL: loop-nesting
|
||||||
|
|
||||||
GENERIC: propagate-before ( node -- )
|
GENERIC: propagate-before ( node -- )
|
||||||
|
|
||||||
GENERIC: propagate-after ( node -- )
|
GENERIC: propagate-after ( node -- )
|
||||||
|
|
|
@ -19,5 +19,6 @@ IN: compiler.tree.propagation
|
||||||
H{ } clone copies set
|
H{ } clone copies set
|
||||||
H{ } clone 1array value-infos set
|
H{ } clone 1array value-infos set
|
||||||
H{ } clone 1array constraints set
|
H{ } clone 1array constraints set
|
||||||
|
H{ } clone inlining-count set
|
||||||
dup count-nodes
|
dup count-nodes
|
||||||
dup (propagate) ;
|
dup (propagate) ;
|
||||||
|
|
|
@ -55,6 +55,8 @@ IN: compiler.tree.propagation.recursive
|
||||||
M: #recursive propagate-around ( #recursive -- )
|
M: #recursive propagate-around ( #recursive -- )
|
||||||
constraints [ H{ } clone suffix ] change
|
constraints [ H{ } clone suffix ] change
|
||||||
[
|
[
|
||||||
|
loop-nesting inc
|
||||||
|
|
||||||
constraints [ but-last H{ } clone suffix ] change
|
constraints [ but-last H{ } clone suffix ] change
|
||||||
|
|
||||||
child>>
|
child>>
|
||||||
|
@ -62,6 +64,8 @@ M: #recursive propagate-around ( #recursive -- )
|
||||||
[ first propagate-recursive-phi ]
|
[ first propagate-recursive-phi ]
|
||||||
[ (propagate) ]
|
[ (propagate) ]
|
||||||
tri
|
tri
|
||||||
|
|
||||||
|
loop-nesting dec
|
||||||
] until-fixed-point ;
|
] until-fixed-point ;
|
||||||
|
|
||||||
: recursive-phi-infos ( node -- infos )
|
: recursive-phi-infos ( node -- infos )
|
||||||
|
|
Loading…
Reference in New Issue