From 63703c271376ba023473524a71f155f2f3e14def Mon Sep 17 00:00:00 2001 From: slava Date: Wed, 10 May 2006 22:51:18 +0000 Subject: [PATCH] Minor performance improvements in optimizer --- library/bootstrap/boot-stage2.factor | 4 +-- library/compiler/compiler.factor | 4 +-- .../compiler/optimizer/call-optimizers.factor | 9 ++--- library/compiler/optimizer/class-infer.factor | 20 ++++++++--- .../compiler/optimizer/inline-methods.factor | 34 ++++++++++++++----- library/compiler/optimizer/optimizer.factor | 2 +- 6 files changed, 48 insertions(+), 25 deletions(-) diff --git a/library/bootstrap/boot-stage2.factor b/library/bootstrap/boot-stage2.factor index 09acfeaaae..7d5d4d7c4b 100644 --- a/library/bootstrap/boot-stage2.factor +++ b/library/bootstrap/boot-stage2.factor @@ -4,7 +4,7 @@ USING: compiler generic help io io-internals kernel kernel-internals lists math memory namespaces optimizer parser sequences sequences-internals words ; -"Cross-referencing..." print +"Cross-referencing..." print flush H{ } clone crossref set-global xref-words H{ } clone help-graph set-global xref-articles @@ -13,8 +13,8 @@ H{ } clone help-graph set-global xref-articles unix? [ "/library/unix/load.factor" run-resource ] when - ] when + windows? [ "/library/windows/load.factor" run-resource ] when diff --git a/library/compiler/compiler.factor b/library/compiler/compiler.factor index f89403be91..ad191cb707 100644 --- a/library/compiler/compiler.factor +++ b/library/compiler/compiler.factor @@ -5,9 +5,7 @@ USING: errors hashtables inference io kernel lists math namespaces optimizer prettyprint sequences test words ; : (compile) ( word -- ) - [ - [ dup specialized-def dataflow optimize generate ] keep - ] benchmark nip "compile-time" set-word-prop ; + dup specialized-def dataflow optimize generate ; : inform-compile ( word -- ) "Compiling " write . flush ; diff --git a/library/compiler/optimizer/call-optimizers.factor b/library/compiler/optimizer/call-optimizers.factor index 26dbf2632c..d98bc25bd4 100644 --- a/library/compiler/optimizer/call-optimizers.factor +++ b/library/compiler/optimizer/call-optimizers.factor @@ -36,17 +36,17 @@ math math-internals sequences words ; [ with-datastack ] catch [ 3drop t ] [ inline-literals ] if ; -: flip-subst ( not -- ) +: call>no-op ( not -- ) #! Note: cloning the vectors, since subst-values will modify #! them. [ node-in-d clone ] keep [ node-out-d clone ] keep - subst-values ; + [ subst-values ] keep node-successor ; : flip-branches ( not -- #if ) #! If a not is followed by an #if, flip branches and #! remove the not. - dup flip-subst node-successor dup + call>no-op dup dup node-children reverse swap set-node-children ; \ not { @@ -66,9 +66,6 @@ math math-internals sequences words ; dup 0 node-class# swap node-param "infer-effect" word-prop second first eq? ; -: call>no-op ( node -- node ) - [ ] dataflow [ subst-node ] keep ; - { >fixnum >bignum >float } [ { { [ dup useless-coerce? ] [ call>no-op ] } diff --git a/library/compiler/optimizer/class-infer.factor b/library/compiler/optimizer/class-infer.factor index 66dea6dd2d..444c34298c 100644 --- a/library/compiler/optimizer/class-infer.factor +++ b/library/compiler/optimizer/class-infer.factor @@ -1,5 +1,5 @@ -! Copyright (C) 2004, 2005 Slava Pestov. -! See http://factor.sf.net/license.txt for BSD license. +! Copyright (C) 2004, 2006 Slava Pestov. +! See http://factorcode.org/license.txt for BSD license. IN: optimizer USING: arrays generic hashtables inference kernel kernel-internals math namespaces sequences words ; @@ -166,10 +166,20 @@ DEFER: (infer-classes) node-successor (infer-classes) ] when* ; -: infer-classes ( node -- ) +: ? [ H{ } clone ] unless* ; + +: infer-classes-with ( node classes literals -- ) [ - H{ } clone value-classes set - H{ } clone value-literals set + ? value-literals set + ? value-classes set H{ } clone ties set (infer-classes) ] 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 ; diff --git a/library/compiler/optimizer/inline-methods.factor b/library/compiler/optimizer/inline-methods.factor index 44f6918b5d..23b60df922 100644 --- a/library/compiler/optimizer/inline-methods.factor +++ b/library/compiler/optimizer/inline-methods.factor @@ -2,31 +2,49 @@ ! See http://factorcode.org/license.txt for BSD license. IN: optimizer 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 : post-inline ( #return/#values #call/#merge -- ) + [ + >r node-in-d r> node-out-d 2array unify-lengths first2 + ] 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 [ - [ - >r node-in-d r> node-out-d - 2array unify-lengths first2 - ] keep subst-values + 3dup [ add-node-classes ] keep add-node-literals + node-successor (subst-classes) ] [ - 2drop + 3drop ] if ; +: subst-classes ( #return/#values #call/#merge -- ) + >r dup node-literals swap node-classes r> (subst-classes) ; + : subst-node ( old new -- ) #! The last node of 'new' becomes 'old', then values are #! substituted. A subsequent optimizer phase kills the #! 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 ) dup t eq? [ 2drop t ] [ 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 ] if ; diff --git a/library/compiler/optimizer/optimizer.factor b/library/compiler/optimizer/optimizer.factor index e8bdfec2a0..e738fa95a1 100644 --- a/library/compiler/optimizer/optimizer.factor +++ b/library/compiler/optimizer/optimizer.factor @@ -9,7 +9,7 @@ SYMBOL: optimizer-changed GENERIC: optimize-node* ( node -- node/t ) : keep-optimizing ( node -- node ? ) - dup optimize-node* dup t = + dup optimize-node* dup t eq? [ drop f ] [ nip keep-optimizing t or ] if ; : optimize-node ( node -- node )