Branch hoisting work in progress
parent
6de8c722a5
commit
d58dfd1b2d
|
@ -1,7 +1,7 @@
|
||||||
IN: temporary
|
IN: temporary
|
||||||
USING: compiler tools.test namespaces sequences
|
USING: compiler tools.test namespaces sequences
|
||||||
kernel.private kernel math continuations continuations.private
|
kernel.private kernel math continuations continuations.private
|
||||||
words splitting ;
|
words splitting sorting ;
|
||||||
|
|
||||||
: symbolic-stack-trace ( -- newseq )
|
: symbolic-stack-trace ( -- newseq )
|
||||||
error-continuation get continuation-call callstack>array
|
error-continuation get continuation-call callstack>array
|
||||||
|
@ -31,9 +31,9 @@ words splitting ;
|
||||||
\ > stack-trace-contains?
|
\ > stack-trace-contains?
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
||||||
: quux [ t [ "hi" throw ] when ] times ;
|
: quux { 1 2 3 } [ "hi" throw ] sort ;
|
||||||
|
|
||||||
[ t ] [
|
[ t ] [
|
||||||
[ 10 quux ] ignore-errors
|
[ 10 quux ] ignore-errors
|
||||||
\ (each-integer) stack-trace-contains?
|
\ sort stack-trace-contains?
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
|
@ -44,7 +44,9 @@ words kernel math effects definitions compiler.units ;
|
||||||
[
|
[
|
||||||
[ ] [ init-templates ] unit-test
|
[ ] [ init-templates ] unit-test
|
||||||
|
|
||||||
[ ] [ init-generator ] unit-test
|
H{ } clone compiled set
|
||||||
|
|
||||||
|
[ ] [ gensym gensym begin-compiling ] unit-test
|
||||||
|
|
||||||
[ t ] [ [ end-basic-block ] { } make empty? ] unit-test
|
[ t ] [ [ end-basic-block ] { } make empty? ] unit-test
|
||||||
|
|
||||||
|
|
|
@ -176,23 +176,71 @@ M: node remember-method*
|
||||||
} cond
|
} cond
|
||||||
] if ;
|
] if ;
|
||||||
|
|
||||||
M: #if optimize-node*
|
: fold-if-branch? dup node-in-d first known-boolean-value? ;
|
||||||
dup dup node-in-d first known-boolean-value? [
|
|
||||||
|
: fold-if-branch ( node value -- node' )
|
||||||
over drop-inputs >r
|
over drop-inputs >r
|
||||||
0 1 ? fold-branch
|
0 1 ? fold-branch
|
||||||
r> [ set-node-successor ] keep
|
r> [ set-node-successor ] keep ;
|
||||||
t
|
|
||||||
] [ 2drop t f ] if ;
|
: only-one ( seq -- elt/f )
|
||||||
|
dup length 1 = [ first ] [ drop f ] if ;
|
||||||
|
|
||||||
|
: lift-throw-tail? ( #if -- tail/? )
|
||||||
|
dup node-successor node-successor
|
||||||
|
[ active-children only-one ] [ drop f ] if ;
|
||||||
|
|
||||||
|
: clone-node ( node -- newnode )
|
||||||
|
clone dup [ clone ] modify-values ;
|
||||||
|
|
||||||
|
: lift-branch ( #if node -- )
|
||||||
|
over last-node clone-node -rot
|
||||||
|
>r dup node-successor r> substitute-node
|
||||||
|
set-node-successor ;
|
||||||
|
|
||||||
|
M: #if optimize-node*
|
||||||
|
dup fold-if-branch? [ fold-if-branch t ] [
|
||||||
|
drop dup lift-throw-tail? dup [
|
||||||
|
dupd lift-branch t
|
||||||
|
] [
|
||||||
|
2drop t f
|
||||||
|
] if
|
||||||
|
] if ;
|
||||||
|
|
||||||
|
: fold-dispatch-branch? dup node-in-d first tuck node-literal? ;
|
||||||
|
|
||||||
|
: fold-dispatch-branch ( node value -- node' )
|
||||||
|
dupd node-literal
|
||||||
|
over drop-inputs >r fold-branch r>
|
||||||
|
[ set-node-successor ] keep ;
|
||||||
|
|
||||||
M: #dispatch optimize-node*
|
M: #dispatch optimize-node*
|
||||||
dup dup node-in-d first 2dup node-literal? [
|
dup fold-dispatch-branch? [
|
||||||
"Optimizing #dispatch" print
|
fold-dispatch-branch t
|
||||||
node-literal
|
|
||||||
over drop-inputs >r fold-branch r> [ set-node-successor ] keep t
|
|
||||||
] [
|
] [
|
||||||
3drop t f
|
2drop t f
|
||||||
] if ;
|
] if ;
|
||||||
|
|
||||||
|
! #loop
|
||||||
|
: lift-loop-tail? ( #label -- tail/f )
|
||||||
|
dup node-child dup #if? [
|
||||||
|
node-children
|
||||||
|
[ penultimate-node ] map
|
||||||
|
[
|
||||||
|
dup #call-label?
|
||||||
|
[ node-param eq? not ] [ 2drop t ] if
|
||||||
|
] with subset only-one
|
||||||
|
] [
|
||||||
|
2drop f
|
||||||
|
] if ;
|
||||||
|
|
||||||
|
! M: #loop optimize-node*
|
||||||
|
! dup lift-loop-tail? dup [
|
||||||
|
! over node-child swap lift-branch t
|
||||||
|
! ] [
|
||||||
|
! 2drop t f
|
||||||
|
! ] if ;
|
||||||
|
|
||||||
! #call
|
! #call
|
||||||
: splice-method ( #call method-spec/t quot/t -- node/t )
|
: splice-method ( #call method-spec/t quot/t -- node/t )
|
||||||
#! t indicates failure
|
#! t indicates failure
|
||||||
|
|
|
@ -70,20 +70,6 @@ M: #branch node-def-use
|
||||||
#! #values node.
|
#! #values node.
|
||||||
dup branch-def-use (node-def-use) ;
|
dup branch-def-use (node-def-use) ;
|
||||||
|
|
||||||
! : dead-literals ( -- values )
|
|
||||||
! def-use get [ >r value? r> empty? and ] assoc-subset ;
|
|
||||||
!
|
|
||||||
! : kill-node* ( node values -- )
|
|
||||||
! [ swap remove-all ] curry modify-values ;
|
|
||||||
!
|
|
||||||
! : kill-node ( node values -- )
|
|
||||||
! dup assoc-empty?
|
|
||||||
! [ 2drop ] [ [ kill-node* ] curry each-node ] if ;
|
|
||||||
!
|
|
||||||
! : kill-values ( node -- )
|
|
||||||
! #! Remove literals which are not actually used anywhere.
|
|
||||||
! dead-literals kill-node ;
|
|
||||||
|
|
||||||
: compute-dead-literals ( -- values )
|
: compute-dead-literals ( -- values )
|
||||||
def-use get [ >r value? r> empty? and ] assoc-subset ;
|
def-use get [ >r value? r> empty? and ] assoc-subset ;
|
||||||
|
|
||||||
|
@ -129,8 +115,6 @@ M: #r> kill-node* [ node-in-r empty? ] prune-if ;
|
||||||
dead-literals [ kill-nodes ] with-variable
|
dead-literals [ kill-nodes ] with-variable
|
||||||
] if ;
|
] if ;
|
||||||
|
|
||||||
!
|
|
||||||
|
|
||||||
: sole-consumer ( #call -- node/f )
|
: sole-consumer ( #call -- node/f )
|
||||||
node-out-d first used-by
|
node-out-d first used-by
|
||||||
dup length 1 = [ first ] [ drop f ] if ;
|
dup length 1 = [ first ] [ drop f ] if ;
|
||||||
|
|
|
@ -24,7 +24,7 @@ IN: optimizer.specializers
|
||||||
\ dispatch ,
|
\ dispatch ,
|
||||||
] [ ] make ;
|
] [ ] make ;
|
||||||
|
|
||||||
: specializer-methods ( word -- alist )
|
: specializer-methods ( quot word -- default alist )
|
||||||
dup [ array? ] all? [ 1array ] unless [
|
dup [ array? ] all? [ 1array ] unless [
|
||||||
[ make-specializer ] keep
|
[ make-specializer ] keep
|
||||||
[ declare ] curry pick append
|
[ declare ] curry pick append
|
||||||
|
|
Loading…
Reference in New Issue