compiler.cfg.gvn: experiment to scan for available vregs when rewriting
instructions instead of relying on the availability of the canonical leader; untesteddb4
parent
3ff0b1a1ec
commit
d58d467434
|
@ -7,6 +7,7 @@ compiler.cfg.dataflow-analysis
|
||||||
compiler.cfg.def-use
|
compiler.cfg.def-use
|
||||||
compiler.cfg.gvn.graph
|
compiler.cfg.gvn.graph
|
||||||
compiler.cfg.predecessors
|
compiler.cfg.predecessors
|
||||||
|
compiler.cfg.renaming.functor
|
||||||
compiler.cfg.rpo ;
|
compiler.cfg.rpo ;
|
||||||
FROM: assocs => change-at ;
|
FROM: assocs => change-at ;
|
||||||
FROM: namespaces => set ;
|
FROM: namespaces => set ;
|
||||||
|
@ -22,20 +23,23 @@ FORWARD-ANALYSIS: avail
|
||||||
|
|
||||||
M: avail-analysis transfer-set drop defined assoc-union ;
|
M: avail-analysis transfer-set drop defined assoc-union ;
|
||||||
|
|
||||||
! Strict idea of availability, for now. Would like to see if
|
: available? ( vn -- ? ) basic-block get avail-in key? ;
|
||||||
! searching the VN congruence classes for the smallest
|
|
||||||
! available vn would work at all / better.
|
|
||||||
|
|
||||||
: available? ( vn -- ? )
|
: best-vreg ( available-vregs -- vreg )
|
||||||
|
[ f ] [ infimum ] if-empty ;
|
||||||
|
|
||||||
|
: >avail-vreg ( vreg -- vreg/f )
|
||||||
final-iteration? get [
|
final-iteration? get [
|
||||||
basic-block get avail-in key?
|
congruence-class [ available? ] filter best-vreg
|
||||||
] [ drop t ] if ;
|
] when ;
|
||||||
|
|
||||||
: available-uses? ( insn -- ? )
|
: available-uses? ( insn -- ? )
|
||||||
uses-vregs [ available? ] all? ;
|
uses-vregs [ >avail-vreg ] all? ;
|
||||||
|
|
||||||
: with-available-uses? ( quot -- ? )
|
: with-available-uses? ( quot -- ? )
|
||||||
keep swap [ available-uses? ] [ drop f ] if ; inline
|
keep swap [ available-uses? ] [ drop f ] if ; inline
|
||||||
|
|
||||||
: make-available ( vreg -- )
|
: make-available ( vreg -- )
|
||||||
basic-block get avail-ins get [ dupd clone ?set-at ] change-at ;
|
basic-block get avail-ins get [ dupd clone ?set-at ] change-at ;
|
||||||
|
|
||||||
|
RENAMING: >avail [ ] [ dup >avail-vreg swap or ] [ ]
|
||||||
|
|
|
@ -15,6 +15,10 @@ SYMBOL: exprs>vns
|
||||||
! assoc mapping value numbers to instructions
|
! assoc mapping value numbers to instructions
|
||||||
SYMBOL: vns>insns
|
SYMBOL: vns>insns
|
||||||
|
|
||||||
|
! assoc mapping each value number to a sequence of vregs
|
||||||
|
! sharing that value number (i.e., the congruence class)
|
||||||
|
SYMBOL: vns>vregs
|
||||||
|
|
||||||
! boolean to track whether vregs>vns changes
|
! boolean to track whether vregs>vns changes
|
||||||
SYMBOL: changed?
|
SYMBOL: changed?
|
||||||
|
|
||||||
|
@ -31,10 +35,18 @@ SYMBOL: final-iteration?
|
||||||
|
|
||||||
: vreg>insn ( vreg -- insn ) vreg>vn vn>insn ;
|
: vreg>insn ( vreg -- insn ) vreg>vn vn>insn ;
|
||||||
|
|
||||||
|
: congruence-class ( vreg -- vregs )
|
||||||
|
vreg>vn vns>vregs get at ;
|
||||||
|
|
||||||
: clear-exprs ( -- )
|
: clear-exprs ( -- )
|
||||||
exprs>vns get clear-assoc
|
exprs>vns get clear-assoc
|
||||||
vns>insns get clear-assoc ;
|
vns>insns get clear-assoc ;
|
||||||
|
|
||||||
|
: compute-congruence-classes ( -- )
|
||||||
|
vregs>vns get H{ } clone [
|
||||||
|
[ push-at ] curry assoc-each
|
||||||
|
] keep vns>vregs set ;
|
||||||
|
|
||||||
: init-value-graph ( -- )
|
: init-value-graph ( -- )
|
||||||
0 input-expr-counter set
|
0 input-expr-counter set
|
||||||
H{ } clone vregs>vns set
|
H{ } clone vregs>vns set
|
||||||
|
|
|
@ -3152,9 +3152,9 @@ cpu x86? [
|
||||||
] unit-test
|
] unit-test
|
||||||
] when
|
] when
|
||||||
|
|
||||||
! FIXME rewrite redundancy elimination to search for available
|
! Make sure to search for available registers that compute the
|
||||||
! registers that compute the same value number, instead of just
|
! same value number, instead of just relying on the
|
||||||
! relying on the availability of the canonical leader
|
! availability of the canonical leader.
|
||||||
|
|
||||||
V{ T{ ##branch } } 0 test-bb
|
V{ T{ ##branch } } 0 test-bb
|
||||||
|
|
||||||
|
@ -3189,13 +3189,11 @@ test-diamond
|
||||||
value-numbering drop
|
value-numbering drop
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
||||||
! ##load-integer cannot be turned into a ##copy because the
|
! First ##load-integer cannot be turned into a ##copy because
|
||||||
! canonical leader for the value 100 is unavailable.
|
! the canonical leader for the value 100 is unavailable, but
|
||||||
|
! the rest should still be redundant.
|
||||||
[ t ] [ 4 get instructions>> first ##load-integer? ] unit-test
|
[ t ] [ 4 get instructions>> first ##load-integer? ] unit-test
|
||||||
|
[ 1 ] [ 4 get instructions>> [ ##load-integer? ] count ] unit-test
|
||||||
! Not fixed yet; and would need to change if value-numbering
|
|
||||||
! subsumed copy-prop.
|
|
||||||
! [ t ] [ 4 get instructions>> rest [ ##copy? ] all? ] unit-test
|
|
||||||
|
|
||||||
! Global optimization
|
! Global optimization
|
||||||
V{ T{ ##prologue } T{ ##branch } } 0 test-bb
|
V{ T{ ##prologue } T{ ##branch } } 0 test-bb
|
||||||
|
|
|
@ -23,7 +23,7 @@ IN: compiler.cfg.gvn
|
||||||
|
|
||||||
GENERIC: simplify ( insn -- insn' )
|
GENERIC: simplify ( insn -- insn' )
|
||||||
|
|
||||||
M: insn simplify dup rewrite [ simplify ] [ ] ?if ;
|
M: insn simplify dup rewrite [ simplify ] [ dup >avail-insn-uses ] ?if ;
|
||||||
M: array simplify [ simplify ] map ;
|
M: array simplify [ simplify ] map ;
|
||||||
M: ##copy simplify ;
|
M: ##copy simplify ;
|
||||||
|
|
||||||
|
@ -96,7 +96,7 @@ M: ##copy gcse defs-available ;
|
||||||
] [ drop defs-available ] if ;
|
] [ drop defs-available ] if ;
|
||||||
|
|
||||||
: eliminate-redundancy ( insn -- insn' )
|
: eliminate-redundancy ( insn -- insn' )
|
||||||
dup >expr exprs>vns get at
|
dup >expr exprs>vns get at >avail-vreg
|
||||||
[ ?eliminate ] [ defs-available ] if* ;
|
[ ?eliminate ] [ defs-available ] if* ;
|
||||||
|
|
||||||
M: ##phi gcse
|
M: ##phi gcse
|
||||||
|
@ -113,6 +113,7 @@ M: insn gcse
|
||||||
|
|
||||||
: eliminate-common-subexpressions ( cfg -- )
|
: eliminate-common-subexpressions ( cfg -- )
|
||||||
final-iteration? on
|
final-iteration? on
|
||||||
|
compute-congruence-classes
|
||||||
dup compute-avail-sets
|
dup compute-avail-sets
|
||||||
[ gcse-step ] simple-optimization ;
|
[ gcse-step ] simple-optimization ;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue