compiler.cfg.gvn.testing: clean stuff up; get full, proper graphviz output

db4
Alex Vondrak 2011-06-09 12:08:25 -07:00 committed by John Benediktsson
parent 6c09bd0cd5
commit b64d116582
3 changed files with 46 additions and 43 deletions

View File

@ -59,6 +59,9 @@ IN: compiler.cfg.graphviz
[ number>string png ] [ number>string png ]
tri* ; tri* ;
SYMBOL: passes
\ optimize-cfg def>> passes set
: watch-pass ( cfg pass pass# -- cfg' ) : watch-pass ( cfg pass pass# -- cfg' )
[ perform-pass ] 2keep draw-cfg ; [ perform-pass ] 2keep draw-cfg ;
@ -66,11 +69,11 @@ IN: compiler.cfg.graphviz
\ build-cfg 0 draw-cfg ; \ build-cfg 0 draw-cfg ;
: watch-passes ( cfg -- cfg' ) : watch-passes ( cfg -- cfg' )
\ optimize-cfg def>> [ 1 + watch-pass ] each-index ; passes get [ 1 + watch-pass ] each-index ;
: finish-watching-passes ( cfg -- ) : finish-watching-passes ( cfg -- )
\ finalize-cfg \ finalize-cfg
\ optimize-cfg def>> length 1 + passes get length 1 +
watch-pass drop ; watch-pass drop ;
: watch-cfg ( path cfg -- ) : watch-cfg ( path cfg -- )

View File

@ -75,12 +75,15 @@ M: array process-instruction
! won't be sound ! won't be sound
dup [ process-instruction drop ] each ; dup [ process-instruction drop ] each ;
: value-numbering-iteration ( cfg -- )
[ value-numbering-step ] simple-optimization ;
: value-numbering ( cfg -- cfg ) : value-numbering ( cfg -- cfg )
dup dup
init-gvn init-gvn
'[ '[
changed? off changed? off
_ [ value-numbering-step ] simple-optimization _ value-numbering-iteration
changed? get changed? get
] loop ] loop

View File

@ -1,17 +1,11 @@
! Copyright (C) 2011 Alex Vondrak. See ! Copyright (C) 2011 Alex Vondrak. See
! http://factorcode.org/license.txt for BSD license. ! http://factorcode.org/license.txt for BSD license.
USING: accessors assocs compiler.cfg USING: accessors assocs compiler.cfg compiler.cfg.graphviz
compiler.cfg.alias-analysis compiler.cfg.block-joining
compiler.cfg.branch-splitting compiler.cfg.copy-prop
compiler.cfg.dce compiler.cfg.debugger
compiler.cfg.finalization compiler.cfg.graphviz
compiler.cfg.gvn compiler.cfg.gvn.expressions compiler.cfg.gvn compiler.cfg.gvn.expressions
compiler.cfg.gvn.graph compiler.cfg.height compiler.cfg.gvn.graph compiler.cfg.optimizer continuations
compiler.cfg.ssa.construction compiler.cfg.tco formatting graphviz graphviz.notation graphviz.render
compiler.cfg.useless-conditionals formatting fry graphviz io.directories kernel math.parser namespaces prettyprint
graphviz.notation graphviz.render io kernel math math.parser sequences sorting splitting tools.annotations ;
math.private namespaces prettyprint sequences sorting strings
tools.annotations ;
IN: compiler.cfg.gvn.testing IN: compiler.cfg.gvn.testing
GENERIC: expr>str ( expr -- str ) GENERIC: expr>str ( expr -- str )
@ -46,19 +40,6 @@ M: object expr>str [ unparse ] map " " join ;
"<%d> : {%s}\\l" sprintf "<%d> : {%s}\\l" sprintf
] map "" concat-as ; ] map "" concat-as ;
SYMBOL: gvn-test
[ 0 100 [ 1 fixnum+fast ] times ]
test-builder first [
optimize-tail-calls
delete-useless-conditionals
split-branches
join-blocks
normalize-height
construct-ssa
alias-analysis
] with-cfg gvn-test set-global
: basic-block# ( -- n ) : basic-block# ( -- n )
basic-block get number>> ; basic-block get number>> ;
@ -75,25 +56,41 @@ test-builder first [
basic-block# add-node[ "bold" =style ]; basic-block# add-node[ "bold" =style ];
add ; add ;
: draw-annotated-cfg ( -- ) SYMBOL: iteration
cfg get cfgviz add-gvns add-lvns
basic-block# number>string "bb" prepend png ;
: watch-gvn ( -- ) : iteration-dir ( -- path )
iteration get number>string "gvn-iter" prepend ;
: new-iteration ( -- )
iteration inc iteration-dir make-directories ;
: draw-annotated-cfg ( -- )
iteration-dir [
cfg get cfgviz add-gvns add-lvns
basic-block# number>string "bb" prepend png
] with-directory ;
: annotate-gvn ( -- )
\ value-numbering-iteration
[ [ new-iteration ] prepend ] annotate
\ value-numbering-step \ value-numbering-step
[ '[ _ call draw-annotated-cfg ] ] annotate ; [ [ draw-annotated-cfg ] append ] annotate ;
: reset-gvn ( -- ) : reset-gvn ( -- )
\ value-numbering-iteration reset
\ value-numbering-step reset ; \ value-numbering-step reset ;
: test-gvn ( -- ) ! Replace compiler.cfg.value-numbering:value-numbering with
watch-gvn ! compiler.cfg.gvn:value-numbering
gvn-test get-global [
{ : gvn-passes ( -- passes )
value-numbering \ optimize-cfg def>> [
copy-propagation name>> "value-numbering" =
eliminate-dead-code ] split-when [ value-numbering ] join ;
finalize-cfg
} [ watch-pass ] each-index drop : watch-gvn ( path quot -- )
] with-cfg annotate-gvn [
reset-gvn ; gvn-passes passes [
0 iteration [ watch-optimizer* ] with-variable
] with-variable
] [ reset-gvn ] [ ] cleanup ;