]> gitweb.factorcode.org Git - factor.git/blob - basis/compiler/cfg/write-barrier/write-barrier.factor
523f7c6d1ced65c45e05869eb5f166e049af2fd2
[factor.git] / basis / compiler / cfg / write-barrier / write-barrier.factor
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
5 sequences sets ;
6 IN: compiler.cfg.write-barrier
7
8 SYMBOL: fresh-allocations
9
10 SYMBOL: mutated-objects
11
12 GENERIC: eliminate-write-barrier ( insn -- ? )
13
14 M: ##allot eliminate-write-barrier
15     dst>> fresh-allocations get conjoin t ;
16
17 M: ##set-slot eliminate-write-barrier
18     obj>> mutated-objects get conjoin t ;
19
20 M: ##set-slot-imm eliminate-write-barrier
21     obj>> mutated-objects get conjoin t ;
22
23 : needs-write-barrier? ( insn -- ? )
24     { [ fresh-allocations get key? not ] [ mutated-objects get key? ] } 1&& ;
25
26 M: ##write-barrier eliminate-write-barrier
27     src>> needs-write-barrier? ;
28
29 M: ##write-barrier-imm eliminate-write-barrier
30     src>> needs-write-barrier? ;
31
32 M: ##copy eliminate-write-barrier
33     "Run copy propagation first" throw ;
34
35 M: insn eliminate-write-barrier drop t ;
36
37 : write-barriers-step ( bb -- )
38     H{ } clone fresh-allocations set
39     H{ } clone mutated-objects set
40     instructions>> [ eliminate-write-barrier ] filter! drop ;
41
42 : eliminate-write-barriers ( cfg -- cfg' )
43     dup [ write-barriers-step ] each-basic-block ;