2009-05-31 13:20:46 -04:00
|
|
|
! Copyright (C) 2009 Slava Pestov.
|
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
2009-07-30 10:19:44 -04:00
|
|
|
USING: accessors kernel sequences assocs fry
|
2009-10-05 06:27:49 -04:00
|
|
|
cpu.architecture layouts
|
2009-07-30 10:19:44 -04:00
|
|
|
compiler.cfg.rpo
|
|
|
|
compiler.cfg.registers
|
|
|
|
compiler.cfg.instructions
|
|
|
|
compiler.cfg.stacks.uninitialized ;
|
2009-05-31 13:20:46 -04:00
|
|
|
IN: compiler.cfg.gc-checks
|
|
|
|
|
2009-08-08 05:02:18 -04:00
|
|
|
! Garbage collection check insertion. This pass runs after representation
|
|
|
|
! selection, so it must keep track of representations.
|
|
|
|
|
2009-07-30 10:19:44 -04:00
|
|
|
: insert-gc-check? ( bb -- ? )
|
2009-05-31 13:20:46 -04:00
|
|
|
instructions>> [ ##allocation? ] any? ;
|
|
|
|
|
2009-07-30 10:19:44 -04:00
|
|
|
: blocks-with-gc ( cfg -- bbs )
|
|
|
|
post-order [ insert-gc-check? ] filter ;
|
|
|
|
|
2009-10-05 06:27:49 -04:00
|
|
|
GENERIC: allocation-size* ( insn -- n )
|
|
|
|
|
|
|
|
M: ##allot allocation-size* size>> ;
|
|
|
|
|
|
|
|
M: ##box-alien allocation-size* drop 4 cells ;
|
|
|
|
|
|
|
|
M: ##box-displaced-alien allocation-size* drop 4 cells ;
|
|
|
|
|
|
|
|
: allocation-size ( bb -- n )
|
|
|
|
instructions>> [ ##allocation? ] filter [ allocation-size* ] sigma ;
|
|
|
|
|
2009-07-30 10:19:44 -04:00
|
|
|
: insert-gc-check ( bb -- )
|
2009-10-05 06:27:49 -04:00
|
|
|
dup dup '[
|
2009-08-08 05:02:18 -04:00
|
|
|
int-rep next-vreg-rep
|
|
|
|
int-rep next-vreg-rep
|
2009-10-05 06:27:49 -04:00
|
|
|
_ allocation-size
|
|
|
|
f
|
|
|
|
f
|
|
|
|
_ uninitialized-locs
|
|
|
|
\ ##gc new-insn
|
2009-07-30 10:19:44 -04:00
|
|
|
prefix
|
|
|
|
] change-instructions drop ;
|
2009-05-31 13:20:46 -04:00
|
|
|
|
|
|
|
: insert-gc-checks ( cfg -- cfg' )
|
2009-07-30 10:19:44 -04:00
|
|
|
dup blocks-with-gc [
|
|
|
|
over compute-uninitialized-sets
|
|
|
|
[ insert-gc-check ] each
|
|
|
|
] unless-empty ;
|