compiler.cfg.gvn.redundancy-elimination: rough draft

db4
Alex Vondrak 2011-06-23 20:12:27 -07:00 committed by John Benediktsson
parent 454c2f245b
commit cb742f24d1
2 changed files with 61 additions and 0 deletions

View File

@ -0,0 +1 @@
Alex Vondrak

View File

@ -0,0 +1,60 @@
! Copyright (C) 2011 Alex Vondrak.
! See http://factorcode.org/license.txt for BSD license.
USING: ;
IN: compiler.cfg.gvn.redundancy-elimination
! ! ! Available expressions analysis
FORWARD-ANALYSIS: avail
M: avail-analysis transfer-set drop defined assoc-union ;
: available? ( vn -- ? )
basic-block get avail-ins get at key? ;
! ! ! Copy propagation
RENAMING: propagate [ vreg>avail-vn ] [ vreg>avail-vn ] [ drop next-vreg ]
! ! ! Redundancy elimination
! Returns f if insn should be removed
GENERIC: process-instruction ( insn -- insn'/f )
: redundant-instruction ( insn vn -- f ) 2drop f ; inline
: make-available ( vn -- )
dup basic-block get avail-ins get [ ?set-at ] change-at ;
:: useful-instruction ( insn expr -- insn' )
insn dst>> :> vn
vn make-available
insn propagate-insn-uses ! I think that's right?
insn ;
: check-redundancy ( insn -- insn'/f )
dup >expr dup exrs>vns get at
[ redundant-instruction ] [ useful-instruction ] ?if ;
: check-redundancy? ( insn -- ? )
defs-vregs {
[ length 1 = ]
[ first dup vreg>vn = not ] ! avoid ##copy x x
} 1&& ;
M: insn process-instruction
dup rewrite
[ process-instruction ]
[ dup check-redundancy? [ check-redundancy ] when ] ?if ;
M: ##copy process-instruction drop f ;
M: array process-instruction [ process-instruction ] map ;
: redundancy-elimination-step ( insns -- insns' )
[ process-instruction ] map flatten sift ;
: eliminate-redunancies ( cfg -- )
final-iteration? on ! if vreg>vn uses this to obey avail-ins
dup compute-avail-sets
[ redundancy-elimination-step ] simple-optimization ;