2010-04-30 18:55:20 -04:00
|
|
|
! Copyright (C) 2008, 2010 Slava Pestov, Daniel Ehrenberg.
|
2008-10-22 19:41:10 -04:00
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
2009-10-14 03:06:01 -04:00
|
|
|
USING: accessors assocs combinators.short-circuit
|
|
|
|
compiler.cfg.instructions compiler.cfg.rpo kernel namespaces
|
|
|
|
sequences sets ;
|
2008-10-22 19:41:10 -04:00
|
|
|
IN: compiler.cfg.write-barrier
|
|
|
|
|
2010-09-06 00:39:45 -04:00
|
|
|
! This pass must run after GC check insertion and scheduling.
|
|
|
|
|
2009-10-14 03:06:01 -04:00
|
|
|
SYMBOL: fresh-allocations
|
2008-10-22 19:41:10 -04:00
|
|
|
|
2009-10-14 03:06:01 -04:00
|
|
|
SYMBOL: mutated-objects
|
2008-10-22 19:41:10 -04:00
|
|
|
|
2010-09-06 02:07:30 -04:00
|
|
|
SYMBOL: copies
|
|
|
|
|
|
|
|
: resolve-copy ( src -- dst )
|
|
|
|
copies get ?at drop ;
|
|
|
|
|
2009-07-24 06:29:28 -04:00
|
|
|
GENERIC: eliminate-write-barrier ( insn -- ? )
|
2008-10-22 19:41:10 -04:00
|
|
|
|
2010-09-06 02:07:30 -04:00
|
|
|
: fresh-allocation ( vreg -- )
|
2013-03-08 15:30:37 -05:00
|
|
|
fresh-allocations get adjoin ;
|
2010-09-06 02:07:30 -04:00
|
|
|
|
2008-10-22 19:41:10 -04:00
|
|
|
M: ##allot eliminate-write-barrier
|
2010-09-06 02:07:30 -04:00
|
|
|
dst>> fresh-allocation t ;
|
|
|
|
|
|
|
|
: mutated-object ( vreg -- )
|
2013-03-08 15:30:37 -05:00
|
|
|
resolve-copy mutated-objects get adjoin ;
|
2008-10-22 19:41:10 -04:00
|
|
|
|
2009-10-14 03:06:01 -04:00
|
|
|
M: ##set-slot eliminate-write-barrier
|
2010-09-06 02:07:30 -04:00
|
|
|
obj>> mutated-object t ;
|
2008-10-22 19:41:10 -04:00
|
|
|
|
2009-10-14 03:06:01 -04:00
|
|
|
M: ##set-slot-imm eliminate-write-barrier
|
2010-09-06 02:07:30 -04:00
|
|
|
obj>> mutated-object t ;
|
2008-10-22 19:41:10 -04:00
|
|
|
|
2009-10-14 03:06:01 -04:00
|
|
|
: needs-write-barrier? ( insn -- ? )
|
2010-09-06 02:07:30 -04:00
|
|
|
resolve-copy {
|
2013-03-08 15:30:37 -05:00
|
|
|
[ fresh-allocations get in? not ]
|
|
|
|
[ mutated-objects get in? ]
|
2010-09-06 00:39:45 -04:00
|
|
|
} 1&& ;
|
2009-08-11 22:21:21 -04:00
|
|
|
|
2009-10-14 03:06:01 -04:00
|
|
|
M: ##write-barrier eliminate-write-barrier
|
|
|
|
src>> needs-write-barrier? ;
|
|
|
|
|
|
|
|
M: ##write-barrier-imm eliminate-write-barrier
|
|
|
|
src>> needs-write-barrier? ;
|
2009-08-11 22:21:21 -04:00
|
|
|
|
2010-09-06 00:39:45 -04:00
|
|
|
M: gc-map-insn eliminate-write-barrier
|
2013-03-08 15:30:37 -05:00
|
|
|
fresh-allocations get clear-set ;
|
2010-09-06 00:39:45 -04:00
|
|
|
|
2009-10-14 03:06:01 -04:00
|
|
|
M: ##copy eliminate-write-barrier
|
2010-09-06 20:01:44 -04:00
|
|
|
[ src>> resolve-copy ] [ dst>> ] bi copies get set-at t ;
|
2009-08-11 22:21:21 -04:00
|
|
|
|
2009-10-14 03:06:01 -04:00
|
|
|
M: insn eliminate-write-barrier drop t ;
|
2009-08-11 22:21:21 -04:00
|
|
|
|
2010-04-30 18:55:20 -04:00
|
|
|
: write-barriers-step ( insns -- insns' )
|
2016-03-29 20:14:42 -04:00
|
|
|
HS{ } clone fresh-allocations namespaces:set
|
|
|
|
HS{ } clone mutated-objects namespaces:set
|
|
|
|
H{ } clone copies namespaces:set
|
2010-04-30 18:55:20 -04:00
|
|
|
[ eliminate-write-barrier ] filter! ;
|
2009-05-26 20:31:19 -04:00
|
|
|
|
2014-12-11 15:48:43 -05:00
|
|
|
: eliminate-write-barriers ( cfg -- )
|
|
|
|
[ write-barriers-step ] simple-optimization ;
|