compiler.cfg.coalescing: more or less complete, now needs debugging
parent
a32cbdd231
commit
ba696b68b8
|
@ -1,8 +1,9 @@
|
||||||
! Copyright (C) 2009 Slava Pestov.
|
! Copyright (C) 2009 Slava Pestov.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: accessors assocs fry kernel locals math math.order
|
USING: accessors assocs fry kernel locals math math.order
|
||||||
sequences
|
sequences namespaces sets
|
||||||
compiler.cfg.rpo
|
compiler.cfg.rpo
|
||||||
|
compiler.cfg.def-use
|
||||||
compiler.cfg.utilities
|
compiler.cfg.utilities
|
||||||
compiler.cfg.dominance
|
compiler.cfg.dominance
|
||||||
compiler.cfg.instructions
|
compiler.cfg.instructions
|
||||||
|
@ -21,7 +22,24 @@ IN: compiler.cfg.coalescing
|
||||||
: process-blocks ( cfg -- )
|
: process-blocks ( cfg -- )
|
||||||
[ [ process-block ] if-has-phis ] each-basic-block ;
|
[ [ process-block ] if-has-phis ] each-basic-block ;
|
||||||
|
|
||||||
: break-interferences ( -- ) ;
|
SYMBOL: seen
|
||||||
|
|
||||||
|
:: visit-renaming ( dst assoc src bb -- )
|
||||||
|
src seen get key? [
|
||||||
|
src dst bb waiting-for push-at
|
||||||
|
src assoc delete-at
|
||||||
|
] [ src seen get conjoin ] if ;
|
||||||
|
|
||||||
|
:: break-interferences ( -- )
|
||||||
|
V{ } clone seen set
|
||||||
|
renaming-sets get [| dst assoc |
|
||||||
|
assoc [| src bb |
|
||||||
|
src seen get key?
|
||||||
|
[ dst assoc src bb visit-renaming ]
|
||||||
|
[ src seen get conjoin ]
|
||||||
|
if
|
||||||
|
] assoc-each
|
||||||
|
] assoc-each ;
|
||||||
|
|
||||||
: remove-phis-from-block ( bb -- )
|
: remove-phis-from-block ( bb -- )
|
||||||
instructions>> [ ##phi? not ] filter-here ;
|
instructions>> [ ##phi? not ] filter-here ;
|
||||||
|
@ -31,9 +49,11 @@ IN: compiler.cfg.coalescing
|
||||||
|
|
||||||
: coalesce ( cfg -- cfg' )
|
: coalesce ( cfg -- cfg' )
|
||||||
init-coalescing
|
init-coalescing
|
||||||
|
dup compute-def-use
|
||||||
|
dup compute-dominance
|
||||||
dup compute-dfs
|
dup compute-dfs
|
||||||
dup process-blocks
|
dup process-blocks
|
||||||
break-interferences
|
break-interferences
|
||||||
dup insert-copies
|
dup insert-copies
|
||||||
perform-renaming
|
dup perform-renaming
|
||||||
dup remove-phis ;
|
dup remove-phis ;
|
|
@ -1,39 +1,21 @@
|
||||||
! Copyright (C) 2009 Slava Pestov.
|
! Copyright (C) 2009 Slava Pestov.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: accessors assocs combinators fry kernel namespaces sequences
|
USING: accessors assocs hashtables fry kernel make namespaces
|
||||||
compiler.cfg.def-use compiler.cfg.dominance compiler.cfg.instructions
|
sequences compiler.cfg.coalescing.state compiler.cfg.parallel-copy ;
|
||||||
compiler.cfg.renaming ;
|
|
||||||
IN: compiler.cfg.coalescing.copies
|
IN: compiler.cfg.coalescing.copies
|
||||||
|
|
||||||
SYMBOLS: stacks visited pushed ;
|
: compute-copies ( assoc -- assoc' )
|
||||||
|
dup assoc-size <hashtable> [
|
||||||
: compute-renaming ( insn -- assoc )
|
'[
|
||||||
uses-vregs stacks get
|
[ _ set-at ] with each
|
||||||
'[ dup dup _ at [ nip last ] unless-empty ]
|
] assoc-each
|
||||||
H{ } map>assoc ;
|
] keep ;
|
||||||
|
|
||||||
: rename-operands ( bb -- )
|
|
||||||
instructions>> [
|
|
||||||
dup ##phi? [ drop ] [
|
|
||||||
dup compute-renaming renamings set
|
|
||||||
[ rename-insn-uses ] [ rename-insn-defs ] bi
|
|
||||||
] if
|
|
||||||
] each ;
|
|
||||||
|
|
||||||
: schedule-copies ( bb -- )
|
|
||||||
! FIXME
|
|
||||||
drop ;
|
|
||||||
|
|
||||||
: pop-stacks ( -- )
|
|
||||||
pushed get stacks get '[ drop _ at pop* ] assoc-each ;
|
|
||||||
|
|
||||||
: (insert-copies) ( bb -- )
|
|
||||||
H{ } clone pushed [
|
|
||||||
[ rename-operands ]
|
|
||||||
[ schedule-copies ]
|
|
||||||
[ dom-children [ (insert-copies) ] each ] tri
|
|
||||||
pop-stacks
|
|
||||||
] with-variable ;
|
|
||||||
|
|
||||||
: insert-copies ( cfg -- )
|
: insert-copies ( cfg -- )
|
||||||
entry>> (insert-copies) ;
|
waiting get [
|
||||||
|
[ instructions>> building ] dip '[
|
||||||
|
building get pop
|
||||||
|
_ compute-copies parallel-copy
|
||||||
|
,
|
||||||
|
] with-variable
|
||||||
|
] assoc-each ;
|
|
@ -1,10 +1,33 @@
|
||||||
! Copyright (C) 2009 Slava Pestov.
|
! Copyright (C) 2009 Slava Pestov.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: kernel ;
|
USING: accessors assocs fry kernel namespaces sequences
|
||||||
|
compiler.cfg.coalescing.state compiler.cfg.renaming compiler.cfg.rpo
|
||||||
|
disjoint-sets ;
|
||||||
IN: compiler.cfg.coalescing.renaming
|
IN: compiler.cfg.coalescing.renaming
|
||||||
|
|
||||||
: perform-renaming ( -- )
|
: update-congruence-class ( dst assoc disjoint-set -- )
|
||||||
renaming-sets get [
|
[ keys swap ] dip
|
||||||
! XXX
|
[ nip add-atoms ]
|
||||||
2drop
|
[ add-atom drop ]
|
||||||
] assoc-each ;
|
[ equate-all-with ] 3tri ;
|
||||||
|
|
||||||
|
: build-congruence-classes ( -- disjoint-set )
|
||||||
|
renaming-sets get
|
||||||
|
<disjoint-set> [
|
||||||
|
'[
|
||||||
|
_ update-congruence-class
|
||||||
|
] assoc-each
|
||||||
|
] keep ;
|
||||||
|
|
||||||
|
: compute-renaming ( disjoint-set -- assoc )
|
||||||
|
[ parents>> ] keep
|
||||||
|
'[ drop dup _ representative ] assoc-map ;
|
||||||
|
|
||||||
|
: perform-renaming ( cfg -- )
|
||||||
|
build-congruence-classes compute-renaming renamings set
|
||||||
|
[
|
||||||
|
instructions>> [
|
||||||
|
[ rename-insn-defs ]
|
||||||
|
[ rename-insn-uses ] bi
|
||||||
|
] each
|
||||||
|
] each-basic-block ;
|
||||||
|
|
|
@ -60,21 +60,26 @@ PRIVATE>
|
||||||
[ '[ 2dup eq? [ 2drop ] [ _ push-at ] if ] assoc-each ] keep
|
[ '[ 2dup eq? [ 2drop ] [ _ push-at ] if ] assoc-each ] keep
|
||||||
dom-childrens set ;
|
dom-childrens set ;
|
||||||
|
|
||||||
! Maps bb -> DF(bb)
|
|
||||||
SYMBOL: dom-frontiers
|
|
||||||
|
|
||||||
PRIVATE>
|
PRIVATE>
|
||||||
|
|
||||||
: dom-frontier ( bb -- set ) dom-frontiers get at keys ;
|
: compute-dominance ( cfg -- )
|
||||||
|
compute-dom-parents compute-dom-children ;
|
||||||
|
|
||||||
<PRIVATE
|
<PRIVATE
|
||||||
|
|
||||||
|
! Maps bb -> DF(bb)
|
||||||
|
SYMBOL: dom-frontiers
|
||||||
|
|
||||||
: compute-dom-frontier ( bb pred -- )
|
: compute-dom-frontier ( bb pred -- )
|
||||||
2dup [ dom-parent ] dip eq? [ 2drop ] [
|
2dup [ dom-parent ] dip eq? [ 2drop ] [
|
||||||
[ dom-frontiers get conjoin-at ]
|
[ dom-frontiers get conjoin-at ]
|
||||||
[ dom-parent compute-dom-frontier ] 2bi
|
[ dom-parent compute-dom-frontier ] 2bi
|
||||||
] if ;
|
] if ;
|
||||||
|
|
||||||
|
PRIVATE>
|
||||||
|
|
||||||
|
: dom-frontier ( bb -- set ) dom-frontiers get at keys ;
|
||||||
|
|
||||||
: compute-dom-frontiers ( cfg -- )
|
: compute-dom-frontiers ( cfg -- )
|
||||||
H{ } clone dom-frontiers set
|
H{ } clone dom-frontiers set
|
||||||
[
|
[
|
||||||
|
@ -83,13 +88,6 @@ PRIVATE>
|
||||||
] [ 2drop ] if
|
] [ 2drop ] if
|
||||||
] each-basic-block ;
|
] each-basic-block ;
|
||||||
|
|
||||||
PRIVATE>
|
|
||||||
|
|
||||||
: compute-dominance ( cfg -- )
|
|
||||||
[ compute-dom-parents compute-dom-children ]
|
|
||||||
[ compute-dom-frontiers ]
|
|
||||||
bi ;
|
|
||||||
|
|
||||||
<PRIVATE
|
<PRIVATE
|
||||||
|
|
||||||
SYMBOLS: work-list visited ;
|
SYMBOLS: work-list visited ;
|
||||||
|
|
|
@ -11,7 +11,7 @@ compiler.cfg.value-numbering
|
||||||
compiler.cfg.copy-prop
|
compiler.cfg.copy-prop
|
||||||
compiler.cfg.dce
|
compiler.cfg.dce
|
||||||
compiler.cfg.write-barrier
|
compiler.cfg.write-barrier
|
||||||
compiler.cfg.phi-elimination
|
compiler.cfg.coalescing
|
||||||
compiler.cfg.empty-blocks
|
compiler.cfg.empty-blocks
|
||||||
compiler.cfg.predecessors
|
compiler.cfg.predecessors
|
||||||
compiler.cfg.rpo
|
compiler.cfg.rpo
|
||||||
|
@ -32,7 +32,7 @@ SYMBOL: check-optimizer?
|
||||||
optimize-tail-calls
|
optimize-tail-calls
|
||||||
delete-useless-conditionals
|
delete-useless-conditionals
|
||||||
compute-predecessors
|
compute-predecessors
|
||||||
split-branches
|
! split-branches
|
||||||
join-blocks
|
join-blocks
|
||||||
compute-predecessors
|
compute-predecessors
|
||||||
construct-ssa
|
construct-ssa
|
||||||
|
@ -42,7 +42,7 @@ SYMBOL: check-optimizer?
|
||||||
copy-propagation
|
copy-propagation
|
||||||
eliminate-dead-code
|
eliminate-dead-code
|
||||||
eliminate-write-barriers
|
eliminate-write-barriers
|
||||||
eliminate-phis
|
coalesce
|
||||||
delete-empty-blocks
|
delete-empty-blocks
|
||||||
?check
|
?check
|
||||||
] with-scope ;
|
] with-scope ;
|
||||||
|
|
|
@ -113,6 +113,7 @@ PRIVATE>
|
||||||
[ ]
|
[ ]
|
||||||
[ compute-live-sets ]
|
[ compute-live-sets ]
|
||||||
[ compute-dominance ]
|
[ compute-dominance ]
|
||||||
|
[ compute-dom-frontiers ]
|
||||||
[ compute-defs compute-phi-nodes insert-phi-nodes ]
|
[ compute-defs compute-phi-nodes insert-phi-nodes ]
|
||||||
[ rename ]
|
[ rename ]
|
||||||
} cleave ;
|
} cleave ;
|
|
@ -35,6 +35,8 @@ TUPLE: disjoint-set
|
||||||
: representative? ( a disjoint-set -- ? )
|
: representative? ( a disjoint-set -- ? )
|
||||||
dupd parent = ; inline
|
dupd parent = ; inline
|
||||||
|
|
||||||
|
PRIVATE>
|
||||||
|
|
||||||
GENERIC: representative ( a disjoint-set -- p )
|
GENERIC: representative ( a disjoint-set -- p )
|
||||||
|
|
||||||
M: disjoint-set representative
|
M: disjoint-set representative
|
||||||
|
@ -42,6 +44,8 @@ M: disjoint-set representative
|
||||||
[ [ parent ] keep representative dup ] 2keep set-parent
|
[ [ parent ] keep representative dup ] 2keep set-parent
|
||||||
] if ;
|
] if ;
|
||||||
|
|
||||||
|
<PRIVATE
|
||||||
|
|
||||||
: representatives ( a b disjoint-set -- r r )
|
: representatives ( a b disjoint-set -- r r )
|
||||||
[ representative ] curry bi@ ; inline
|
[ representative ] curry bi@ ; inline
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue