1 ! Copyright (C) 2008, 2009 Slava Pestov, Daniel Ehrenberg.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors assocs combinators.short-circuit
4 compiler.cfg.instructions compiler.cfg.rpo kernel namespaces
6 FROM: namespaces => set ;
7 IN: compiler.cfg.write-barrier
9 SYMBOL: fresh-allocations
11 SYMBOL: mutated-objects
13 GENERIC: eliminate-write-barrier ( insn -- ? )
15 M: ##allot eliminate-write-barrier
16 dst>> fresh-allocations get conjoin t ;
18 M: ##set-slot eliminate-write-barrier
19 obj>> mutated-objects get conjoin t ;
21 M: ##set-slot-imm eliminate-write-barrier
22 obj>> mutated-objects get conjoin t ;
24 : needs-write-barrier? ( insn -- ? )
25 { [ fresh-allocations get key? not ] [ mutated-objects get key? ] } 1&& ;
27 M: ##write-barrier eliminate-write-barrier
28 src>> needs-write-barrier? ;
30 M: ##write-barrier-imm eliminate-write-barrier
31 src>> needs-write-barrier? ;
33 M: ##copy eliminate-write-barrier
34 "Run copy propagation first" throw ;
36 M: insn eliminate-write-barrier drop t ;
38 : write-barriers-step ( bb -- )
39 H{ } clone fresh-allocations set
40 H{ } clone mutated-objects set
41 instructions>> [ eliminate-write-barrier ] filter! drop ;
43 : eliminate-write-barriers ( cfg -- cfg' )
44 dup [ write-barriers-step ] each-basic-block ;