]> gitweb.factorcode.org Git - factor.git/blob - basis/compiler/cfg/gc-checks/gc-checks.factor
Solution to Project Euler problem 65
[factor.git] / basis / compiler / cfg / gc-checks / gc-checks.factor
1 ! Copyright (C) 2009 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors kernel sequences assocs fry
4 cpu.architecture
5 compiler.cfg.rpo
6 compiler.cfg.registers
7 compiler.cfg.instructions
8 compiler.cfg.stacks.uninitialized ;
9 IN: compiler.cfg.gc-checks
10
11 ! Garbage collection check insertion. This pass runs after representation
12 ! selection, so it must keep track of representations.
13
14 : insert-gc-check? ( bb -- ? )
15     instructions>> [ ##allocation? ] any? ;
16
17 : blocks-with-gc ( cfg -- bbs )
18     post-order [ insert-gc-check? ] filter ;
19
20 : insert-gc-check ( bb -- )
21     dup '[
22         int-rep next-vreg-rep
23         int-rep next-vreg-rep
24         f f _ uninitialized-locs \ ##gc new-insn
25         prefix
26     ] change-instructions drop ;
27
28 : insert-gc-checks ( cfg -- cfg' )
29     dup blocks-with-gc [
30         over compute-uninitialized-sets
31         [ insert-gc-check ] each
32     ] unless-empty ;