factor/basis/compiler/cfg/write-barrier/write-barrier.factor

45 lines
1.3 KiB
Factor
Raw Normal View History

! 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.
USING: accessors assocs combinators.short-circuit
compiler.cfg.instructions compiler.cfg.rpo kernel namespaces
sequences sets ;
2010-02-26 16:01:01 -05:00
FROM: namespaces => set ;
2008-10-22 19:41:10 -04:00
IN: compiler.cfg.write-barrier
SYMBOL: fresh-allocations
2008-10-22 19:41:10 -04:00
SYMBOL: mutated-objects
2008-10-22 19:41:10 -04:00
GENERIC: eliminate-write-barrier ( insn -- ? )
2008-10-22 19:41:10 -04:00
M: ##allot eliminate-write-barrier
dst>> fresh-allocations get conjoin t ;
2008-10-22 19:41:10 -04:00
M: ##set-slot eliminate-write-barrier
obj>> mutated-objects get conjoin t ;
2008-10-22 19:41:10 -04:00
M: ##set-slot-imm eliminate-write-barrier
obj>> mutated-objects get conjoin t ;
2008-10-22 19:41:10 -04:00
: needs-write-barrier? ( insn -- ? )
{ [ fresh-allocations get key? not ] [ mutated-objects get key? ] } 1&& ;
M: ##write-barrier eliminate-write-barrier
src>> needs-write-barrier? ;
M: ##write-barrier-imm eliminate-write-barrier
src>> needs-write-barrier? ;
M: ##copy eliminate-write-barrier
"Run copy propagation first" throw ;
M: insn eliminate-write-barrier drop t ;
: write-barriers-step ( bb -- )
H{ } clone fresh-allocations set
H{ } clone mutated-objects set
2009-10-28 01:44:05 -04:00
instructions>> [ eliminate-write-barrier ] filter! drop ;
: eliminate-write-barriers ( cfg -- cfg' )
dup [ write-barriers-step ] each-basic-block ;