M: ##set-slot-imm insn-object obj>> resolve ;
M: ##alien-global insn-object drop \ ##alien-global ;
-: init-alias-analysis ( basic-block -- )
+: init-alias-analysis ( live-in -- )
H{ } clone histories set
H{ } clone vregs>acs set
H{ } clone acs>vregs set
H{ } clone constants set
H{ } clone copies set
- live-in keys [ set-heap-ac ] each
+ [ set-heap-ac ] each
0 ac-counter set
next-ac heap-ac set ;
: eliminate-dead-stores ( insns -- insns' )
[ insn# set eliminate-dead-stores* ] map-index sift ;
-: alias-analysis-step ( basic-block -- )
- dup init-alias-analysis
- [
- analyze-aliases
- compute-live-stores
- eliminate-dead-stores
- ] change-instructions drop ;
+: alias-analysis-step ( insns -- insns' )
+ analyze-aliases
+ compute-live-stores
+ eliminate-dead-stores ;
: alias-analysis ( rpo -- )
- [ alias-analysis-step ] each ;
\ No newline at end of file
+ [ init-alias-analysis ] [ alias-analysis-step ] local-optimization ;
\ No newline at end of file
: height-step ( insns -- insns' )
0 ds-height set
0 rs-height set
- [
- [ [ compute-heights ] each ]
- [ [ [ normalize-height* ] map sift ] with-scope ] bi
- ds-height get dup zero? [ drop ] [ f \ ##inc-d boa prefix ] if
- rs-height get dup zero? [ drop ] [ f \ ##inc-r boa prefix ] if
- ] change-instructions drop ;
+ [ [ compute-heights ] each ]
+ [ [ [ normalize-height* ] map sift ] with-scope ] bi
+ ds-height get dup zero? [ drop ] [ f \ ##inc-d boa prefix ] if
+ rs-height get dup zero? [ drop ] [ f \ ##inc-r boa prefix ] if ;
: normalize-height ( rpo -- )
- [ height-step ] each ;
+ [ ] [ height-step ] local-optimization ;
! Copyright (C) 2009 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
-USING: kernel namespaces deques accessors sets sequences assocs fry dlists
-compiler.cfg.def-use compiler.cfg.rpo ;
+USING: kernel namespaces deques accessors sets sequences assocs fry
+dlists compiler.cfg.def-use ;
IN: compiler.cfg.liveness
! This is a backward dataflow analysis. See http://en.wikipedia.org/wiki/Liveness_analysis
! Copyright (C) 2008, 2009 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
USING: kernel accessors namespaces make math sequences sets
-assocs fry compiler.cfg compiler.cfg.instructions ;
+assocs fry compiler.cfg compiler.cfg.instructions
+compiler.cfg.liveness ;
IN: compiler.cfg.rpo
SYMBOL: visited
: each-basic-block ( cfg quot -- )
[ reverse-post-order ] dip each ; inline
+
+: optimize-basic-block ( bb init-quot insn-quot -- )
+ [ '[ live-in keys _ each ] ] [ '[ _ change-instructions drop ] ] bi* bi ; inline
+
+: local-optimization ( rpo init-quot: ( live-in -- ) insn-quot: ( insns -- insns' ) -- )
+ '[ _ _ optimize-basic-block ] each ;
\ No newline at end of file
! See http://factorcode.org/license.txt for BSD license.
USING: namespaces assocs biassocs classes kernel math accessors
sorting sets sequences
-compiler.cfg.liveness
+compiler.cfg.rpo
compiler.cfg.value-numbering.graph
compiler.cfg.value-numbering.expressions
compiler.cfg.value-numbering.propagate
compiler.cfg.value-numbering.rewrite ;
IN: compiler.cfg.value-numbering
-: number-input-values ( basic-block -- )
- live-in keys [ [ next-input-expr ] dip set-vn ] each ;
+: number-input-values ( live-in -- )
+ [ [ f next-input-expr ] dip set-vn ] each ;
-: value-numbering-step ( basic-block -- )
+: init-value-numbering ( live-in -- )
init-value-graph
init-expressions
- dup number-input-values
- [ [ [ number-values ] [ rewrite propagate ] bi ] map ] change-instructions drop ;
+ number-input-values ;
+
+: value-numbering-step ( insns -- insns' )
+ [ [ number-values ] [ rewrite propagate ] bi ] map ;
: value-numbering ( rpo -- )
- [ value-numbering-step ] each ;
+ [ init-value-numbering ] [ value-numbering-step ] local-optimization ;
! Copyright (C) 2008, 2009 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
USING: kernel accessors namespaces assocs sets sequences locals
-compiler.cfg compiler.cfg.instructions compiler.cfg.copy-prop ;
+compiler.cfg compiler.cfg.instructions compiler.cfg.copy-prop
+compiler.cfg.rpo ;
IN: compiler.cfg.write-barrier
! Eliminate redundant write barrier hits.
M: insn eliminate-write-barrier ;
-: write-barriers-step ( basic-block -- )
+: write-barriers-step ( insns -- insns' )
H{ } clone safe set
H{ } clone mutated set
H{ } clone copies set
- [ [ eliminate-write-barrier ] map sift ] change-instructions drop ;
+ [ eliminate-write-barrier ] map sift ;
: eliminate-write-barriers ( rpo -- )
- [ write-barriers-step ] each ;
+ [ ] [ write-barriers-step ] local-optimization ;