2009-08-11 22:21:21 -04:00
|
|
|
! Copyright (C) 2008, 2009 Slava Pestov, Daniel Ehrenberg.
|
2008-10-22 19:41:10 -04:00
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
2009-07-24 06:29:28 -04:00
|
|
|
USING: kernel accessors namespaces assocs sets sequences
|
2009-08-11 22:21:21 -04:00
|
|
|
compiler.cfg compiler.cfg.instructions compiler.cfg.rpo
|
|
|
|
compiler.cfg.dataflow-analysis fry combinators.short-circuit ;
|
2008-10-22 19:41:10 -04:00
|
|
|
IN: compiler.cfg.write-barrier
|
|
|
|
|
|
|
|
! Eliminate redundant write barrier hits.
|
|
|
|
|
|
|
|
! Objects which have already been marked, as well as
|
|
|
|
! freshly-allocated objects
|
|
|
|
SYMBOL: safe
|
|
|
|
|
|
|
|
! Objects which have been mutated
|
|
|
|
SYMBOL: mutated
|
|
|
|
|
2009-07-24 06:29:28 -04:00
|
|
|
GENERIC: eliminate-write-barrier ( insn -- ? )
|
2008-10-22 19:41:10 -04:00
|
|
|
|
|
|
|
M: ##allot eliminate-write-barrier
|
2009-07-24 06:29:28 -04:00
|
|
|
dst>> safe get conjoin t ;
|
2008-10-22 19:41:10 -04:00
|
|
|
|
|
|
|
M: ##write-barrier eliminate-write-barrier
|
2009-07-24 06:29:28 -04:00
|
|
|
src>> dup [ safe get key? not ] [ mutated get key? ] bi and
|
|
|
|
[ safe get conjoin t ] [ drop f ] if ;
|
2008-10-22 19:41:10 -04:00
|
|
|
|
|
|
|
M: ##set-slot eliminate-write-barrier
|
2009-07-24 06:29:28 -04:00
|
|
|
obj>> mutated get conjoin t ;
|
2008-10-22 19:41:10 -04:00
|
|
|
|
|
|
|
M: ##set-slot-imm eliminate-write-barrier
|
2009-07-24 06:29:28 -04:00
|
|
|
obj>> mutated get conjoin t ;
|
2008-10-22 19:41:10 -04:00
|
|
|
|
2009-07-24 06:29:28 -04:00
|
|
|
M: insn eliminate-write-barrier drop t ;
|
2008-10-22 19:41:10 -04:00
|
|
|
|
2009-08-11 22:21:21 -04:00
|
|
|
FORWARD-ANALYSIS: safe
|
|
|
|
|
|
|
|
: has-allocation? ( bb -- ? )
|
|
|
|
instructions>> [ { [ ##allocation? ] [ ##call? ] } 1|| ] any? ;
|
|
|
|
|
2009-08-13 16:18:47 -04:00
|
|
|
GENERIC: safe-slot ( insn -- slot ? )
|
|
|
|
M: object safe-slot drop f f ;
|
|
|
|
M: ##write-barrier safe-slot src>> t ;
|
|
|
|
M: ##allot safe-slot dst>> t ;
|
|
|
|
|
2009-08-11 22:21:21 -04:00
|
|
|
M: safe-analysis transfer-set
|
2009-08-13 00:52:29 -04:00
|
|
|
drop [ H{ } assoc-clone-like ] dip
|
2009-08-11 22:21:21 -04:00
|
|
|
instructions>> over '[
|
2009-08-13 16:18:47 -04:00
|
|
|
safe-slot [ _ conjoin ] [ drop ] if
|
2009-08-11 22:21:21 -04:00
|
|
|
] each ;
|
|
|
|
|
|
|
|
M: safe-analysis join-sets
|
2009-08-13 00:52:29 -04:00
|
|
|
drop has-allocation? [ drop H{ } clone ] [ assoc-refine ] if ;
|
2009-08-11 22:21:21 -04:00
|
|
|
|
2009-07-24 06:29:28 -04:00
|
|
|
: write-barriers-step ( bb -- )
|
2009-08-13 00:52:29 -04:00
|
|
|
dup safe-in H{ } assoc-clone-like safe set
|
2008-10-22 19:41:10 -04:00
|
|
|
H{ } clone mutated set
|
2009-07-24 06:29:28 -04:00
|
|
|
instructions>> [ eliminate-write-barrier ] filter-here ;
|
2009-05-26 20:31:19 -04:00
|
|
|
|
2009-05-29 14:11:34 -04:00
|
|
|
: eliminate-write-barriers ( cfg -- cfg' )
|
2009-08-13 16:18:47 -04:00
|
|
|
dup compute-safe-sets
|
2009-07-24 06:29:28 -04:00
|
|
|
dup [ write-barriers-step ] each-basic-block ;
|