Minor performance improvements in optimizer
parent
72fe1b6134
commit
63703c2713
|
@ -4,7 +4,7 @@ USING: compiler generic help io io-internals kernel
|
||||||
kernel-internals lists math memory namespaces optimizer parser
|
kernel-internals lists math memory namespaces optimizer parser
|
||||||
sequences sequences-internals words ;
|
sequences sequences-internals words ;
|
||||||
|
|
||||||
"Cross-referencing..." print
|
"Cross-referencing..." print flush
|
||||||
H{ } clone crossref set-global xref-words
|
H{ } clone crossref set-global xref-words
|
||||||
H{ } clone help-graph set-global xref-articles
|
H{ } clone help-graph set-global xref-articles
|
||||||
|
|
||||||
|
@ -13,8 +13,8 @@ H{ } clone help-graph set-global xref-articles
|
||||||
unix? [
|
unix? [
|
||||||
"/library/unix/load.factor" run-resource
|
"/library/unix/load.factor" run-resource
|
||||||
] when
|
] when
|
||||||
|
|
||||||
] when
|
] when
|
||||||
|
|
||||||
windows? [
|
windows? [
|
||||||
"/library/windows/load.factor" run-resource
|
"/library/windows/load.factor" run-resource
|
||||||
] when
|
] when
|
||||||
|
|
|
@ -5,9 +5,7 @@ USING: errors hashtables inference io kernel lists math
|
||||||
namespaces optimizer prettyprint sequences test words ;
|
namespaces optimizer prettyprint sequences test words ;
|
||||||
|
|
||||||
: (compile) ( word -- )
|
: (compile) ( word -- )
|
||||||
[
|
dup specialized-def dataflow optimize generate ;
|
||||||
[ dup specialized-def dataflow optimize generate ] keep
|
|
||||||
] benchmark nip "compile-time" set-word-prop ;
|
|
||||||
|
|
||||||
: inform-compile ( word -- ) "Compiling " write . flush ;
|
: inform-compile ( word -- ) "Compiling " write . flush ;
|
||||||
|
|
||||||
|
|
|
@ -36,17 +36,17 @@ math math-internals sequences words ;
|
||||||
[ with-datastack ] catch
|
[ with-datastack ] catch
|
||||||
[ 3drop t ] [ inline-literals ] if ;
|
[ 3drop t ] [ inline-literals ] if ;
|
||||||
|
|
||||||
: flip-subst ( not -- )
|
: call>no-op ( not -- )
|
||||||
#! Note: cloning the vectors, since subst-values will modify
|
#! Note: cloning the vectors, since subst-values will modify
|
||||||
#! them.
|
#! them.
|
||||||
[ node-in-d clone ] keep
|
[ node-in-d clone ] keep
|
||||||
[ node-out-d clone ] keep
|
[ node-out-d clone ] keep
|
||||||
subst-values ;
|
[ subst-values ] keep node-successor ;
|
||||||
|
|
||||||
: flip-branches ( not -- #if )
|
: flip-branches ( not -- #if )
|
||||||
#! If a not is followed by an #if, flip branches and
|
#! If a not is followed by an #if, flip branches and
|
||||||
#! remove the not.
|
#! remove the not.
|
||||||
dup flip-subst node-successor dup
|
call>no-op dup
|
||||||
dup node-children reverse swap set-node-children ;
|
dup node-children reverse swap set-node-children ;
|
||||||
|
|
||||||
\ not {
|
\ not {
|
||||||
|
@ -66,9 +66,6 @@ math math-internals sequences words ;
|
||||||
dup 0 node-class#
|
dup 0 node-class#
|
||||||
swap node-param "infer-effect" word-prop second first eq? ;
|
swap node-param "infer-effect" word-prop second first eq? ;
|
||||||
|
|
||||||
: call>no-op ( node -- node )
|
|
||||||
[ ] dataflow [ subst-node ] keep ;
|
|
||||||
|
|
||||||
{ >fixnum >bignum >float } [
|
{ >fixnum >bignum >float } [
|
||||||
{
|
{
|
||||||
{ [ dup useless-coerce? ] [ call>no-op ] }
|
{ [ dup useless-coerce? ] [ call>no-op ] }
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
! Copyright (C) 2004, 2005 Slava Pestov.
|
! Copyright (C) 2004, 2006 Slava Pestov.
|
||||||
! See http://factor.sf.net/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
IN: optimizer
|
IN: optimizer
|
||||||
USING: arrays generic hashtables inference kernel
|
USING: arrays generic hashtables inference kernel
|
||||||
kernel-internals math namespaces sequences words ;
|
kernel-internals math namespaces sequences words ;
|
||||||
|
@ -166,10 +166,20 @@ DEFER: (infer-classes)
|
||||||
node-successor (infer-classes)
|
node-successor (infer-classes)
|
||||||
] when* ;
|
] when* ;
|
||||||
|
|
||||||
: infer-classes ( node -- )
|
: ?<hashtable> [ H{ } clone ] unless* ;
|
||||||
|
|
||||||
|
: infer-classes-with ( node classes literals -- )
|
||||||
[
|
[
|
||||||
H{ } clone value-classes set
|
?<hashtable> value-literals set
|
||||||
H{ } clone value-literals set
|
?<hashtable> value-classes set
|
||||||
H{ } clone ties set
|
H{ } clone ties set
|
||||||
(infer-classes)
|
(infer-classes)
|
||||||
] with-scope ;
|
] with-scope ;
|
||||||
|
|
||||||
|
: infer-classes ( node -- )
|
||||||
|
f f infer-classes-with ;
|
||||||
|
|
||||||
|
: infer-classes/node ( existing node -- )
|
||||||
|
#! Infer classes, using the existing node's class info as a
|
||||||
|
#! starting point.
|
||||||
|
over node-classes rot node-literals infer-classes-with ;
|
||||||
|
|
|
@ -2,31 +2,49 @@
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
IN: optimizer
|
IN: optimizer
|
||||||
USING: arrays generic hashtables inference kernel
|
USING: arrays generic hashtables inference kernel
|
||||||
kernel-internals lists math namespaces sequences words ;
|
kernel-internals lists math namespaces prettyprint sequences
|
||||||
|
words ;
|
||||||
|
|
||||||
! Some utilities for splicing in dataflow IR subtrees
|
! Some utilities for splicing in dataflow IR subtrees
|
||||||
: post-inline ( #return/#values #call/#merge -- )
|
: post-inline ( #return/#values #call/#merge -- )
|
||||||
dup [
|
|
||||||
[
|
[
|
||||||
>r node-in-d r> node-out-d
|
>r node-in-d r> node-out-d 2array unify-lengths first2
|
||||||
2array unify-lengths first2
|
] keep subst-values ;
|
||||||
] keep subst-values
|
|
||||||
|
: ?hash-union ( hash/f hash -- hash )
|
||||||
|
over [ hash-union ] [ nip ] if ;
|
||||||
|
|
||||||
|
: add-node-literals ( hash node -- )
|
||||||
|
[ node-literals ?hash-union ] keep set-node-literals ;
|
||||||
|
|
||||||
|
: add-node-classes ( hash node -- )
|
||||||
|
[ node-classes ?hash-union ] keep set-node-classes ;
|
||||||
|
|
||||||
|
: (subst-classes) ( literals classes node -- )
|
||||||
|
dup [
|
||||||
|
3dup [ add-node-classes ] keep add-node-literals
|
||||||
|
node-successor (subst-classes)
|
||||||
] [
|
] [
|
||||||
2drop
|
3drop
|
||||||
] if ;
|
] if ;
|
||||||
|
|
||||||
|
: subst-classes ( #return/#values #call/#merge -- )
|
||||||
|
>r dup node-literals swap node-classes r> (subst-classes) ;
|
||||||
|
|
||||||
: subst-node ( old new -- )
|
: subst-node ( old new -- )
|
||||||
#! The last node of 'new' becomes 'old', then values are
|
#! The last node of 'new' becomes 'old', then values are
|
||||||
#! substituted. A subsequent optimizer phase kills the
|
#! substituted. A subsequent optimizer phase kills the
|
||||||
#! last node of 'new' and the first node of 'old'.
|
#! last node of 'new' and the first node of 'old'.
|
||||||
last-node 2dup swap post-inline set-node-successor ;
|
last-node 2dup swap 2dup post-inline subst-classes
|
||||||
|
set-node-successor ;
|
||||||
|
|
||||||
: (inline-method) ( #call quot -- node )
|
: (inline-method) ( #call quot -- node )
|
||||||
dup t eq? [
|
dup t eq? [
|
||||||
2drop t
|
2drop t
|
||||||
] [
|
] [
|
||||||
over node-in-d dataflow-with
|
over node-in-d dataflow-with
|
||||||
[ >r node-param r> remember-node ] 2keep
|
2dup infer-classes/node
|
||||||
|
over node-param over remember-node
|
||||||
[ subst-node ] keep
|
[ subst-node ] keep
|
||||||
] if ;
|
] if ;
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@ SYMBOL: optimizer-changed
|
||||||
GENERIC: optimize-node* ( node -- node/t )
|
GENERIC: optimize-node* ( node -- node/t )
|
||||||
|
|
||||||
: keep-optimizing ( node -- node ? )
|
: keep-optimizing ( node -- node ? )
|
||||||
dup optimize-node* dup t =
|
dup optimize-node* dup t eq?
|
||||||
[ drop f ] [ nip keep-optimizing t or ] if ;
|
[ drop f ] [ nip keep-optimizing t or ] if ;
|
||||||
|
|
||||||
: optimize-node ( node -- node )
|
: optimize-node ( node -- node )
|
||||||
|
|
Loading…
Reference in New Issue