Working on optimizer

release
slava 2006-03-04 07:53:22 +00:00
parent fd1db437a5
commit b8bcdc8909
10 changed files with 19 additions and 22 deletions

View File

@ -54,7 +54,7 @@
- code gc - code gc
- compiled gc check slows things down - compiled gc check slows things down
- fix branch folding - fix branch folding
- remove branch splitting - new x86 write barrier
+ misc: + misc:

View File

@ -133,7 +133,6 @@ vectors words ;
"/library/compiler/xt.factor" "/library/compiler/xt.factor"
"/library/compiler/stack.factor" "/library/compiler/stack.factor"
"/library/compiler/intrinsics.factor" "/library/compiler/intrinsics.factor"
"/library/compiler/basic-blocks.factor"
"/library/compiler/generator.factor" "/library/compiler/generator.factor"
"/library/compiler/compiler.factor" "/library/compiler/compiler.factor"

View File

@ -7,7 +7,7 @@ sequences words ;
: (compile) ( word -- ) : (compile) ( word -- )
#! Should be called inside the with-compiler scope. #! Should be called inside the with-compiler scope.
dup word-def dataflow optimize linearize dup word-def dataflow optimize linearize
[ split-blocks simplify generate ] hash-each ; [ generate ] hash-each ;
: inform-compile ( word -- ) "Compiling " write . flush ; : inform-compile ( word -- ) "Compiling " write . flush ;
@ -47,8 +47,6 @@ sequences words ;
] if ; ] if ;
\ dataflow profile \ dataflow profile
\ optimize profile
\ linearize profile \ linearize profile
\ split-blocks profile
\ simplify profile
\ generate profile \ generate profile
\ optimize profile

View File

@ -12,14 +12,13 @@ GENERIC: generate-node ( vop -- )
#! The %prologue node contains the maximum stack reserve of #! The %prologue node contains the maximum stack reserve of
#! all VOPs. The precise meaning of stack reserve is #! all VOPs. The precise meaning of stack reserve is
#! platform-specific. #! platform-specific.
0 [ 0 [ stack-reserve max ] reduce max ] reduce 0 [ stack-reserve max ] reduce \ stack-reserve set ;
\ stack-reserve set ;
: generate-code ( word linear -- length ) : generate-code ( word linear -- length )
compiled-offset >r compiled-offset >r
compile-aligned compile-aligned
swap save-xt swap save-xt
[ [ dup [ generate-node ] with-vop ] each ] each [ dup [ generate-node ] with-vop ] each
compile-aligned compile-aligned
compiled-offset r> - ; compiled-offset r> - ;

View File

@ -80,15 +80,15 @@ M: #label linearize* ( node -- next )
dup node-successor #if? dup node-successor #if?
[ node-param "if-intrinsic" word-prop ] [ drop f ] if ; [ node-param "if-intrinsic" word-prop ] [ drop f ] if ;
: linearize-if ( node label -- next ) : linearize-if ( node label -- )
<label> dup >r >r >r node-children first2 linearize-child <label> dup >r >r >r node-children first2 linearize-child
r> r> %jump-label , %label , linearize-child r> %label , r> r> %jump-label , %label , linearize-child r> %label ,
iterate-next ; iterate-next ;
M: #call linearize* ( node -- ) M: #call linearize* ( node -- next )
dup if-intrinsic [ dup if-intrinsic [
>r <label> 2dup r> call >r <label> 2dup r> call
>r node-successor r> linearize-if >r node-successor r> linearize-if node-successor
] [ ] [
dup intrinsic dup intrinsic
[ call iterate-next ] [ node-param linearize-call ] if* [ call iterate-next ] [ node-param linearize-call ] if*

View File

@ -63,7 +63,7 @@ C: #label make-node ;
TUPLE: #entry ; TUPLE: #entry ;
C: #entry make-node ; C: #entry make-node ;
: #entry ( -- node ) f param-node <#entry> ; : #entry ( -- node ) meta-d get clone in-node <#entry> ;
TUPLE: #call ; TUPLE: #call ;
C: #call make-node ; C: #call make-node ;

View File

@ -75,8 +75,8 @@ M: #killable live-values* ( node -- seq ) drop { } ;
! #label ! #label
M: #label live-values* ( node -- seq ) M: #label live-values* ( node -- seq )
dup node-child node-in-d dup node-child [ node-in-d ] 2apply 2array
>r collect-recursion r> add purge-invariants ; purge-invariants ;
! branching ! branching
UNION: #branch #if #dispatch ; UNION: #branch #if #dispatch ;

View File

@ -35,8 +35,8 @@ sequences strings vectors words prettyprint ;
dup "infer-effect" word-prop consume/produce dup "infer-effect" word-prop consume/produce
[ [ t ] [ f ] if ] infer-quot ; [ [ t ] [ f ] if ] infer-quot ;
{ fixnum<= fixnum< fixnum>= fixnum> eq? } ! { fixnum<= fixnum< fixnum>= fixnum> eq? }
[ dup [ manual-branch ] curry "infer" set-word-prop ] each ! [ dup [ manual-branch ] curry "infer" set-word-prop ] each
! Primitive combinators ! Primitive combinators
\ call [ [ general-list ] [ ] ] "infer-effect" set-word-prop \ call [ [ general-list ] [ ] ] "infer-effect" set-word-prop

View File

@ -1,7 +1,7 @@
! Copyright (C) 2004, 2006 Slava Pestov. ! Copyright (C) 2004, 2006 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
IN: optimizer IN: optimizer
USING: compiler-backend generic hashtables inference kernel USING: compiler-backend generic hashtables inference io kernel
lists math namespaces sequences vectors ; lists math namespaces sequences vectors ;
GENERIC: optimize-node* ( node -- node/t ) GENERIC: optimize-node* ( node -- node/t )
@ -25,11 +25,12 @@ DEFER: optimize-node
over set-node-successor r> r> r> or or over set-node-successor r> r> r> or or
] [ r> ] if ; ] [ r> ] if ;
: optimize-1 ( dataflow -- dataflow ? ) : (optimize) ( dataflow n -- dataflow n ? )
dup kill-values dup infer-classes optimize-node ; >r dup kill-values dup infer-classes optimize-node r> swap
[ 1+ (optimize) ] when ;
: optimize ( dataflow -- dataflow ) : optimize ( dataflow -- dataflow )
[ optimize-1 ] with-scope [ optimize ] when ; 1 (optimize) [ "! Optimizer passes: " % # ] "" make print ;
: prune-if ( node quot -- successor/t ) : prune-if ( node quot -- successor/t )
over >r call [ r> node-successor ] [ r> drop t ] if ; over >r call [ r> node-successor ] [ r> drop t ] if ;

View File

@ -97,7 +97,7 @@ M: #call-label collect-recursion* ( label node -- )
dup f inline-block over recursive-label? [ dup f inline-block over recursive-label? [
meta-d get >r meta-d get >r
drop join-values f inline-block apply-infer drop join-values f inline-block apply-infer
r> over node-child set-node-in-d node, r> over set-node-in-d node,
] [ ] [
apply-infer node-child node-successor splice-node drop apply-infer node-child node-successor splice-node drop
] if ; ] if ;